diff --git a/fix_unknown_album_and_artist_flac_file.sh b/fix_unknown_album_and_artist_flac_file.sh index 1972346..054dcb3 100755 --- a/fix_unknown_album_and_artist_flac_file.sh +++ b/fix_unknown_album_and_artist_flac_file.sh @@ -15,10 +15,14 @@ function fix_flac_file() echo "running command ffmpeg -i $1 -c:a flac -map_metadata 0 fixed.flac" - ffmpeg -i "$1" -c:a flac -map_metadata 0 "fixed.flac" - - echo "moving fixed.flac to $1" - mv "fixed.flac" "$1" + if ffmpeg -nostdin -i "$1" -c:a flac -map_metadata 0 fixed.flac + then + echo "Moving fixed.flac to $1" + mv fixed.flac "$1" + else + echo "Failed to process $1" >&2 + rm -f fixed.flac + fi } function print_help() @@ -51,7 +55,8 @@ else if [ "$1" = "-l" ] then echo "Looping through $2" - while read flacfile; do + # Use IFS= and -r with read so backslashes and leading/trailing whitespace are preserved + while IFS= read -r flacfile; do echo "Processing line $flacfile" fix_flac_file "$flacfile" done < "$2"