[KPhotoAlbum] Command line filtering

Robert Krawitz rlk at alum.mit.edu
Sun Feb 17 17:05:20 CET 2019


On Sun, 17 Feb 2019 00:36:47 -0500, Joe wrote:
> On 2/16/19 7:17 PM, Robert Krawitz wrote:
>> For a project I might or might not do, I was thinking of writing a
>> script to list the images in an index.xml file, with optional
>> filtering on the command line or via a file.
>>
>> The filter "syntax" would actually be a perl expression.  This sounds
>> inefficient, but it can be done via creating the loop as a string with
>> the filter expression embedded, and then eval'ing the entire loop.
>> One-off tags like filename, start/end date, height, width etc. would
>> be expressed as simple variables; an invocation might look like
>>
>> kpa-filter index.xml '($height * $width > 20000000) && (has_keyword("foo") || matches_person("krawitz") || matches_category("Places", "USA"))'
>>
>> or put the expression in a file and use it via -f.  The output would
>> be a list of filenames.
>>
>> Do people think this would be interesting?  I should warn everyone
>> that the next month will be very busy for me (I'm hoping it will be,
>> at any rate) depending upon how deep we go in the NCAA Division III
>> basketball postseason.
> TL;DR: It's a great idea and creates many possibilities.

I did the barest of prototypes (with no filtering) last night.  It
takes longer than I'd like; it took about 15 seconds to just run
through all 300K images, extract the kpa data, and print out the
paths.

I've done this kind of filtering thing before, where the filter is
essentially a perl expression (or program).  It can be done
efficiently.

> You could do things like tag some photos with a particular tag and then
> have an automated script come along later and find them and put them
> through an automated work flow. Lots of possibilities!

Yes.

> I assume when you say "file names", you mean file paths - because the
> name alone wouldn't tell you where they are - and there could be files
> with duplicate names in different directories.

Of cousre.

> Also, the syntax of your example above would need a bit of tweaking. It
> has to be able to reference whatever categories and tags the user has
> defined in KPA. E.g. I have a top level category of Animals that I would
> need to be able select values from.

has_keyword("foo") is shorthand for has_category("Keyword", "foo").

> I don't actually need to do any of this now, but I bet someone else does.
>
> I guess I'd have to learn some perl to use this. I know bash and GNU
> BREs and EREs.

When I've done this in the past, you usually don't need to know more
than $variable syntax (which is familiar to shell scripters) and
regular expression syntax if you want to do something a little
fancier.  If you want to get more elaborate, you'd need to know some
perl.
-- 
Robert Krawitz                                     <rlk at alum.mit.edu>

***  MIT Engineers   A Proud Tradition   http://mitathletics.com  ***
Member of the League for Programming Freedom  --  http://ProgFree.org
Project lead for Gutenprint   --    http://gimp-print.sourceforge.net

"Linux doesn't dictate how I work, I dictate how Linux works."
--Eric Crampton


More information about the KPhotoAlbum mailing list