Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A quick automatic tagger for MP3 (uses eyeD3 - http://eyed3.nicfit.net)
#!/bin/bash
# This expects files ordered like:
# Artist/Album/01 Track Title.mp3
#
# You should provide the dir containing the Artist dirs at the command line.
START="$1"
if [ "$START" == "" ]; then
echo "You must tell me where to start."
exit 1
fi
cd "$START"
for ARTIST in *; do
if [ "$ARTIST" == "VA" ]; then
# Avoids albums by Various Artists
continue
fi
cd "$ARTIST"
for ALBUM in *; do
cd "$ALBUM"
if [ "$(ls *.mp3)" == "" ]; then
# Skips empty dirs/non-mp3 files (for now)
cd ..
continue
fi
for FILE in *.mp3; do
TRACK=$(echo "$FILE" | egrep -o ^[0-9]{2})
SONG=$(echo "$FILE" | sed s/^[0-9][0-9]\ // | sed s/\.mp3$//)
# Workaround for eyeD3 bug with UTF8 chars
eyeD3 --to-v2.4 "$FILE"
# DO IT!
eyeD3 --to-v2.4 --set-encoding=utf8 \
--artist "$ARTIST" \
--album "$ALBUM" \
--title "$SONG" \
--track $TRACK "$FILE" || exit 1
done
cd ..
done
cd ..
done
#!/bin/bash
# Same as masstagger, but for albums by Various Artists
# Differences: uses one less directory level and detects artists/titles differently.
#
# Expects files like:
# VA/Album/01 Artist Name - Track Title.mp3
#
# You should provide the "VA" dir at the command line.
START="$1"
if [ "$START" == "" ]; then
echo "You must tell me where to start."
exit 1
fi
cd "$START"
for ALBUM in *; do
cd "$ALBUM"
if [ "$(ls *.mp3)" == "" ]; then
# Skips empty dirs/non-mp3 files (for now)
cd ..
continue
fi
for FILE in *.mp3; do
TRACK=$(echo "$FILE" | egrep -o ^[0-9]{2})
ARTIST=$(echo "$FILE" | sed s/^[0-9][0-9]\ // | sed s/\.mp3$// | sed s/\ \-.*//)
SONG=$(echo "$FILE" | sed s/^[0-9][0-9]\ // | sed s/\.mp3$// | sed s/"$ARTIST - "//)
# Workaround for eyeD3 bug with UTF8 chars
eyeD3 --to-v2.4 "$FILE"
# DO IT!
eyeD3 --to-v2.4 --set-encoding=utf8 \
--artist "$ARTIST" \
--album "$ALBUM" \
--title "$SONG" \
--track $TRACK "$FILE" || exit 1
done
cd ..
done
@fzero

This comment has been minimized.

Copy link
Owner Author

@fzero fzero commented Jul 15, 2011

Yeah, it's full of bad practices, but I hacked this in less than one hour and it worked for me and my files. Feel free do adapt for your own messy library. :-)

@fzero

This comment has been minimized.

Copy link
Owner Author

@fzero fzero commented Jul 15, 2011

Edited for legibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment