From 5f61ca0280dc1da1e01a4d3bf21d19093eb7a037 Mon Sep 17 00:00:00 2001 From: eriedaberrie Date: Thu, 7 Nov 2024 15:45:11 -0800 Subject: [PATCH] fix: sync-music: ensure output file names are valid on Android --- sync-music/sync-music.lisp | 10 ++++++---- sync-music/utils.lisp | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sync-music/sync-music.lisp b/sync-music/sync-music.lisp index f385a60..af3b8fd 100644 --- a/sync-music/sync-music.lisp +++ b/sync-music/sync-music.lisp @@ -84,10 +84,12 @@ Return the action if it exists, or NIL if the file should not be copied." data-raw) :for metadata-filtered := (delete-if (compose #'emptyp #'cdr) metadata) :for previous-action := nil :then current-action - :for output-file-name := (substitute #\! #\/ (format nil - "~A - ~A" - track-number - track-title)) + :for output-file-name := (ppcre:regex-replace-all *invalid-char-scanner* + (format nil + "~A - ~A" + track-number + track-title) + "!!!") :for current-action := (make-copy-flac-action :origin origin-file :target (pathname-normalize-unicode diff --git a/sync-music/utils.lisp b/sync-music/utils.lisp index 19d3b63..be76720 100644 --- a/sync-music/utils.lisp +++ b/sync-music/utils.lisp @@ -21,6 +21,9 @@ (defparameter *timestamp-scanner* (ppcre:create-scanner "^(\\d+):(\\d{2})\\.(\\d{2})$") "Scan for a cuetools position.") +(defparameter *invalid-char-scanner* (ppcre:create-scanner "[\"*/:<>?\\\\|]") + "Scan for any characters not allowed in an Android/NTFS file name.") + (defun maybe-normalize-unicode (s) (if (stringp s) (uax-15:normalize s :nfc) s))