Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

MP3::Tag - Leading zeros on 'track' truncated

by initself (Monk)
on Jan 17, 2008 at 06:34 UTC ( #662807=perlquestion: print w/ replies, xml ) Need Help??
initself has asked for the wisdom of the Perl Monks concerning the following question:

Venerable Monks,

I am using MP3::Tag for a very simple operation: parsing the id3v2 tag format into a %02d format for use with id3v1, like so:

#!/usr/bin/perl use warnings; use strict; use Data::Dumper; use MP3::Tag; my $filename = $ARGV[0]; die "Usage: $0 filename" unless $filename; my $mp3 = MP3::Tag->new($filename); $mp3->get_tags(); my $id3v1 = $mp3->{ID3v1} if exists $mp3->{ID3v1}; my $id3v2 = $mp3->{ID3v2} if exists $mp3->{ID3v2}; # Convert id3v2 track format to id3v1 my $track = $id3v2->track; $track = sprintf( "%02d", (split(/\//, $track))[0] ); $id3v1->track($track); $id3v1->write_tag();

Dumping $id3v1 right before the write_tag function shows the track field populated with "01". Dumping the tag after the write shows "1". I have torn apart both MP3::Tag and MP3::Tag::ID3v1 and I just cannot find anything that is truncating this data, althought MP3::Tag does refer to it:

2-digit numbers, or I<number1/number2> with number1,2 up to 999 are allowed for the track number (the leading 0 is stripped);

I just can't find where that is actually implemented! Can anyone help me?

Comment on MP3::Tag - Leading zeros on 'track' truncated
Select or Download Code
Re: MP3::Tag - Leading zeros on 'track' truncated
by Ryszard (Priest) on Jan 17, 2008 at 10:38 UTC
    perhaps its not explicitly stripped, it could be that the truncation you see is a result of a math operation..?
      Quite possibly as a result of getting the next track number. It's easy to use math ($t=$t+1) instead of the increment operator ($t++) causing the leading zeroes to be removed. Example:

      $ perl -e 'my $t="00";print ++$t' 01 $ perl -e 'my $t="00";print $t+1' 1
      ...roboticus
Re: MP3::Tag - Leading zeros on 'track' truncated
by martin (Pilgrim) on Jan 17, 2008 at 11:50 UTC
    The track number available in an ID3v1 tag is a small unsigned integer number stored in a single byte. If you retrieve this information once MP3::Tag has stored it in such a tag you will only get a numerical value back, without fancy formatting.

    The documentation you quote refers to parse_rex() -- a method not related to your code.

    If you want to find out about the conversion from a Perl scalar holding some numerical value into a raw byte look out for the pack function.

    Example:

    $x = pack 'C', 65; print "$x\n"; # prints the letter A $n = unpack 'C', $x; print "$n\n"; # prints the number 65
Re: MP3::Tag - Leading zeros on 'track' truncated
by Anonymous Monk on Jan 17, 2008 at 20:22 UTC
    I think you meant to say "venerable," not veritable. Not that I am monk or anything though ...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://662807]
Approved by lidden
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-09-20 11:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (158 votes), past polls