iTunes – Copying ID3 Tags in your MP3s from ID3v1 to ID3v2 in Perl
Update
I’ve consolidated this script into a new one. GO HERE : http://warped.org/blog/2009/05/03/itunes-fixing-id3-tags-in-mp3s-take-two/
Overview
MP3’s have been around almost 15 years now. In the beginning there was a slot in the top of the MP3 file where you could hold the Artist, Album Name, Title, Track Number, etc. This is called the ID3 tag, and is part of every MP3 file. Fast forward some years and the ID3 standard has changed a number of times from V1 to V2 to V2.2, V2.4, etc.
iTunes sucks. iTunes will only use the ID3v2 information in your file, even though the other info is present and perfectly usable. Thanks Apple. FAIL.
The Script
The following script is based on this one by Bob of the UK : http://rnewson.blogspot.com/2005/10/itunes-artwork-fetcher.html
#!/usr/bin/perl -w # Based on http://rnewson.blogspot.com/2005/10/itunes-artwork-fetcher.html use MP3::Tag; # Bug that you may need to patch for : https://rt.cpan.org/Ticket/Display.html?id=45647 foreach my $file (@ARGV) { next unless -r $file; id3v1_to_id3v2($file); } sub id3v1_to_id3v2 { my $file = shift; print "$file\n"; my $mp3 = MP3::Tag->new($file); $mp3->get_tags; $mp3->config('write_v24',1); my $id3v1 = $mp3->{ID3v1}; my $id3v2 = $mp3->{ID3v2}; $id3v2 = $mp3->new_tag("ID3v2") unless defined $id3v2; # === TIT2 (Title/songname/content description): Sordid # === TPE1 (Lead performer(s)/Soloist(s)): Amon Tobin # === TALB (Album/Movie/Show title): Funkungfusion: Ninja Cuts, Vol # === TYER (Year): 1998 # === TRCK (Track number/Position in set): 2 copy($id3v2, 'TPE1', $id3v1->artist); copy($id3v2, 'TALB', $id3v1->album); copy($id3v2, 'TCON', $id3v1->genre); copy($id3v2, 'TRCK', $id3v1->track); copy($id3v2, 'TIT2', $id3v1->song); copy($id3v2, 'TYER', $id3v1->year); copy($id3v2, 'COMM', 'ENG', $id3v1->comment,$id3v1->comment) if $id3v1->comment; $id3v2->write_tag; $mp3->close; } sub copy { my ($id3v2, $frame, @data) = @_; my $value = $data[0]; return unless defined $value; return unless $value !~ /^\s*$/; my $frameids = $id3v2->get_frame_ids; if (exists $$frameids{$frame}) { print " Changing $frame to @data\n"; $id3v2->change_frame($frame, @data); } else { print " Adding $frame = @data\n"; $id3v2->add_frame($frame, @data); } }
Prerequisites
This script uses MP3::Tag. I had to patch it to work around a bug. See my post on setting the compilation tag for details.
RSS 2.0 Comments Feed | Leave a Response | Trackback
Leave a Reply