[KPhotoAlbum] Command line filtering

Robert Krawitz rlk at alum.mit.edu
Thu Feb 21 03:37:18 CET 2019


On Sat, 16 Feb 2019 19:17:08 -0500, 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.

I managed to squeeze in some time (the upside of installs that take a
long time :-) ) to implement something quick and dirty that does this;
I stuck it in contrib for people to play with.  It does not handle
EXIF data at this time, but there's no question that that would be
useful.  Slurping in the EXIF data would add considerable overhead in
the cases it isn't needed.

Performance isn't too bad.  On my 300K+ database it takes about 20
seconds to run everything through the filter (which is interestingly
not too much more than kpa startup -- and the former is not exactly
highly optimized by perl, while the latter is compiled).  The
technique is to build the entire loop ove the images and then eval the
whole thing.  That pushes it all though the perl compiler.

There's a help message that describes how to use it.
-- 
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