[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-gnupod] mktunes.pl creates corrupt iTunesDB ?
From: |
Richard van den Berg |
Subject: |
Re: [Bug-gnupod] mktunes.pl creates corrupt iTunesDB ? |
Date: |
Fri, 19 Jun 2009 20:26:30 +0200 |
User-agent: |
Thunderbird 2.0.0.21 (Macintosh/20090302) |
On 6/19/09 11:07 AM, H. Langos wrote:
Maybe the merge code should only be active if your memory saving feature is
active?
Here is the new patch that does just that. I love git, it's super fast. :-)
Cheers,
Richard
diff --git a/doc/gnupodrc.example b/doc/gnupodrc.example
index e290224..27b6bc0 100644
--- a/doc/gnupodrc.example
+++ b/doc/gnupodrc.example
@@ -33,24 +33,38 @@
##### NON GLOBAL OPTIONS ######
# *** mktunes.pl ***
+
## Specify the iPods name
# mktunes.ipod-name = Wurstli
+## Set --volume boost to +10 percent
+# 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
# *** on the go sync (V2 Firmware) ***
+
## Uncomment this to skip 'on-the-go' sync
# otgsync.nosync = 1
# *** tunes2pod.pl ***
+
## Uncomment to set '--force' switch to true (DANGEROUS)
# tunes2pod.force = 1
-
-# *** mktunes.pl ***
-## Set --volume boost to +10 percent
-# mktunes.volume = +10
-## Enforce iPod serial number:
-# mktunes.fwguid = 000ba3100310abcf
+## Setting the low_ram_attr option above causes tunes2pod.pl to sync
+## the attibutes in iTunesDB with those in GNUtunesDB.xml to make sure
+## attributes not present in iTunesDB will be lost
# *** gnupod_search.pl ***
diff --git a/src/ext/Mktunes.pm b/src/ext/Mktunes.pm
index c47d679..b503058 100644
--- a/src/ext/Mktunes.pm
+++ b/src/ext/Mktunes.pm
@@ -34,7 +34,7 @@ package GNUpod::Mktunes;
#########################################################################
# 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 @@ package GNUpod::Mktunes;
$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 @@ package GNUpod::Mktunes;
#########################################################################
# 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 @@ package GNUpod::Mktunes;
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;
diff --git a/src/ext/XMLhelper.pm b/src/ext/XMLhelper.pm
index 748ce22..bb7c88b 100755
--- a/src/ext/XMLhelper.pm
+++ b/src/ext/XMLhelper.pm
@@ -301,19 +301,23 @@ sub mkh {
}
-
#############################################################
-# 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});
diff --git a/src/mktunes.pl b/src/mktunes.pl
index fab4ce3..a35ef62 100644
--- a/src/mktunes.pl
+++ b/src/mktunes.pl
@@ -41,7 +41,7 @@ print "mktunes.pl ###__VERSION__### (C) Adrian Ulrich\n";
$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 @@ sub main {
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});
diff --git a/src/tunes2pod.pl b/src/tunes2pod.pl
index a19f6f3..4d37620 100644
--- a/src/tunes2pod.pl
+++ b/src/tunes2pod.pl
@@ -35,13 +35,15 @@ use constant MODE_NEWPL => 3;
use vars qw(%opts);
$| = 1;
+my $xml_files_parsed=0;
+my $gtdb = {};
print "tunes2pod.pl Version ###__VERSION__### (C) Adrian Ulrich\n";
$opts{mount} = $ENV{IPOD_MOUNTPOINT};
GetOptions(\%opts, "version", "force", "help|h", "mount|m=s");
-GNUpod::FooBar::GetConfig(\%opts, {mount=>'s', force=>'b', model=>'s'},
"tunes2pod");
+GNUpod::FooBar::GetConfig(\%opts, {mount=>'s', force=>'b', model=>'s',
low_ram_attr=>'s'}, "tunes2pod");
usage() if $opts{help};
@@ -65,6 +67,13 @@ sub convert {
exit(1);
}
+ if($opts{'low_ram_attr'}) {
+ 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 +206,7 @@ sub MhitStart {
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 +353,35 @@ sub MhypEnd {
$self->ResetPlaylists; # Resets podcast and normal playlist data
}
+#########################################################################
+# Merge GNUtunesDB with ctx
+sub MergeGtdbCtx {
+ my($Ctx) = @_;
+ return $Ctx unless $Ctx->{path} && $gtdb->{$Ctx->{path}};
+ return {%{$gtdb->{$Ctx->{path}}}, %$Ctx};
+}
+#########################################################################
+# Called by doxml if it finds a new <file tag
+sub newfile {
+ my($item) = @_;
+ my $file = $item->{file};
+ my $path = $file->{path};
+ $xml_files_parsed++;
+ print "\r> ".$xml_files_parsed." files parsed" if $xml_files_parsed %
96 == 0;
-
-
+ return unless $path;
+ $gtdb->{$path} = {};
+ foreach(keys(%$file)){
+ $gtdb->{$path}->{$_}=$file->{$_};
+ }
+}
+
+#########################################################################
+# Called by doxml if it a new <playlist.. has been found
+ sub newpl {
+}
sub usage {
my($rtxt) = @_;
- Re: [Bug-gnupod] mktunes.pl creates corrupt iTunesDB ?, (continued)
- Re: [Bug-gnupod] mktunes.pl creates corrupt iTunesDB ?, Richard van den Berg, 2009/06/17
- Re: [Bug-gnupod] mktunes.pl creates corrupt iTunesDB ?, Richard van den Berg, 2009/06/18
- Re: [Bug-gnupod] mktunes.pl creates corrupt iTunesDB ?, H. Langos, 2009/06/18
- Re: [Bug-gnupod] mktunes.pl creates corrupt iTunesDB ?, Richard van den Berg, 2009/06/18
- Re: [Bug-gnupod] mktunes.pl creates corrupt iTunesDB ?, H. Langos, 2009/06/19
- Re: [Bug-gnupod] mktunes.pl creates corrupt iTunesDB ?, Richard van den Berg, 2009/06/19
- Re: [Bug-gnupod] mktunes.pl creates corrupt iTunesDB ?, H. Langos, 2009/06/19
- Re: [Bug-gnupod] mktunes.pl creates corrupt iTunesDB ?, Richard van den Berg, 2009/06/19
- Re: [Bug-gnupod] mktunes.pl creates corrupt iTunesDB ?,
Richard van den Berg <=
Re: [Bug-gnupod] mktunes.pl creates corrupt iTunesDB ?, Richard van den Berg, 2009/06/12