commit b1aaa6f9743f70d65bc321843cc59ef458646392
parent d68acebdae56856d47048ec0330104bdb7a267d6
Author: René Wagner <rwagner@rw-net.de>
Date: Tue, 28 Jul 2020 22:11:55 +0200
fill photo_stats.db from exiftool
Diffstat:
2 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
@@ -4,9 +4,25 @@ This project is about a small project providing some stats of your photography.
It is mainly a small [SQlite](https://sqlite.org) database that stores the data which is extracted from the exif data of your images using [exiftool](https://exiftool.org/) and provides some predefined statistics about the data.
-### requirements
+## requirements
The famous `exiftool` needs to be installed on your system.
+### bare scripts
+Simply clone the repo or manually download the scripts from https://git.sr.ht/~rwa/photo-stats/
+
+To run a script, open a shell and invoke `perl script.pl`, on most systems it should be sufficient to just invoke `script.pl` (after you granted execute-permissions to the script).
+Prerequisites for running the pure scripts
+
+- Perl 5.30 (or newer)
+
+Additionally the following perl modules need to be installed:
+
+- Cwd
+- DBI
+- Perl::DBD::SQLite
+- File::HomeDir
+- File::Spec::Functions
+
## available stats
- pictures by lens
- pictures by camera body
diff --git a/phosta.pl b/phosta.pl
@@ -7,11 +7,18 @@ use warnings;
use strict;
use feature qw(say);
use Cwd;
+use DBI;
use File::Basename;
use File::Spec::Functions;
use File::HomeDir;
use Getopt::Std;
+my $driver = "SQLite";
+my $database = "photo_stats.db";
+my $dsn = "DBI:$driver:dbname=$database";
+my $userid = "";
+my $password = "";
+
$Getopt::Std::STANDARD_HELP_VERSION = 'true';
my $VERSION = '0.1';
@@ -46,13 +53,26 @@ sub get_stats
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##\$shutterspeed##\$iso##\$flash##\$datetimeoriginal' -d \"%Y-%m-%d %H:%M:%S\" -ext jpg " . $destination_dir;
my @lines = qx($cmd);
+ my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 })
+ or die $DBI::errstr;
+ $dbh->do('DELETE FROM photos');
+ my $errorcount = 0;
foreach (@lines)
{
- say "$_";
+ chomp $_;
+ my ( $file, $maker, $model, $lens, $lensmodel, $fl, $fl35, $apert, $ss, $iso, $flash, $date ) = split(/#/, $_);
+ $lens = ($lens ne '-') ? $lens : $lensmodel;
+
+ ($date ne '-' && $model ne '-') or next;
+
+ 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')";
+ my $rv = $dbh->do($stmt) or die $DBI::errstr;
}
+ $dbh->disconnect();
}
sub getconfig