Author Topic: ID3 Tagging Shell Script  (Read 6011 times)

0 Members and 2 Guests are viewing this topic.

Offline Newby

  • Moderator
  • Hero Member
  • *****
  • Posts: 10877
  • Thrash!
    • View Profile
ID3 Tagging Shell Script
« on: February 12, 2006, 12:51:41 pm »
Mwhahaha. Another waste of 45 minutes, for something I'll use once or twice more. :P

http://www.newbyproductions.net/downloads/id3tagger.sh

Requirements: bash shell, id3lib (need the id3convert and id3tag binaries)

Code: [Select]
#/bin/bash
# ID3 tagger - written by newby (newbypwns@gmail.com, SPAMMERS BRING IT ON)
# Written with SOME of the terribly-tagged posts on Kerrazy in mind ;)
# Example usage: ./id3tagger.sh "Exodus/Exodus - 1985 - Bonded by Blood" 144
# Folders MUST be in format of: %artist - %year - %album/##-%songname.mp3
# Requirements: bash shell, id3lib (id3lib.sourceforge.net) (for the id3convert / id3tag binaries)
# Will fully tag your mp3s ID3v2 / ID3v1 :)
# Genre MUST be a number, so I included some common genres (again, common with kerrazy in mind) here.
# Feel free to modify/redistribute.
# Genres:
# Metal = 9
# Black Metal  = 138
# Death Metal  = 22
# Heavy Metal  = 137
# Thrash Metal = 144

