Hack27.Edit ID3v2 Tags from the Command Line

Hack 27. Edit ID3v2 Tags from the Command Line

Use the id3v2 tool to update your music tags either manually on the command line or through shell scripts.

If you ever need to hack the metadata in your MP3 files but wish to have more control over the metadata reading/writing process than you get with common GUI tools, the id3v2 tool can help you. Using this tool, you can dump, change, or remove the ID3 tags from any MP3 file, which makes it perfect for calling from tools like find to dump, change, or remove all the tags in your entire MP3 collection.

The id3v2 tool is a reasonably popular program and should be prepackaged by your Linux distribution of choice. Use your distributions software installation tool to install this program. If for some reason you don't have this tool prepackaged, download the tarball from http://id3v2.sf.net, compile, and install it according to the included installation instructions.

To list the ID3v2 tag contents of an MP3 file, invoke id3v2 with the -l option:

 $ id2v3l"Dr Greenthumb.mp3" id3v1 tag info for Dr Greenthumb.mp3: Title : Dr Greenthumb Artist: Cypress Hill Album : IV Year: , Genre: Unknown (255) Comment: Track: 13 id3v2 tag info for ../Cypress Hill/IV/13 Dr Greenthumb.mp3: TIT2 (Title/songname/content description): Dr Greenthumb TALB (Album/Movie/Show title): IV TPE1 (Lead performer(s)/Soloist(s)): Cypress Hill TRCK (Track number/Position in set): 13 

This Cypress Hill track contains both ID3v1 and ID3v2 tags. ID3v1 tags appear at the end of the file and contain the name of the artist, album, and track names as well as a release year, a genre, a track number, and a comment field. ID3v1 limits the name fields to 30 characters, which all too often cuts off longer track names. The ID3v2 standard fixes this shortcoming by making many more fields of arbitrary length available to the user. Unlike ID3v1, v2 tags reside at the beginning of the file, which means that a file can contain both a v1 and a v2 tag, as does the example above. To see what you can store in ID3v2 tags, take a look at the ID3 specification pages at http://id3.org.

Each ID3v2 tag consists of a number of frames, where each frame has a four-letter identifying code and contains one piece of information (see Table 2-5). The artist name tag (Lead Performer/Soloist in ID3v2-speak) has the code TPE1, the album name TALB, and the track name TIT2.

Table 2-5. Frame identifying codes

Identifying code



Lead performer/soloist




Lyricist/text writer


Album name


Track name


Title of the original recording


Track number


Encoded by


Attached picture

Using these codes and the ones listed on the ID3 specification pages, you can change any one piece of data in the ID3v2 tag. For instance, to change the album name using id3v2, type:

 $ id3v2TALB  "New album name" sample.mp3  

This changes the album name to "New album name" in both the id3v1 and id3v2 tags. id3v2 also has the -a, -A, -t, -c, -g, -y, -T shortcut options to set the artist, album and track names, the comment, genre, year, and track number, respectively. If you want to remove the ID3 tags from a file, use the -s, -d, and -D options to remove id3v1 tag, the id3v2 tag, or both tags, respectively.

Finally, if you wanted to dump all the ID3 tags in all your MP3 files, you could do this:

 $ find  /mnt/mp3  -name \*mp3 -exec id3v2 -l {} \;  

This assumes that you stashed all your MP3 files under the /mnt/mp3 directorychange it according to your music collection organization. This find command executes id3v2l for each file it finds, which causes id3v2 to dump all the tags it finds in the MP3 file.

Pipe the output through more or less, because if you're like me, there will be lots of output.

Robert Kaye

Linux Multimedia Hacks
Linux Multimedia Hacks
ISBN: 596100760
Year: 2005
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net