diff --git a/phosta.pl b/phosta.pl
index 41d681905670593bf1a613ee3d71fe37a7db03a6..ed6244b78bf1d0de0aa8439d90fd56b8934183e9 100755
--- a/phosta.pl
+++ b/phosta.pl
@@ -6,6 +6,8 @@
use warnings;
use strict;
use feature qw(say);
+use POSIX qw(lround);
+use Scalar::Util qw(looks_like_number);
use Cwd;
use DBI;
use File::Basename;
@@ -47,7 +49,7 @@ my ($destination_dir) = @_;
say "Scanning $destination_dir for files...";
- my $cmd = "exiftool -r -m -f -p '\$filepath##\$make##\$model##\$lens##\$lensmodel##\$focallength##\$focallengthin35mmformat##\$aperture##\$shutterspeed##\$iso##\$flash##\$datetimeoriginal' -d \"%Y-%m-%d %H:%M:%S\" -ext jpg " . $destination_dir;
+ my $cmd = "exiftool -r -m -f -p '\$filepath##\$make##\$model##\$lens##\$lensmodel##\$focallength##\$focallengthin35mmformat##\$aperture##\$exposuretime##\$iso##\$flash##\$datetimeoriginal##\$createdate' -d \"%Y-%m-%d %H:%M:%S\" -ext jpg " . $destination_dir;
my @lines = qx($cmd);
my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 })
@@ -58,13 +60,15 @@ my $emptycount = 0;
foreach (@lines)
{
chomp $_;
- my ( $file, $maker, $model, $lens, $lensmodel, $fl, $fl35, $apert, $ss, $iso, $flash, $date ) = split(/#/, $_);
- $lens = ($lens ne '-') ? $lens : $lensmodel;
+ my ( $file, $maker, $model, $lens, $lensmodel, $fl, $fl35, $apert, $exposuretime, $iso, $flash, $datetimeoriginal, $createdate ) = split(/#/, $_);
- if ($date eq '-' || $model eq '-') { $emptycount++; next; }
+ if ($model eq '-') { $emptycount++; next; }
+ $lens = ($lens ne '-') ? $lens : $lensmodel;
+ if ($datetimeoriginal eq '0000:00:00 00:00:00') { $datetimeoriginal = $createdate; }
+ $exposuretime = (looks_like_number($exposuretime) && $exposuretime < 1) ? "1/". POSIX::lround(1/$exposuretime) : $exposuretime;
my $stmt = "INSERT INTO photos (file, maker, model, lens, focallength, focallength35mm, aperture, shutterspeed, iso, flash, datetimeoriginal)
- VALUES ('$file', '$maker', '$model', '$lens', '$fl', '$fl35', '$apert', '$ss', '$iso', '$flash', '$date')";
+ VALUES ('$file', '$maker', '$model', '$lens', '$fl', '$fl35', '$apert', '$exposuretime', '$iso', '$flash', '$datetimeoriginal')";
my $rv = $dbh->do($stmt) or $errorcount++;
}
$dbh->disconnect();