|
From: | Richard van den Berg |
Subject: | Re: [Bug-gnupod] mktunes.pl creates corrupt iTunesDB ? |
Date: | Wed, 17 Jun 2009 22:00:16 +0200 |
User-agent: | Thunderbird 2.0.0.21 (Macintosh/20090302) |
On 6/17/09 10:41 AM, H. Langos wrote:- $mktunes->WriteItunesDB; + $mktunes->WriteItunesDB(Keep=>$opts{'keepattr'});Shouldn't that be : $mktunes->WriteItunesDB( {Keep => $opts{'keepattr'}} ); It turns out it depends on your usage. The form I chose you can used as: ($self,%args) = @_; @keep=split(/[ ,]+/, $args{Keep}); While the form with the {} can be used as: ($self,$args) = @_; @keep=split(/[ ,]+/, $args->{Keep}); Both forms are in use in the gnupod code at the moment, I just picked the first.. Here is a new patch with your suggestions and the tunes2pod code. The diff for XMLhelper.pm looks a bit weird, but all I did was move the reset code to a new resetxml() sub. The reset is needed because the playlists are stored in XDAT by doxml() and won't be overwritten by the playlists from the iTunesDB otherwise. Cheers, Richard |
? .gnupod_version ? Makefile ? autom4te.cache ? config.log ? config.status ? configure Index: doc/gnupodrc.example =================================================================== RCS file: /sources/gnupod/gnupod/doc/gnupodrc.example,v retrieving revision 1.7 diff -u -r1.7 gnupodrc.example --- doc/gnupodrc.example 5 Jun 2009 12:55:56 -0000 1.7 +++ doc/gnupodrc.example 17 Jun 2009 19:56:32 -0000 @@ -51,6 +51,14 @@ # mktunes.volume = +10 ## Enforce iPod serial number: # mktunes.fwguid = 000ba3100310abcf +## Only keep some attributes to make the iTunesDB fit inside small RAM +## The minimum attributes needed by the iPod are path and title +## Valid attributes are: +## title path album artist genre fdesc eq comment category composer group +## desc podcastguid podcastrss chapterdata subtitle tvshow tvepisode +## tvnetwork albumartist artistthe keywords sorttitle sortalbum +## sortalbumartist sortcomposer sorttvshow +# low_ram_attr = path title artist album # *** gnupod_search.pl *** Index: src/mktunes.pl =================================================================== RCS file: /sources/gnupod/gnupod/src/mktunes.pl,v retrieving revision 1.86 diff -u -r1.86 mktunes.pl --- src/mktunes.pl 8 Dec 2007 10:26:08 -0000 1.86 +++ src/mktunes.pl 17 Jun 2009 19:56:32 -0000 @@ -41,7 +41,7 @@ $opts{mount} = $ENV{IPOD_MOUNTPOINT}; GetOptions(\%opts, "version", "help|h", "ipod-name|n=s", "mount|m=s", "volume|v=i", "energy|e", "fwguid|g=s"); -GNUpod::FooBar::GetConfig(\%opts, {'ipod-name'=>'s', mount=>'s', volume=>'i', energy=>'b', fwguid=>'s', model=>'s'}, "mktunes"); +GNUpod::FooBar::GetConfig(\%opts, {'ipod-name'=>'s', mount=>'s', volume=>'i', energy=>'b', fwguid=>'s', model=>'s', low_ram_attr=>'s'}, "mktunes"); $opts{'ipod-name'} ||= "GNUpod ###__VERSION__###"; @@ -69,7 +69,12 @@ GNUpod::XMLhelper::doxml($con->{xml}) or usage("Could not read $con->{xml}, did you run gnupod_INIT.pl ?"); print "\r> ".$mktunes->GetFileCount." files parsed, assembling iTunesDB...\n"; - $mktunes->WriteItunesDB; + + my $keep = {}; + foreach(split(/[ ,]+/,$opts{'low_ram_attr'})) { + $keep->{$_}++; + } + $mktunes->WriteItunesDB(keep=>$keep); if($fwguid) { my $k = GNUpod::Hash58::HashItunesDB(FirewireId=>$fwguid, iTunesDB=>$con->{itunesdb}); Index: src/tunes2pod.pl =================================================================== RCS file: /sources/gnupod/gnupod/src/tunes2pod.pl,v retrieving revision 1.49 diff -u -r1.49 tunes2pod.pl --- src/tunes2pod.pl 2 Feb 2008 11:42:58 -0000 1.49 +++ src/tunes2pod.pl 17 Jun 2009 19:56:32 -0000 @@ -35,6 +35,8 @@ use vars qw(%opts); $| = 1; +my $xml_files_parsed=0; +my $gtdb = {}; print "tunes2pod.pl Version ###__VERSION__### (C) Adrian Ulrich\n"; @@ -65,6 +67,11 @@ exit(1); } + print "> Parsing XML document...\n"; + GNUpod::XMLhelper::doxml($con->{xml}) or usage("Could not read $con->{xml}, did you run gnupod_INIT.pl ?"); + GNUpod::XMLhelper::resetxml; + print "\r> ".$xml_files_parsed." files parsed, converting iTunesDB...\n"; + open(ITUNES, $con->{itunesdb}) or usage("Could not open $con->{itunesdb}"); while(<ITUNES>) {}; sysseek(ITUNES,0,0); # the iPod is a sloooow mass-storage device, slurp it into the fs-cache @@ -197,7 +204,7 @@ sub MhitEnd { my($self, %args) = @_; if($self->{mode} == MODE_SONGS) { - GNUpod::XMLhelper::mkfile({file=>$self->{ctx}}); # Add <file element to xml + GNUpod::XMLhelper::mkfile({file=>MergeGtdbCtx($self->{ctx})}); # Add <file element to xml $self->{ctx} = (); # And drop this buffer my $i = ++$self->{count_songs_done}; if($i % 32 == 0) { @@ -344,11 +351,35 @@ $self->ResetPlaylists; # Resets podcast and normal playlist data } - - - - - +######################################################################### +# Merge GNUtunesDB with ctx +sub MergeGtdbCtx { + my($Ctx) = @_; + return $Ctx unless $Ctx->{id} && $gtdb->{$Ctx->{id}}; + return {%{$gtdb->{$Ctx->{id}}}, %$Ctx}; +} + +######################################################################### +# Called by doxml if it finds a new <file tag +sub newfile { + my($item) = @_; + my $file = $item->{file}; + my $id = $file->{id}; + + $xml_files_parsed++; + print "\r> ".$xml_files_parsed." files parsed" if $xml_files_parsed % 96 == 0; + + return unless $id; + $gtdb->{$id} = {}; + foreach(keys(%$file)){ + $gtdb->{$id}->{$_}=$file->{$_}; + } +} + +######################################################################### +# Called by doxml if it a new <playlist.. has been found + sub newpl { +} sub usage { my($rtxt) = @_; Index: src/ext/Mktunes.pm =================================================================== RCS file: /sources/gnupod/gnupod/src/ext/Mktunes.pm,v retrieving revision 1.6 diff -u -r1.6 Mktunes.pm --- src/ext/Mktunes.pm 6 Oct 2007 07:26:52 -0000 1.6 +++ src/ext/Mktunes.pm 17 Jun 2009 19:56:32 -0000 @@ -34,7 +34,7 @@ ######################################################################### # Create and write the iTunesDB file sub WriteItunesDB { - my($self) = @_; + my($self,%args) = @_; my $mhbd_size = 0; my $mhsd_size = 0; @@ -52,7 +52,7 @@ $mhsd_size = tell(ITUNES); print ITUNES GNUpod::iTunesDB::mk_mhlt({songs=>$self->GetFileCount}); foreach my $item (@{$self->GetFiles}) { - print ITUNES $self->AssembleMhit($item); + print ITUNES $self->AssembleMhit(object=>$item, keep=>$args{keep}); print "\r> $i files assembled " if ($i++ % 96 == 0); } $mhsd_size = tell(ITUNES)-$mhsd_size; @@ -267,7 +267,9 @@ ######################################################################### # Builds a single mhit with mhod childs sub AssembleMhit { - my($self, $object) = @_; + my($self, %args) = @_; + my $object = $args{object}; + my $keep = $args{keep}; my $mhit = ''; # Buffer for the new mhit my $mhod_chunks = ''; # Buffer for the childs (mhods) my $mhod_count = 0; # Child counter @@ -275,6 +277,7 @@ foreach my $key (sort keys(%$object)) { my $value = $object->{$key}; next unless $value; # Do not write empty values + next if (scalar keys %$keep && !$keep->{$key}); # Only keep specific mhods my $new_mhod = GNUpod::iTunesDB::mk_mhod({stype=>$key, string=>$value}); next unless $new_mhod; # Something went wrong $mhod_chunks .= $new_mhod; Index: src/ext/XMLhelper.pm =================================================================== RCS file: /sources/gnupod/gnupod/src/ext/XMLhelper.pm,v retrieving revision 1.69 diff -u -r1.69 XMLhelper.pm --- src/ext/XMLhelper.pm 16 Jun 2009 08:35:27 -0000 1.69 +++ src/ext/XMLhelper.pm 17 Jun 2009 19:56:32 -0000 @@ -301,19 +301,23 @@ } - ############################################################# -# Parses the XML File and do events -sub doxml { - my($xmlin, %opts) = @_; - return undef unless (-r $xmlin); - ### reset some stuff if we do a second run +# Reset some stuff if we do a second run +sub resetxml { $cpn = undef; #Current PlaylistName @idpub = (); @plorder = (); $xid = 1; $XDAT = undef; - ### +} + + +############################################################# +# Parses the XML File and do events +sub doxml { + my($xmlin, %opts) = @_; + return undef unless (-r $xmlin); + &resetxml; my $p; my $ref = eval { $p = new XML::Parser(ErrorContext => 0, Handlers=>{Start=>\&eventer});
[Prev in Thread] | Current Thread | [Next in Thread] |