#!/bin/bash # script to fix where flac tags are set correctly but navidrome still sees them as having [Unknown album] and [Unknown artist] # usage: fix_unknown_album_and_artist_flac_file.sh FILENAME [LOCATION] [-l] # parameters: # FILENAME: file to fix. Can be a relative or absolute path # LOCATION: optional, location of the file, if the script is run from a different directory than where the file to fix is. # -l LISTFILE: optional, location of file containing multiple files to fix, each starting with a new line. # This is the same as running the script for each single file in the list function fix_flac_file() { if [ -z "$1" ] then echo "Line is empty. Skipping" return fi echo "Fixing flac file $1" echo "running command ffmpeg -i $1 -c:a flac -map_metadata 0 fixed.flac" 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() { echo "script to fix where flac tags are set correctly but navidrome still sees them as having [Unknown album] and [Unknown artist]" echo "usage: fix_unknown_album_and_artist_flac_file.sh FILENAME [LOCATION] [-l]" echo "parameters:" echo -e "\tFILENAME: file to fix. Can be a relative or absolute path" echo -e "\tLOCATION: optional, location of the file, if the script is run from a different directory than where the file to fix is." echo -e "\t-l LISTFILE: optional, location of file containing multiple files to fix, each starting with a new line. " echo -e "\tThis is the same as running the script for each single file in the list" } if [ -z "$1" ] then echo "use the -h flag to get help on how to use this script" exit 0 fi if [ "$1" = "-h" ] then print_help exit 0 fi if [ -z "$2" ] then echo "staying in current directory" else if [ "$1" = "-l" ] then echo "Looping through $2" # 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" exit 0; else echo "moving to $2" cd "$2" fi fi fix_flac_file "$1"