Hi,
here's an alternative. Shell scripts are, hmm, shell scripts ;-) Doesn't
call external programs, just uses a per module.
#!/usr/bin/perl -w
# Author: Michael Staats (michael.staats at gmx.de)
# Free according to GPL
# $Id: picdate2fn 819 2016-12-17 13:18:00Z michael $
use strict;
use Image::ExifTool qw(:Public);
use Date::Parse;
use POSIX qw(strftime);
use Getopt::Std;
my %Opt;
getopts('vnp:o:', \%Opt);
$Opt{o} = int($Opt{o} || 0);
$Opt{p} = $Opt{p} ? '-' . $Opt{p} : '';
my $exif = new Image::ExifTool(); # we need exactly one object
die "Usage: $0 [-n] [-p prefix] [-o offset] file [...]\n"
unless($ARGV[0]);
######################################################################################################
ARG: foreach my $a (@ARGV) {
my $tt = gettime($a);
next ARG unless ($tt);
$tt += $Opt{o};
my $nfn = strftime("%Y%m%d-%H%M%S", localtime($tt)) . $Opt{p} . '-'
. $a;
print "$a\t->\t$nfn\n";
rename($a, $nfn) unless($Opt{n});
}
sub gettime {
my $f = $_[0];
my $pt;
open(F, $f) or do {
warn "$f: $!\n";
return undef;
};
close(F);
my $data = ImageInfo($f);
if ($Opt{v}) {
print "Exif Info of $f\n";
foreach my $k (keys(%$data)) {
print "$k: ", $data->{$k}, "\n";
}
print "\n";
}
my $date = $data->{CreateDate} || $data->{DateTimeOriginal};
if ($date) {
$pt = str2time($date);
} else {
warn "$f: has no Exif-CreateDate, using mtime instead\n";
$pt = (stat($f))[9];
}
return $pt;
}
Regards,
Michael
--
Michael Staats
[email protected]
____________________________________________________________________________
darktable user mailing list
to unsubscribe send a mail to [email protected]