While idly thinking about coding an mp3 sorting program, I decided to look at my options for reading mp3 tags.
Turns out that (unless my benchmarking is off) MP3::Info is much faster than MP3::Tag. pudge was quite pleased...
If the following benchmark is completely off, I can only claim exhaustion, as it was wirtten at an hour when I should have been asleep. :-)
#!/usr/local/bin/perl
use MP3::Info;
use MP3::Tag;
use Benchmark;
use strict;
use warnings;
my $track = shift;
timethese(
shift || 10000,
{ info => sub {
my $tag = get_mp3tag($track);
my $tracknum = $tag->{TRACKNUM};
},
autotag => sub {
my $mp3 = MP3::Tag->new($track);
my $tracknum = ( $mp3->autoinfo )[1];
},
manualtag => sub {
my $mp3 = MP3::Tag->new($track);
$mp3->get_tags;
if ( exists $mp3->{ID3v1} ) {
# read some information from the tag
my $id3v1 = $mp3
->{ID3v1}; # $id3v1 is only a shortcut for $mp3
+->{ID3v1}
my $tracknum = $mp3->{ID3v1}->track;
}
if ( exists $mp3->{ID3v2} ) {
# read some information from the tag
my $tacknum = $mp3->{ID3v2}->get_frame("TRCK");
# delete the tag completely from the file
$mp3->{ID3v2}->remove_tag;
}
$mp3->close();
}
}
);