for i in "$1"/*.mp3
do
        echo "\$i = $i"
        FOLDERNAME=${i#*/}
        FOLDERNAME=${FOLDERNAME%%/*}
        FILENAME=${i##*/}
        ARTIST=${FOLDERNAME%%" -"*}
        ALBUM=${FOLDERNAME##*"- "}
        YEAR=${FOLDERNAME#*" - "}
        YEAR=${YEAR%%" - "*}
        SONG=${FILENAME:3:${#FILENAME}-7}
        NUMBER=${FILENAME:0:2}
        if [ "$2" = "" ]
        then
                GENRE=137
        else
                declare -i GENRE=$2
        fi
        # echo "Foldername: $FOLDERNAME"
        # echo "Filename: $FILENAME"
        # echo "Artist Name: \"$ARTIST\""
        # echo "Album Name: \"$ALBUM\""
        # echo "Year: \"$YEAR\""
        # echo "Song Name: \"$SONG\""
        # echo "Song Number: $NUMBER"
        id3convert --strip "$i"
        id3tag --v2tag --artist="$ARTIST" --album="$ALBUM" --song="$SONG" --year="$YEAR" --track="$NUMBER" --genre="$GENRE" "$i"
        id3tag --v1tag --artist="$ARTIST" --album="$ALBUM" --song="$SONG" --year="$YEAR" --track="$NUMBER" --genre="$GENRE" "$i"
done

Example output of parsing (taken from IRC):

Quote
<b00n> $i = Possessed/Possessed - 1985 - Seven Churches/10-Death Metal.mp3
<b00n> Foldername: Possessed - 1985 - Seven Churches
<b00n> Filename: 10-Death Metal.mp3
<b00n> Artist Name: "Possessed"
<b00n> Album Name: "Seven Churches"
<b00n> Year: "1985"
<b00n> Song Name: "Death Metal"
<b00n> Song Number: 10

Example output of tagging (heavily trimmed with nicely placed grep, warning the actual output is VERY verbose):

Quote
newby@impaler:~/music$ ./id3tagger.sh "Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law" 22 | grep "attempting"
Converting Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/01-In Battle There Is No Law.mp3: attempting v1 and v2, stripped v1 and v2
Tagging Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/01-In Battle There Is No Law.mp3: attempting v2, tagged v2
Tagging Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/01-In Battle There Is No Law.mp3: attempting v1, tagged v1
Converting Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/02-Challenge For Power.mp3: attempting v1 and v2, stripped v1 and v2
Tagging Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/02-Challenge For Power.mp3: attempting v2, tagged v2
Tagging Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/02-Challenge For Power.mp3: attempting v1, tagged v1
Converting Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/03-Forgotten Existence.mp3: attempting v1 and v2, stripped v1 and v2
Tagging Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/03-Forgotten Existence.mp3: attempting v2, tagged v2
Tagging Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/03-Forgotten Existence.mp3: attempting v1, tagged v1
Converting Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/04-Denial of Destiny.mp3: attempting v1 and v2, stripped v1 and v2
Tagging Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/04-Denial of Destiny.mp3: attempting v2, tagged v2
Tagging Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/04-Denial of Destiny.mp3: attempting v1, tagged v1
Converting Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/05-Blind to Defeat.mp3: attempting v1 and v2, stripped v1 and v2
Tagging Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/05-Blind to Defeat.mp3: attempting v2, tagged v2
Tagging Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/05-Blind to Defeat.mp3: attempting v1, tagged v1
Converting Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/06-Concession of Pain.mp3: attempting v1 and v2, stripped v1 and v2
Tagging Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/06-Concession of Pain.mp3: attempting v2, tagged v2
Tagging Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/06-Concession of Pain.mp3: attempting v1, tagged v1
Converting Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/07-Attack in the Aftermath.mp3: attempting v1 and v2, stripped v1 and v2
Tagging Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/07-Attack in the Aftermath.mp3: attempting v2, tagged v2
Tagging Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/07-Attack in the Aftermath.mp3: attempting v1, tagged v1
Converting Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/08-Psychological Warfare.mp3: attempting v1 and v2, stripped v1 and v2
Tagging Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/08-Psychological Warfare.mp3: attempting v2, tagged v2
Tagging Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/08-Psychological Warfare.mp3: attempting v1, tagged v1
Converting Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/09-Nuclear Annihilation.mp3: attempting v1 and v2, stripped v1 and v2
Tagging Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/09-Nuclear Annihilation.mp3: attempting v2, tagged v2
Tagging Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law/09-Nuclear Annihilation.mp3: attempting v1, tagged v1

Example of parsed tag (as read by xmms):



Example of parsed tag (as read by id3info):

Quote
newby@impaler:~/music/Bolt Thrower/Bolt Thrower - 1988 - In Battle There Is No Law$ id3info "01-In Battle There Is No Law.mp3" 

*** Tag information for 01-In Battle There Is No Law.mp3
=== TPE1 (Lead performer(s)/Soloist(s)): Bolt Thrower
=== TALB (Album/Movie/Show title): In Battle There Is No Law
=== TIT2 (Title/songname/content description): In Battle There Is No Law
=== TYER (Year): 1988
=== TCON (Content type): (22)
=== TRCK (Track number/Position in set): 1
*** mp3 info
MPEG1/layer III
Bitrate: 192KBps
Frequency: 44KHz

Comments? Concerns? :)
- Newby
http://www.x86labs.org

Quote
[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

I'd bet that you're currently bloated like a water ballon on a hot summer's day.

That analogy doesn't even make sense.  Why would a water balloon be especially bloated on a hot summer's day? For your sake, I hope there wasn't too much logic testing on your LSAT. 

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: ID3 Tagging Shell Script
« Reply #1 on: February 12, 2006, 02:01:17 pm »
Very nice!  Hehe, saved my Carcass discography from having to be in the 1 - Compressed Albums folder for the rest of its life! :D

:-*

Offline Newby

  • Moderator
  • Hero Member
  • *****
  • Posts: 10877
  • Thrash!
    • View Profile
Re: ID3 Tagging Shell Script
« Reply #2 on: February 12, 2006, 03:20:34 pm »
Code: [Select]
for i in ArtistName/*; do ./id3tagger.sh "$i"; done
That'll run recursively on a folder as long as it's named correctly. :)
- Newby
http://www.x86labs.org

Quote
[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

I'd bet that you're currently bloated like a water ballon on a hot summer's day.

That analogy doesn't even make sense.  Why would a water balloon be especially bloated on a hot summer's day? For your sake, I hope there wasn't too much logic testing on your LSAT. 

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: ID3 Tagging Shell Script
« Reply #3 on: February 12, 2006, 03:22:21 pm »
Code: [Select]
for i in ArtistName/*; do ./id3tagger.sh "$i"; done
That'll run recursively on a folder as long as it's tagged correctly. :)

Cool!  My Pantera discography has fucked up ID3 tags too.  I'll rename the directories and see if this fixes it! :)

How hard would it be to write a shell script that recursively renames the filenames?
Quote
Pantera\ -\ 01\ -\ Ride\ My\ Rocket.mp3*
Pantera\ -\ 02\ -\ I'll\ Be\ Alright.mp3*
Pantera\ -\ 03\ -\ Tell\ Me\ If\ You\ Want\ It.mp3*
Pantera\ -\ 04\ -\ Latest\ Lover.mp3*
Pantera\ -\ 05\ -\ Biggest\ Part\ Of\ Me.mp3*
Pantera\ -\ 06\ -\ Metal\ Magic.mp3*
Pantera\ -\ 07\ -\ Widowmaker.mp3*
Pantera\ -\ 08\ -\ Nothin'\ On\ (But\ The\ Radio).mp3*
Pantera\ -\ 09\ -\ Sad\ Lover.mp3*
Pantera\ -\ 10\ -\ Rock\ Out.mp3*
Pantera\ -\ Metal\ Magic\ Front.jpg*

Offline Newby

  • Moderator
  • Hero Member
  • *****
  • Posts: 10877
  • Thrash!
    • View Profile
Re: ID3 Tagging Shell Script
« Reply #4 on: February 12, 2006, 03:27:33 pm »
Pretty hard.

Just stick to using rename on 'em.

Or do something like rename "Pantera - " "" */*.mp3 && rename " - " "-" */*.mp3 to see if that works.

I wouldn't try it unless you make a backup, though.
- Newby
http://www.x86labs.org

Quote
[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

I'd bet that you're currently bloated like a water ballon on a hot summer's day.

That analogy doesn't even make sense.  Why would a water balloon be especially bloated on a hot summer's day? For your sake, I hope there wasn't too much logic testing on your LSAT. 

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: ID3 Tagging Shell Script
« Reply #5 on: February 12, 2006, 03:37:36 pm »
That worked, I think.  I had a backup too!

Quote
sidoh@deepthought:/mnt/hdb1/usr/pub/media/MUSIC/1 - Compressed Albums$ ls -l --block-size=M pantera.tar.bz2
-rwxr-xr-x  1 sidoh media 610M 2006-01-12 02:15 pantera.tar.bz2*

Offline Newby

  • Moderator
  • Hero Member
  • *****
  • Posts: 10877
  • Thrash!
    • View Profile
Re: ID3 Tagging Shell Script
« Reply #6 on: February 12, 2006, 04:00:47 pm »
A quicker way for that ls: ls -lh <target>
- Newby
http://www.x86labs.org

Quote
[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

I'd bet that you're currently bloated like a water ballon on a hot summer's day.

That analogy doesn't even make sense.  Why would a water balloon be especially bloated on a hot summer's day? For your sake, I hope there wasn't too much logic testing on your LSAT. 

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: ID3 Tagging Shell Script
« Reply #7 on: February 12, 2006, 04:15:01 pm »
A quicker way for that ls: ls -lh <target>

Cool!

Offline Newby

  • Moderator
  • Hero Member
  • *****
  • Posts: 10877
  • Thrash!
    • View Profile
Re: ID3 Tagging Shell Script
« Reply #8 on: February 12, 2006, 04:30:23 pm »
Windows users are mad that they can't use this. :(
- Newby
http://www.x86labs.org

Quote
[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

I'd bet that you're currently bloated like a water ballon on a hot summer's day.

That analogy doesn't even make sense.  Why would a water balloon be especially bloated on a hot summer's day? For your sake, I hope there wasn't too much logic testing on your LSAT. 

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: ID3 Tagging Shell Script
« Reply #9 on: February 12, 2006, 04:32:14 pm »
Windows users are mad that they can't use this. :(

Haha, poor bastards.  I wish there was a nice, open source id3 library for windows. ._.

Offline Newby

  • Moderator
  • Hero Member
  • *****
  • Posts: 10877
  • Thrash!
    • View Profile
Re: ID3 Tagging Shell Script
« Reply #10 on: February 12, 2006, 04:41:01 pm »
http://sourceforge.net/project/showfiles.php?group_id=979

windows binaries = id3lib-3.8.3binaries.zip

Oh well. Too bad the bash script isn't portable across OS'.

My bad. It is if you have a bash shell. Too bad you Windows users and your wsh suck.

Someone should port this to batch. :)

EDIT -- Warrior plans to port this to Monad's script language, so we'll see. :)
« Last Edit: February 12, 2006, 05:21:51 pm by Newby »
- Newby
http://www.x86labs.org

Quote
[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

I'd bet that you're currently bloated like a water ballon on a hot summer's day.

That analogy doesn't even make sense.  Why would a water balloon be especially bloated on a hot summer's day? For your sake, I hope there wasn't too much logic testing on your LSAT. 

Offline rabbit

  • x86
  • Hero Member
  • *****
  • Posts: 8092
  • I speak for the entire clan (except Joe)
    • View Profile
Re: ID3 Tagging Shell Script
« Reply #11 on: February 12, 2006, 08:47:09 pm »
Newby, you forget the GNU/MinGW bash.

Offline igimo1

  • Full Member
  • ***
  • Posts: 420
    • View Profile
Re: ID3 Tagging Shell Script
« Reply #12 on: February 12, 2006, 10:21:05 pm »
I used an ID3 retagger a while back for Windows...

Offline Chavo

  • x86
  • Hero Member
  • *****
  • Posts: 2219
  • no u
    • View Profile
    • Chavoland
Re: ID3 Tagging Shell Script
« Reply #13 on: February 13, 2006, 02:52:50 am »
MediaMonkey for Windows has batch [re]naming and batch [re]tagging, its what I use.  I think there is still a free version or at least a free trial.

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: ID3 Tagging Shell Script
« Reply #14 on: February 13, 2006, 03:55:55 am »
I wrote a couple Java programs which automatically convert file structure -> id3 or id3 -> proper file structure.  The two programs are probably:
http://www.javaop.com/~iago/FixId3.jar
http://www.javaop.com/~iago/MoveMP3.jar

The source should be included in the .jar.  They are in no way well written, but I use them all the time.