Fixes on rename-tracknumber script

This commit is contained in:
Out Of Ideas 2024-07-20 15:28:39 -05:00
parent 8052fcb7ba
commit 0fc5a4e748

View file

@ -167,9 +167,9 @@ if [ ${#TRACKNUMBER} -gt 9 ]
else
if [ $VERBOSE ]
then
echo "mv \"$file\" \"0$TRACKNUMBER - $file\""
echo "mv \"$file\" \"$TRACKNUMBER - $file\""
fi
mv "$file" "0$TRACKNUMBER - $file"
mv "$file" "$TRACKNUMBER - $file"
fi
}
@ -195,6 +195,7 @@ Msg=""
# Unset variables
unset VERBOSE
unset MUSIC
############################################################
# Process the input options. Add options as needed. #
@ -223,33 +224,22 @@ done
# Display a message before the program starts
#echo "$Msg"
for file in *
do
# Loop through all .flac and .mp3 files
for file in *.flac *.mp3; do
# Ensure only songs are renamed.
if [[ $file == *.flac ]]
then
if [[ $file == *.flac ]]; then
TRACKNUMBER=$(metaflac --show-tag=TRACKNUMBER "$file" | head -n 1 | sed -r 's/^TRACKNUMBER=([0-9]+).*$/\1/')
elif [[ $file == *.mp3 ]]
then
TRACKNUMBER=$(ffprobe $file 2>&1 | grep 'track' | awk '{print $3}' | sed "s/\/[0-9]*//")
else
echo "Warning: $file does not end \`.flac\` or \`.mp3\`."
exit
elif [[ $file == *.mp3 ]]; then
TRACKNUMBER=$(ffprobe "$file" 2>&1 | grep 'track' | awk '{print $3}' | sed "s/\/[0-9]*//")
else
# Skip non-music files
continue
fi
if [ $VERBOSE ]
then
if [ $VERBOSE ]; then
echo "TRACKNUMBER = $TRACKNUMBER"
fi
# Rename $file
RenameFile
done