Skip to content

Instantly share code, notes, and snippets.

@silvasur
Created August 18, 2014 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silvasur/4508b9c695a124f239ac to your computer and use it in GitHub Desktop.
Save silvasur/4508b9c695a124f239ac to your computer and use it in GitHub Desktop.
Mass retagging of mp3 files that don't have ID3 tags
#!/bin/sh
# Mass retagging of mp3 files that don't have ID3 tags.
# The MP3 files must be named like this to use this script:
# ./<first letter of artist>/<artist>/<album>/<track number> - <title>.<file extension(s)>
# ^-- The current working directory
exsomething() { echo "$1" | sed 's#'"$2"'#\1#'; }
exartist() { exsomething "$1" '^\././\([^/]*\)/.*$'; }
exalbum() { exsomething "$1" '^\././[^/]*/\([^/]*\)/.*$'; }
extrack() { exsomething "$1" '^\././[^/]*/[^/]*/0*\([0-9]*\)\s*-.*$'; }
extitle() { exsomething "$1" '^\././[^/]*/[^/]*/[0-9]*\s*-\s*\([^\.]*\)\.[^\.]*$'; }
hasinfo() { id3info "$1" | grep Title >/dev/null; }
retag() { id3tag -a"$(exartist "$1")" -A"$(exalbum "$1")" -s"$(extitle "$1")" -t"$(extrack "$1")" "$1"; }
find -type f | while read fn; do
if ! hasinfo "$fn"; then
retag "$fn"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment