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"