]> mj.ucw.cz Git - gallery.git/blobdiff - gal/bin/gal-scan
Added caching of image hashes (optional)
[gallery.git] / gal / bin / gal-scan
index 41e2d3a607bd5183ae1f032230544a786b1c1ab5..4424cc3732b78a987b610ab776876e8be9913f87 100755 (executable)
@@ -1,14 +1,14 @@
 #!/usr/bin/perl
 # UCW Gallery: Scan images and generate image list
-# (c) 2004--2012 Martin Mares <mj@ucw.cz>
+# (c) 2004--2015 Martin Mares <mj@ucw.cz>
 
 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 = ".";
@@ -141,3 +139,4 @@ if (!$update) {
 
 $gal->write_list('gallery.list', \@images);
 print "Written gallery.list (", (scalar @images), " items)\n";
+$hashes->write;