X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=gal%2Fbin%2Fgal-scan;h=4424cc3732b78a987b610ab776876e8be9913f87;hb=a89f2eee3e06facd7b9b2cfce35e2c38828b4134;hp=0cdff942663b41429db9e53e970a9b64f1071823;hpb=807cfec9d967b9262a416da4b11f68832c0e8425;p=gallery.git diff --git a/gal/bin/gal-scan b/gal/bin/gal-scan index 0cdff94..4424cc3 100755 --- a/gal/bin/gal-scan +++ b/gal/bin/gal-scan @@ -1,14 +1,14 @@ #!/usr/bin/perl # UCW Gallery: Scan images and generate image list -# (c) 2004--2012 Martin Mares +# (c) 2004--2015 Martin Mares use strict; use warnings; use UCW::Gallery; +use UCW::Gallery::Hashes; use File::Spec; use Image::EXIF; -use Digest::SHA; use Getopt::Long; if (@ARGV && $ARGV[0] eq '--help') { @@ -60,6 +60,8 @@ if ($update) { } } +my $hashes = UCW::Gallery::Hashes->new($gal); + print "Scanning photos\n"; my @images = (); foreach my $src (@source) { @@ -75,11 +77,7 @@ foreach my $src (@source) { my $path = File::Spec->rel2abs($name, $gal->get('OrigDir')); -f $path or die "Cannot find $path\n"; - if (!defined $src->{id}) { - my $sha = Digest::SHA->new(1); - $sha->addfile($path) or die "Cannot hash $path\n"; - $src->{id} = substr($sha->hexdigest, 0, 16); - } + $src->{id} = $hashes->hash_image($path); print " id=", $src->{id}; if (!defined $src->{orientation} || $src->{orientation} eq '-') { @@ -94,7 +92,7 @@ foreach my $src (@source) { if ($o eq "Top, Left-Hand") { $o = "."; } elsif ($o eq "Right-Hand, Top") { $o = "r"; } elsif ($o eq "Left-Hand, Bottom") { $o = "l"; } - elsif ($o eq "Bottom, Right-Hand") { $o = "d"; } + elsif ($o eq "Bottom, Right-Hand") { $o = "u"; } else { print "Unrecognized orientation: $o\n"; $o = "."; @@ -116,25 +114,29 @@ if (!$update) { my $old = $gal->read_list('gallery.list'); if ($old) { print "Updating gallery.list\n"; - my %old_by_id = map { $_->{id} => $_ } @$old; - for my $i (@images) { - my $id = $i->{id}; - my $o = $old_by_id{$id}; - if ($o) { - print "\t$id: updated\n"; - $i->{orientation} = $o->{orientation}; - $i->{xfrm} = $o->{xfrm}; - $i->{title} = $o->{title}; - } else { - print "\t$id: new\n"; + my %new_by_id = map { $_->{id} => $_ } @images; + my @result = (); + for my $o (@$old) { + my $id = $o->{id}; + my $i = $new_by_id{$id}; + if (!$i) { + print "\t$id: removed\n"; + next; } - delete $old_by_id{$id}; + print "\t$id: updated\n"; + push @result, $o; + delete $new_by_id{$id}; } - for my $id (keys %old_by_id) { - print "\t$id: removed\n"; + for my $i (@images) { + my $id = $i->{id}; + $new_by_id{$id} or next; + print "\t$id: new\n"; + push @result, $i; } + @images = @result; } } $gal->write_list('gallery.list', \@images); print "Written gallery.list (", (scalar @images), " items)\n"; +$hashes->write;