MPEG-ID3v2Tag

 view release on metacpan or  search on metacpan

lib/MPEG/ID3v2Tag.pm  view on Meta::CPAN

####
sub parse_data {
    my ( $self, $data ) = @_;

    #  ($self->{ENCODING}, $self->{DATA}) = unpack("CZ*", $data) ;
    $self->{ENCODING} = unpack( "C", substr( $data, 0, 1 ) );

    if ( $self->{ENCODING} == 0 ) {
        $self->{DATA} = unpack( "Z*", substr( $data, 1 ) );
    }
    elsif ( $self->{ENCODING} == 1 ) {    ##with BOM
        ######## a really dirty hack to change the UNICODE to normal ISO-8859-1  this will of course
        ######## destroy the real unicode. so no need to write a UNICODE back to file
        my @text_as_list;
        $self->{BOM} = unpack( "n", substr( $data, 1, 2 ) );
        if ( $self->{BOM} == 0xfeff ) {
            @text_as_list = unpack( "n*", substr( $data, 3 ) );
        }
        else {
            @text_as_list = unpack( "v*", substr( $data, 3 ) );
        }
        $self->{DATA} = pack( "C*", @text_as_list );
        $self->{ENCODING} = 0;    ## now
    }
    elsif ( $self->{ENCODING} == 2 ) {    #no BOM here   ##never tested
        ######## a really dirty hack to change the UNICODE to normal ISO-8859-1  this will of course
        ######## destroy the real unicode. so no need to write a UNICODE back to file

        ## I hope this n is working for ENCODING type 2. else change to back to v like type 1
        my @text_as_list;
        @text_as_list = unpack( "v*", substr( $data, 1 ) );
        $self->{DATA} = pack( "C*", @text_as_list );
        $self->{ENCODING} = 0;    ## now
    }
    elsif ( $self->{ENCODING} == 3 ) {    ##never tested

lib/MPEG/ID3v2Tag.pm  view on Meta::CPAN

    ( $self->{ENCODING}, $self->{LANGUAGE} ) = unpack( "Ca3", substr( $data, 0, 4 ) );

    my $textpos = index( $data, "\0", 4 ) + 1;
    my $desc = substr( $data, 4, $textpos - 5 );
    my $text = substr( $data, $textpos );

    if ( $self->{ENCODING} == 0 ) {
        $self->{DESCRIPTION} = $desc;
        $self->{TEXT}        = $text;
    }
    elsif ( $self->{ENCODING} == 1 ) {    ##with BOM
        ######## a really dirty hack to change the UNICODE to normal ISO-8859-1  this will of course
        ######## destroy the real unicode. so no need to write a UNICODE back to file
        my @text_as_list_t;
        my @text_as_list_d;

        $self->{BOM} = unpack( "n", substr( $data, 1, 2 ) );
        if ( $self->{BOM} == 0xfeff ) {
            @text_as_list_t = unpack( "n*", substr( $text, 2 ) );
            @text_as_list_d = unpack( "n*", substr( $desc, 2 ) );
        }
        else {
            @text_as_list_t = unpack( "v*", $text );
            @text_as_list_d = unpack( "v*", $desc );
        }
        $self->{DESCRIPTION} = pack( "C*", @text_as_list_d );
        $self->{TEXT}        = pack( "C*", @text_as_list_t );
        $self->{ENCODING} = 0;    ## now



( run in 2.317 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )