Add MP3 finctionality

This commit is contained in:
Out Of Ideas 2024-01-03 11:58:22 -06:00
parent 8a32a3f3bc
commit fc93b4bae5
1 changed files with 45 additions and 24 deletions

View File

@ -39,6 +39,8 @@
# #
# 02/01/2024 Out Of Ideas File renaming issue fixed. #
# #
# 02/01/2024 Out Of Ideas MP3 functionality has been #
# added; not tested. #
############################################################
############################################################
############################################################
@ -148,6 +150,28 @@ CheckMetaflac()
fi
}
RenameFile ()
{
# If the track number is less than 10, put a 0 before it in the new song title.
# Eg. "Song", with track number "1", is renamed to "01 - Song".
if [ ${#TRACKNUMBER} -gt 9 ]
then
if [ $VERBOSE ]
then
echo "mv \"$file\" \"$TRACKNUMBER - $file\""
fi
mv "$file" "$TRACKNUMBER - $file"
else
if [ $VERBOSE ]
then
echo "mv \"$file\" \"0$TRACKNUMBER - $file\""
fi
mv "$file" "0$TRACKNUMBER - $file"
fi
}
############################################################
# Main Program #
############################################################
@ -198,36 +222,33 @@ done
# Display a message before the program starts
#echo "$Msg"
read -p 'File extension: ' EXTENSION
for file in *
do
# Ensure only songs are renamed.
if [[ $file == *.$EXTENSION ]]
if [[ $file == *.flac ]]
then
TRACKNUMBER=$(metaflac --show-tag=TRACKNUMBER "$file" | head -n 1 | sed -r 's/^TRACKNUMBER=([0-9]+).*$/\1/')
if [ $VERBOSE ]
then
echo "TRACKNUMBER = $TRACKNUMBER"
fi
# If the track number is less than 10, put a 0 before it in the new song title.
# Eg. "Song", with track number "1", is renamed to "01 - Song".
if [ ${#TRACKNUMBER} -gt 9 ]
then
if [ $VERBOSE ]
then
echo "mv \"$file\" \"$TRACKNUMBER - $file\""
fi
mv "$file" "$TRACKNUMBER - $file"
else
if [ $VERBOSE ]
then
echo "mv \"$file\" \"0$TRACKNUMBER - $file\""
fi
mv "$file" "0$TRACKNUMBER - $file"
fi
elif [[ $file == *.mp3 ]]
then
TRACKNUMBER=$(ffprobe $file 2>&1 | grep 'track' | awk '{print $3}' | sed "s/\/[0-9]*//")
else
echo 'Error: No `.flac` or `.mp3` files found.'
exit
fi
if [ $VERBOSE ]
then
echo "TRACKNUMBER = $TRACKNUMBER"
fi
# Rename $file
RenameFile
done