From ab586178158e760341b03b48400266a77527d7e0 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Wed, 19 Mar 2025 08:27:15 -0700 Subject: [PATCH] Don't create the new file if it has no data. Also make the Track portion optional so that the files do not become hidden with a `.`. --- refactor_music_library.sh | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/refactor_music_library.sh b/refactor_music_library.sh index 9734e43..b8eccf8 100755 --- a/refactor_music_library.sh +++ b/refactor_music_library.sh @@ -75,7 +75,7 @@ find "$OLD" -type f ! -name "*".mp3 | sort | while read file; do if [[ $status != 0 ]]; then echo "*** FAILED: Exited with status '$status'." echo "**** To troubleshoot, try running this:" - echo "ffmpeg -i '$file' '$file'.converted.mp3" + echo "ffmpeg -i \"$file\" \"$file\".converted.mp3" else echo "*** Success!" fi @@ -127,7 +127,9 @@ function migrate_music { [[ ${#track} == 1 ]] && track="0$track" echo "*** Track=$track" - new_file="$track. $new_file" + if [[ -s "$track" ]]; then + new_file="$track. $new_file" + fi # Add the Album and Year. album="" @@ -209,6 +211,26 @@ function migrate_music { new_file="$grandparent/$new_file" + # Check that the file has proper data. + skip=false + if [[ -z "$grandparent" ]]; then + echo "ERROR: Could not find Artist information." + skip="true" + fi + if [[ -z "$parent" ]]; then + echo "ERROR: Could not find Album or Year information." + skip="true" + fi + if [[ -z "$track" && -z "$title" ]]; then + echo "ERROR: Could not find Track or Title information." + skip="true" + fi + + if [[ "$skip" == "true" ]]; then + echo "*** Skipping file, critical data missing." + return 1 + fi + # Create the new directories if they do not already exist. mkdir -pv "$NEW/$grandparent/$parent"