diff --git a/phosta.pl b/phosta.pl

index e39c7555459b6bfe7e20dfc88f96a601beebe114..f314a68b6953e6d4f7becef7e99459b73b56648e 100755

--- a/phosta.pl

+++ b/phosta.pl

@@ -7,10 +7,10 @@ use v5.32;

use warnings;

no warnings 'experimental';

use strict;

-use feature qw(say);

-use POSIX qw(lround);

+use feature 'say';

+use POSIX 'lround';

use Text::SimpleTable::AutoWidth;

-use Scalar::Util qw(looks_like_number);

+use Scalar::Util 'looks_like_number';

use Cwd;

use DBI;

use Getopt::Std;

@@ -25,16 +25,18 @@

my $configfile = catfile(File::HomeDir->my_home, '.phosta.conf');

# read commandline switches

+our $opt_E='jpg,jpeg';

our $opt_D=getcwd . "/photo_stats.db";

our $opt_p='';

our $opt_t='';

our $opt_c=0;

our $opt_s='';

our $opt_g='';

+our $opt_v=0;

getconfig($configfile);

-getopts('cp:g:s:t:D:') or die "Invalid parameters provided! See 'phosta --help' for more details.";

+getopts('vcp:g:s:t:D:E:') or die "Invalid parameters provided! See 'phosta --help' for more details.";

validate() or die "Invalid parameters provided! See 'phosta --help' for more details.";

my $dsn = "DBI:SQLite:dbname=$opt_D";

@@ -65,6 +67,8 @@ }

if ($opt_t ne '' && $opt_t !~ /^([0-9]{8}){0,1}\-([0-9]{8}){0,1}$/) { return 0; }

+ if ($opt_E !~ /^([a-z]{2,4}){1,}(\,[a-z]{2,4}){0,}$/) { return 0; }

+

return 1;

}

@@ -79,6 +83,7 @@ {

my ( $config_filename ) = @_;

open(my $filehandle, '>', $config_filename) or die "Could not open file '$config_filename': $!";

say $filehandle '$opt_D="'. $opt_D .'";';

+ say $filehandle '$opt_E="'. $opt_E .'";';

close $filehandle;

}

@@ -88,6 +93,7 @@ my ($dbfile) = @_;

my $dbh = DBI->connect($dsn, '', '', { RaiseError => 1 }) or die $DBI::errstr;

my $stmt = 'CREATE TABLE photos (file TEXT PRIMARY KEY, maker TEXT, model TEXT, lensmake TEXT, lens TEXT, focallength INTEGER, focallength35mm INTEGER, aperture DECIMAL, exposuretime TEXT, iso INTEGER, flash TEXT, datetimeoriginal DATETIME);';

+ if ($opt_v) { say "### DB Statement: $stmt"; }

my $rv = $dbh->do($stmt);

}

@@ -96,9 +102,12 @@ {

my ($destination_dir) = @_;

say "Scanning $destination_dir for images...";

-

- my $cmd = "exiftool -fast2 -r -m -f -p '\$filepath##\$make##\$model##\$lensmake##\$lens##\$lensmodel##\$focallength##\$focallengthin35mmformat##\$aperture##\$exposuretime##\$shutterspeed##\$iso##\$flash##\$datetimeoriginal' -d \"%Y-%m-%d %H:%M:%S\" -ext jpg " . $destination_dir;

- my @lines = qx($cmd);

+

+ my $extensions = ' -ext ' . join(' -ext ', split(/\,/, $opt_E)) .' ';

+

+ my $cmd = "exiftool -fast2 -r -m -f -p '\$filepath##\$make##\$model##\$lensmake##\$lens##\$lensmodel##\$focallength##\$focallengthin35mmformat##\$aperture##\$exposuretime##\$shutterspeed##\$iso##\$flash##\$datetimeoriginal' -d \"%Y-%m-%d %H:%M:%S\" " . $extensions . $destination_dir;

+ if ( $opt_v ) { say "### Exiftool command: $cmd"; }

+ my @lines = `$cmd`;

my $dbh = DBI->connect($dsn, '', '', { RaiseError => 1 }) or die $DBI::errstr;

my $errorcount = 0;

@@ -126,7 +135,7 @@ }

$dbh->disconnect();

say sprintf('%5d', $emptycount). ' image files skipped due to missing EXIF data';

say sprintf('%5d', $errorcount). ' image files skipped due to errors';

- say "Updated local database $opt_D.";

+ say "Updated database $opt_D.";

}

sub get_sql

@@ -210,12 +219,12 @@

my $dbh = DBI->connect($dsn, '', '', { RaiseError => 1 }) or die $DBI::errstr;

my $total_count = $dbh->selectrow_array("SELECT count(file) from photos");

- say "Querying local database with $total_count entries...";

+ say "Querying database $opt_D with $total_count entries...";

say '';

my $tb = Text::SimpleTable::AutoWidth->new();

- #say get_sql($selected, $grouping);

+ if ($opt_v) { say '### SQL Statement: '. get_sql($selected, $grouping); }

my $stmt = $dbh->prepare(get_sql($selected, $grouping));

$stmt->execute();

while (my @row = $stmt->fetchrow_array)

@@ -247,13 +256,17 @@ say '';

say 'generic options:';

say ' -D <file> : path and name of the db file to use, defaults to <workingdir>/photo_stats.db';

say ' This option is automatically saved in the user conf, you can omit this option if you always use the same db';

- say ' -c : clear the database before populating with data from the folder';

+ say ' -c : clear the database';

+ say ' -v : be verbose - print some debug output';

say ' --help : show this help';

say '';

say 'data gathering:';

say ' -p <folder> : populate database from the files in the specified folder';

say ' Media files in the given folder and every subfolder are scanned, EXIF data extracted and pulled into the database';

- say '';

+ say ' -E <ext> : list of comma separated extensions used for scanning image files, defaults to jpg,jpeg';

+ say ' only media files which match (case-insensitive!) the given extensions are added to the database';

+ say ' This option is saved to the user conf';

+ say '';

say 'stats querying:';

say ' -g : group by time range, defaults to total (which means no grouping by time range)';

say ' allowed values: year, month, week, hour';