Skip to content

Instantly share code, notes, and snippets.

@ij96
Last active November 6, 2022 00:26
Show Gist options
  • Save ij96/e8c5bc9c04057d2cd4e2bcdc4fc5288a to your computer and use it in GitHub Desktop.
Save ij96/e8c5bc9c04057d2cd4e2bcdc4fc5288a to your computer and use it in GitHub Desktop.
Rename MP3 files based on metadata
# rename MP3 files based on metadata (named artist and title)
# copy this script in the same directory as the MP3 files and run
# renamed MP3 are copied to renamed/
mkdir renamed;
for f in *.mp3; do
TITLE=`ffmpeg -i "$f" 2>&1 | grep title | sed "s/ \+title \+: //"`;
ARTIST=`ffmpeg -i "$f" 2>&1 | grep artist | sed "s/ \+artist \+: //"`;
TRACK=`ffmpeg -i "$f" 2>&1 | grep track | sed "s/ \+track \+: //"`;
ZERO_TRACK=$(printf %02d ${TRACK}); # zero-padded track number
echo "Move $f to ${ARTIST} - ${TITLE}.mp3";
cp "$f" "renamed/${ARTIST} - ${TITLE}.mp3";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment