Subject: | Mishandling with ID3v2 tags |
MPEG::Audio::Frame sometimes 'finds' apparently valid frames in the
ID3v2 tags present at the beginnings of some files (courtesy of the
ludicrously overcomplicated ID3v2 format). It's necessary to scan for
and skip these tags first, or the final hash value can include them.
Find attached:
- two mp3s with equal audio data; one with id3v2 tag and one without
- two scripts; one manually skips id3 tags, the other shows the output
of Audio::Digest::MP3 (call with filename argument)
Thanks for the handy module :)
Subject: | test_tag.mp3 |
Message body not shown because it is not plain text.
Subject: | hash_correct.pl |
#!/usr/pkg/bin/perl
use Digest::SHA1 qw(sha1_hex);
use MPEG::Audio::Frame;
my $sha1 = Digest::SHA1->new();
open IN, "<", $ARGV[0] || die("Can't open input!");
my $h;
while (1) {
my $n = read IN, $h, 10;
unless ($n==10 && $h =~ /^ID3/) {
seek(IN, -$n, 1);
last;
};
print "found id3 tag ";
my @szb = unpack("C4", substr($h, 6, 4));
my $len = ((((($szb[0] << 7) | $szb[1]) << 7) | $szb[2]) << 7) | $szb[3]; # 7-bit ints, sigh
print "len $len\n";
seek (IN, $len, 1);
};
# print "starting parse at " . tell(IN) . "\n";
tie *MP3, 'MPEG::Audio::Frame', *IN;
while (<MP3>) {
$sha1->add($_);
# print "off " . $_->offset . " length " . $_->length . " " . sha1_hex($_->asbin()) . "\n";
}
print "SHA1-" . $sha1->hexdigest() . "\n";
Subject: | hash_with_module.pl |
#!/usr/pkg/bin/perl
use Digest::SHA1;
use Audio::Digest::MP3;
my $info = Audio::Digest::MP3->scan(shift @ARGV, 'SHA1');
return unless $info;
print "SHA1-" . $info->digest() . "\n";
Subject: | test_tag2.mp3 |
Message body not shown because it is not plain text.