Skip to content

Instantly share code, notes, and snippets.

@hdonnay
Last active December 10, 2015 21:39
Show Gist options
  • Save hdonnay/4496761 to your computer and use it in GitHub Desktop.
Save hdonnay/4496761 to your computer and use it in GitHub Desktop.
tiny mp3 tagger based on id3v2 and a sane file layout. Now with arbitrary genre support!
#!/bin/sh
ALBUM=$(basename "`pwd`")
ARTIST=$(basename "$(dirname "`pwd`")")
TOT=$( ls -1 | grep \.mp3 | wc -l )
printf "Tagging %d track in pwd as %s / %s\n" "$TOT" "$ARTIST" "$ALBUM"
printf "Pick a genre: (enter to list, the genre id, or '255' to specify string) "
read GENRE
if [ "x${GENRE}" = "x" ]; then
id3v2 -L | less
read GENRE
elif [ "${GENRE}" -eq 255 ]; then
printf "Genre string: "
read GENRE_STRING
fi
for song in *.mp3; do
num=$(printf "$song" | sed -r 's/([0-9]{2}).+$/\1/')
title=$(printf "$song" | sed -r 's/[0-9]{2} |\.mp3//g')
if [ -z "$GENRE_STRING" ]; then
echo id3v2 -a "$ARTIST" -A "$ALBUM" -t "$title" -T "$num/$TOT" -g "$GENRE" "$song"
id3v2 -a "$ARTIST" -A "$ALBUM" -t "$title" -T "$num/$TOT" -g "$GENRE" "$song"
else
echo id3v2 -a "$ARTIST" -A "$ALBUM" -t "$title" -T "$num/$TOT" --TCON "$GENRE_STRING" "$song"
id3v2 -a "$ARTIST" -A "$ALBUM" -t "$title" -T "$num/$TOT" --TCON "$GENRE_STRING" "$song"
fi
done
if which mpc > /dev/null 2>&1; then
mpc update
fi
if [ ! -f cover.jpg ]; then
url="http://www.albumart.org/index.php?skey=$(printf "$ALBUM"| sed 's/ /+/g')&itempage=1&newsearch=1&searchindex=Music"
printf "Fetching cover...\n"
curl -# "$(curl -s "$url" | awk -F 'src=' '/zoom-icon.jpg/ {print $2}' | cut -d '"' -f 2 | head -n1)" > cover.jpg
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment