Skip to content

Instantly share code, notes, and snippets.

@fzero
Created July 15, 2011 04:22
Show Gist options
  • Select an option

  • Save fzero/1084055 to your computer and use it in GitHub Desktop.

Select an option

Save fzero/1084055 to your computer and use it in GitHub Desktop.
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

fzero commented Jul 15, 2011

Copy link
Copy Markdown
Author

Edited for legibility.

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