Created
August 18, 2014 20:14
-
-
Save silvasur/4508b9c695a124f239ac to your computer and use it in GitHub Desktop.
Mass retagging of mp3 files that don't have ID3 tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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