Mac-iPod-GNUpod

 view release on metacpan or  search on metacpan

GNUpod/iTunesDBread.pm  view on Meta::CPAN

        push(@ret, {field=>$field,action=>$action,string=>$rs});
    }
    return \@ret;
}

# Read SPLpref data
sub read_splpref {
    my($hs) = @_;
    my ($live, $chkrgx, $chklim, $mos);

    $live    = 1 if   get_int($hs->{start}+24,1);
    $chkrgx  = 1 if get_int($hs->{start}+25,1);
    $chklim  = 1 if get_int($hs->{start}+26,1);
    my $item =    get_int($hs->{start}+27,1);
    my $sort =    get_int($hs->{start}+28,1);
    my $limit=   get_int($hs->{start}+32,4);
    $mos     = 1 if get_int($hs->{start}+36,1);
    return({
        live=>$live,
        value=>$limit, 
        iitem=>$item, 
        isort=>$sort,
        mos=>$mos,
        checkrule=>($chklim+($chkrgx*2))
    });
}

# Do a hexDump DEBUGGING ONLY
sub __hd {
    open(KK,">/tmp/XLZ"); print KK $_[0]; close(KK);
    system("hexdump -vC /tmp/XLZ");
}

#get a SINGLE mhod entry:
# return+seek = new_mhod should be there
sub get_mhod {
    my ($seek) = @_;

    my $id  = get_string($seek, 4);          #are we lost?
    my $ml  = get_int($seek+8, 4);           #Length of this mhod
    my $mty = get_int($seek+12, 4);          #type number
    my $xl  = get_int($seek+28,4);           #String length

    ## That's spl stuff, only to be used with 51 mhod's
    my $htm = get_int($seek+35,1); #Only set for 51
    my $anym= get_int($seek+39,1); #Only set for 51
    my $spldata = undef; #dummy
    my $splpref = undef; #dummy

    if($id eq "mhod") { #Seek was okay
        my $foo = get_string($seek+($ml-$xl), $xl); #string of the entry 
        #$foo is now UTF16 (Swapped), but we need an utf8
        $foo = Unicode::String::byteswap2($foo);
        $foo = Unicode::String::utf16($foo)->utf8;

        ##Special handling for SPLs
        if($mty == 51) { #Get data from spldata mhod
            $foo = undef;
            $spldata = read_spldata({start=>$seek, htm=>$htm});
        }
        elsif($mty == 50) { #Get prefs from splpref mhod
            $foo = undef;
            $splpref = read_splpref({start=>$seek, end=>$ml});
        }
        return({size=>$ml,string=>$foo,type=>$mty,spldata=>$spldata,splpref=>$splpref,matchrule=>$anym});

    }
    else {
        return({size => -1});
    }
}

# get an mhip entry
sub get_mhip {
    my($pos) = @_;
    my $oid = 0;
    if(get_string($pos, 4) eq "mhip") {
        my $oof = get_int($pos+4, 4);
        my $mhods=get_int($pos+12,4);

        for(my $i=0;$i<$mhods;$i++) {
            my $mhs = get_mhod($pos+$oof)->{size};
            die "Fatal seek error in get_mhip, can't continue\n" if $mhs == -1;
            $oid+=$mhs;
        }

        my $plid = get_int($pos+5*4,4);
        my $sid  = get_int($pos+6*4, 4);
        return({size=>($oid+$oof),sid=>$sid,plid=>$plid});
    }

    #we are lost
    return ({size=>-1});
}

# Reads a string
sub get_string {
    my ($start, $anz) = @_;
    my($buffer) = undef;

    # paranoia
    $start = int($start);
    $anz = int($anz);
    seek(FILE, $start, 0);

    #start reading
    read(FILE, $buffer, $anz);
    return $buffer;
}

# Get a playlist (Should be called get_mhyp, but it does the whole playlist)
sub get_pl {
    my($pos) = @_;

    my %ret_hash = ();
    my @pldata = ();

    if(get_string($pos, 4) eq "mhyp") { #Ok, its an mhyp
        $ret_hash{type}= get_int($pos+20, 4); #Is it a main playlist?
        my $scount     = get_int($pos+16, 4); #How many songs should we expect?
        my $header_len = get_int($pos+4, 4);  #Size of the header



( run in 2.990 seconds using v1.01-cache-2.11-cpan-97f6503c9c8 )