10 if (@ARGV && $ARGV[0] eq '--help') {
12 Usage: gal mj-digikam [<album>]
16 my $photos_root = $ENV{HOME} . '/photos';
19 if (!defined $album) {
21 $cwd =~ m{/photos/(.*)} or die "Cannot identify album from current directory, need to specify maunally.\n";
25 if (! -f "gallery.cf") {
26 system 'gal', 'mj-init'; die if $?;
29 my $dbfile = "$photos_root/digikam4.db";
30 my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "") or die "Cannot access $dbfile\n";
33 for my $r (@{$dbh->selectall_arrayref(
34 'SELECT a.id AS id, r.label AS label, a.relativePath AS rpath FROM Albums a JOIN AlbumRoots r ON (r.id = a.albumRoot)',
36 my $name = $r->{label} . $r->{rpath};
38 $alba{$name} = $r->{id};
41 my $album_id = $alba{$album} // die "Unknown album $album\n";
42 print "## Album $album: id=$album_id\n";
44 my ($tag_id) = $dbh->selectrow_array('SELECT id FROM Tags WHERE pid=0 AND name="web"');
45 $tag_id // die "Cannot find web tag\n";
46 print "## Tag ID: $tag_id\n";
48 my $res = $dbh->selectall_arrayref( <<AMEN, { Slice => {} },
51 p.latitudeNumber AS lat,
52 p.longitudeNumber AS lon,
55 JOIN ImageTags t ON (i.id = t.imageid)
56 LEFT JOIN ImagePositions p ON (i.id = p.imageid)
57 WHERE i.album=? AND t.tagid=?
58 ORDER BY i.modificationDate
64 open OUT, '|-', $ENV{GALLERY_ROOT} . '/bin/gal-scan' or die "Cannot feed gal scan\n";
66 print OUT "$photos_root/$album/" . $r->{name}, "\n";
67 for my $k (qw(lat lon alt)) {
68 print OUT "\t$k=", $r->{$k}, "\n" if defined $r->{$k};