9 my $photos_root = $ENV{HOME} . '/photos';
12 if (!defined $album) {
14 $cwd =~ m{/photos/(.*)} or die "Cannot identify album from current directory, need to specify maunally.\n";
18 if (! -f "gallery.cf") {
19 system 'gal', 'mj-init'; die if $?;
22 my $dbfile = "$photos_root/digikam4.db";
23 my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "") or die "Cannot access $dbfile\n";
26 for my $r (@{$dbh->selectall_arrayref(
27 'SELECT a.id AS id, r.label AS label, a.relativePath AS rpath FROM Albums a JOIN AlbumRoots r ON (r.id = a.albumRoot)',
29 my $name = $r->{label} . $r->{rpath};
31 $alba{$name} = $r->{id};
34 my $album_id = $alba{$album} // die "Unknown album $album\n";
35 print "## Album $album: id=$album_id\n";
37 my ($tag_id) = $dbh->selectrow_array('SELECT id FROM Tags WHERE pid=0 AND name="web"');
38 $tag_id // die "Cannot find web tag\n";
39 print "## Tag ID: $tag_id\n";
41 open OUT, '|-', $ENV{GALLERY_ROOT} . '/bin/gal-scan' or die "Cannot feed gal scan\n";
42 for my $r (@{$dbh->selectall_arrayref(
43 'SELECT i.name AS name FROM Images i JOIN ImageTags t ON (i.id = t.imageid) WHERE i.album=? AND t.tagid=? ORDER BY i.name',
45 $album_id, $tag_id)}) {
46 print OUT "$photos_root/$album/" . $r->{name}, "\n";