diff --git a/import_music.sh b/import_music.sh index e0a614d..1b9b0e6 100755 --- a/import_music.sh +++ b/import_music.sh @@ -97,8 +97,15 @@ done # Also move/copy associated image files (cover art & artist images) find "$IMPORT_DIR" -type f \( -iname "*.jpg" -o -iname "*.png" \) | while read -r img_file; do dir_path=$(dirname "$img_file") - artist=$(metaflac --show-tag=ALBUMARTIST "$dir_path"/*.flac 2>/dev/null | head -n1 | sed 's/^ALBUMARTIST=//') - album=$(metaflac --show-tag=ALBUM "$dir_path"/*.flac 2>/dev/null | head -n1 | sed 's/^ALBUM=//') + first_flac=$(find "$dir_path" -maxdepth 1 -type f -iname "*.flac" | head -n 1) + + if [[ -z "$first_flac" ]]; then + echo "No FLAC file found in $dir_path to extract metadata from. Skipping image: $img_file" + continue + fi + + artist=$(metaflac --show-tag=ALBUMARTIST "$first_flac" | sed 's/^ALBUMARTIST=//') + album=$(metaflac --show-tag=ALBUM "$first_flac" | sed 's/^ALBUM=//') resolved_artist="$artist" resolved_album="$album" @@ -120,4 +127,3 @@ find "$IMPORT_DIR" -type f \( -iname "*.jpg" -o -iname "*.png" \) | while read - done echo "Import completed." -