fixing mp3 id3 tags in unix
I was browsing through my music collection and found a soundtrack to Natural Born Killers.
I thought, great- I’ll put this in my ipod.
The ipod organizes by album, track, and artist.
I put these files in, but the track names, album, etc – were all messed up!!!
It seems they were encoded in Japanese or Chinese- most likely.
So- what to do?
As a human being, visually, I had all the data I needed.
But what would I do, tag each one separately? Fix the id3 tags by hand?
Hell no, that’s why I run unix- not to so stupid shit like that.
So, I solved it. Here’s how.
(You’ll need id3tag command, it’s in libid3tag package )
My file listing:
$ ls 01 - Leonard Cohen - Waiting For The Miracle.mp3 02 - L7 - Shitlist.mp3 03 - Dan Zanes - Moon Over Greene County.mp3 04 - Patti Smith - Rock & Roll Nigger.mp3 05 - Cowboy Junkies - Sweet Jane.mp3 06 - Bob Dylan - You Belong To Me.mp3 07 - Duane Eddy - The Trembler.mp3 08 - Nine Inch Nails - Burn.mp3 09 - Brian Berdan - Route 666.mp3 10 - Remmy Ongala - Totally Hot.mp3 11 - Patsy Cline - Back In Baby's Arms.mp3 12 - Peter Gabriel - Taboo.mp3 13 - Jane's Addiction - Sex Is Violent.mp3 14 - AOS - History (Repeats Itself).mp3 15 - Nine Inch Nails - Something I Can Never Have.mp3 16 - Russell Means - I Will Take You Home.mp3 17 - Hollywood Persuaders - Drums A Go-Go.mp3 18 - Barry Adamson - Hungry Ants.mp3 19 - Dr.Dre - The Day The Niggaz Took Over.mp3 20 - Juliette Lewis - Born Bad.mp3 21 - Sergio Cervetti - Fall Of The Rebel Angels.mp3 22 - Lard - Forkboy.mp3 23 - Budapest Philharmonic - Batonga In Batongaville.mp3 24 - Nine Inch Nails - A Warm Place.mp3 25 - Khan & Nusrat Fateh - Allah, Mohammed, Char, Yaar.mp3 26 - Leonard Cohen - The Future.mp3 27 - Dogg Pound - What Would U Do.mp3 data newfile scan0001.jpg scan0002.jpg scan0003.jpg scan0004.jpg scan0005.jpg scan0006.jpg scan0007.jpg
I know the album is ‘Natural Born Killers’. I can tell the id3 tag info I need from the filenames. I need to format this to fit id3tag commands such as:
idt3tag --artist='Peter Gabriel' --album='Natural Born Killers' --track=12 --song='Taboo' '12 - Peter Gabriel - Taboo.mp3'
-
Create a dsv
What I’m going to do is create a delimiter separated values file (dsv) for short.
We know that each ‘field’ is separated here by ‘ – ‘, we cannot set the delimiter to be more than one character at a time (this is not perl, this is bash- so we need to make the field delimiter be one character. Let’s use the colon (as do password files).
for file in *mp3 ; do record=$(echo $file | sed 's/ - /:/g' | sed 's/\.mp3//') ; echo "$record:$file" >> data ; done
Great, let’s check out the data…
$ cat data 01:Leonard Cohen:Waiting For The Miracle:01 - Leonard Cohen - Waiting For The Miracle.mp3 02:L7:Shitlist:02 - L7 - Shitlist.mp3 03:Dan Zanes:Moon Over Greene County:03 - Dan Zanes - Moon Over Greene County.mp3 04:Patti Smith:Rock & Roll Nigger:04 - Patti Smith - Rock & Roll Nigger.mp3 05:Cowboy Junkies:Sweet Jane:05 - Cowboy Junkies - Sweet Jane.mp3 06:Bob Dylan:You Belong To Me:06 - Bob Dylan - You Belong To Me.mp3 07:Duane Eddy:The Trembler:07 - Duane Eddy - The Trembler.mp3 08:Nine Inch Nails:Burn:08 - Nine Inch Nails - Burn.mp3 09:Brian Berdan:Route 666:09 - Brian Berdan - Route 666.mp3 10:Remmy Ongala:Totally Hot:10 - Remmy Ongala - Totally Hot.mp3 11:Patsy Cline:Back In Baby's Arms:11 - Patsy Cline - Back In Baby's Arms.mp3 12:Peter Gabriel:Taboo:12 - Peter Gabriel - Taboo.mp3 13:Jane's Addiction:Sex Is Violent:13 - Jane's Addiction - Sex Is Violent.mp3 14:AOS:History (Repeats Itself):14 - AOS - History (Repeats Itself).mp3 15:Nine Inch Nails:Something I Can Never Have:15 - Nine Inch Nails - Something I Can Never Have.mp3 16:Russell Means:I Will Take You Home:16 - Russell Means - I Will Take You Home.mp3 17:Hollywood Persuaders:Drums A Go-Go:17 - Hollywood Persuaders - Drums A Go-Go.mp3 18:Barry Adamson:Hungry Ants:18 - Barry Adamson - Hungry Ants.mp3 19:Dr.Dre:The Day The Niggaz Took Over:19 - Dr.Dre - The Day The Niggaz Took Over.mp3 20:Juliette Lewis:Born Bad:20 - Juliette Lewis - Born Bad.mp3 21:Sergio Cervetti:Fall Of The Rebel Angels:21 - Sergio Cervetti - Fall Of The Rebel Angels.mp3 22:Lard:Forkboy:22 - Lard - Forkboy.mp3 23:Budapest Philharmonic:Batonga In Batongaville:23 - Budapest Philharmonic - Batonga In Batongaville.mp3 24:Nine Inch Nails:A Warm Place:24 - Nine Inch Nails - A Warm Place.mp3 25:Khan & Nusrat Fateh:Allah, Mohammed, Char, Yaar:25 - Khan & Nusrat Fateh - Allah, Mohammed, Char, Yaar.mp3 26:Leonard Cohen:The Future:26 - Leonard Cohen - The Future.mp3 27:Dogg Pound:What Would U Do:27 - Dogg Pound - What Would U Do.mp3
Looks good? Yes? No? Edit and make changes to your data file as wanted.
-
Create the id3tag commands
Now we’re going to use unix ‘read’ to create out commands..
$ IFS=':'; cat data | while read track artist song file; do echo id3tag --artist=\'$artist\' --song=\'$song\' --track=$track --album=\'Natural Born Killers\' \'$file\'; done > commands
Notice that we set IFS to colon.
Let’s revise our commands..$ cat commands id3tag --artist='Leonard Cohen' --song='Waiting For The Miracle' --track=01 --album='Natural Born Killers' '01 - Leonard Cohen - Waiting For The Miracle.mp3' id3tag --artist='L7' --song='Shitlist' --track=02 --album='Natural Born Killers' '02 - L7 - Shitlist.mp3' id3tag --artist='Dan Zanes' --song='Moon Over Greene County' --track=03 --album='Natural Born Killers' '03 - Dan Zanes - Moon Over Greene County.mp3' id3tag --artist='Patti Smith' --song='Rock & Roll Nigger' --track=04 --album='Natural Born Killers' '04 - Patti Smith - Rock & Roll Nigger.mp3' id3tag --artist='Cowboy Junkies' --song='Sweet Jane' --track=05 --album='Natural Born Killers' '05 - Cowboy Junkies - Sweet Jane.mp3' id3tag --artist='Bob Dylan' --song='You Belong To Me' --track=06 --album='Natural Born Killers' '06 - Bob Dylan - You Belong To Me.mp3' id3tag --artist='Duane Eddy' --song='The Trembler' --track=07 --album='Natural Born Killers' '07 - Duane Eddy - The Trembler.mp3' id3tag --artist='Nine Inch Nails' --song='Burn' --track=08 --album='Natural Born Killers' '08 - Nine Inch Nails - Burn.mp3' id3tag --artist='Brian Berdan' --song='Route 666' --track=09 --album='Natural Born Killers' '09 - Brian Berdan - Route 666.mp3' id3tag --artist='Remmy Ongala' --song='Totally Hot' --track=10 --album='Natural Born Killers' '10 - Remmy Ongala - Totally Hot.mp3' id3tag --artist='Patsy Cline' --song='Back In Baby's Arms' --track=11 --album='Natural Born Killers' '11 - Patsy Cline - Back In Baby's Arms.mp3' id3tag --artist='Peter Gabriel' --song='Taboo' --track=12 --album='Natural Born Killers' '12 - Peter Gabriel - Taboo.mp3' id3tag --artist='Jane's Addiction' --song='Sex Is Violent' --track=13 --album='Natural Born Killers' '13 - Jane's Addiction - Sex Is Violent.mp3' id3tag --artist='AOS' --song='History (Repeats Itself)' --track=14 --album='Natural Born Killers' '14 - AOS - History (Repeats Itself).mp3' id3tag --artist='Nine Inch Nails' --song='Something I Can Never Have' --track=15 --album='Natural Born Killers' '15 - Nine Inch Nails - Something I Can Never Have.mp3' id3tag --artist='Russell Means' --song='I Will Take You Home' --track=16 --album='Natural Born Killers' '16 - Russell Means - I Will Take You Home.mp3' id3tag --artist='Hollywood Persuaders' --song='Drums A Go-Go' --track=17 --album='Natural Born Killers' '17 - Hollywood Persuaders - Drums A Go-Go.mp3' id3tag --artist='Barry Adamson' --song='Hungry Ants' --track=18 --album='Natural Born Killers' '18 - Barry Adamson - Hungry Ants.mp3' id3tag --artist='Dr.Dre' --song='The Day The Niggaz Took Over' --track=19 --album='Natural Born Killers' '19 - Dr.Dre - The Day The Niggaz Took Over.mp3' id3tag --artist='Juliette Lewis' --song='Born Bad' --track=20 --album='Natural Born Killers' '20 - Juliette Lewis - Born Bad.mp3' id3tag --artist='Sergio Cervetti' --song='Fall Of The Rebel Angels' --track=21 --album='Natural Born Killers' '21 - Sergio Cervetti - Fall Of The Rebel Angels.mp3' id3tag --artist='Lard' --song='Forkboy' --track=22 --album='Natural Born Killers' '22 - Lard - Forkboy.mp3' id3tag --artist='Budapest Philharmonic' --song='Batonga In Batongaville' --track=23 --album='Natural Born Killers' '23 - Budapest Philharmonic - Batonga In Batongaville.mp3' id3tag --artist='Nine Inch Nails' --song='A Warm Place' --track=24 --album='Natural Born Killers' '24 - Nine Inch Nails - A Warm Place.mp3' id3tag --artist='Khan & Nusrat Fateh' --song='Allah, Mohammed, Char, Yaar' --track=25 --album='Natural Born Killers' '25 - Khan & Nusrat Fateh - Allah, Mohammed, Char, Yaar.mp3' id3tag --artist='Leonard Cohen' --song='The Future' --track=26 --album='Natural Born Killers' '26 - Leonard Cohen - The Future.mp3' id3tag --artist='Dogg Pound' --song='What Would U Do' --track=27 --album='Natural Born Killers' '27 - Dogg Pound - What Would U Do.mp3'
Look good? Revise, edit at will..
-
Do it
Now we run the commands..
sh commands
Done.
Unix rules.
