By Marco Fioretti
February 23, 2012, 9:00 AM PST
Takeaway: Marco Fioretti shows you his method for tagging MP3 files with as much automation as possible so that you can impose a little order on music or other audio collections.
....And now one shell way to tag MP3 files
The easiest way to prepare non-song MP3 files for proper tagging is to give them consistent and meaningful names. Once that precondition is verified, you can automatically use those names to write tags with a script like this:
Code: Select all
1 #! /bin/bash
2
3 for SONG in `find $1 -type f -name "*mp3"`
4 do
5 TITLE=`basename $SONG | cut -d_ -f1 | tr "-" " "`
6 LEAD=`basename $SONG | cut -d_ -f2 | tr "-" " "`
7 YEAR=`basename $SONG | cut -d_ -f3 | cut -c1-4`
8 id3tag --song="\"$TITLE\"" $SONG
9 id3tag --album="\"$TITLE\"" $SONG
10 id3tag --artist="\"$LEAD\"" $SONG
11 id3tag -y$YEAR $SONG
12 done
13 exit
Here I assume that each file has a name in the format TITLE_LEAD_DATE.mp3, with the first four characters of the DATE being the YEAR of recording. Of course, once you get the trick, you can easily hack the script to work with any other (constant!) naming format. Lines 5 to 7 extract title, lead and year from the file name, replacing hyphens with spaces: a file named The-Wall_Pink-Floyd-19791130.mp3 will return “The Wall