Matching against keyword tags using wildcards / regular expressions

Started by swarup, May 02, 2022, 06:28:36 AM

Previous topic - Next topic

swarup

Does exiftool's command-line version allow fetching image filenames containing an xmp:keyword value that matches against a regular expression? If not regular expressions, then at least the * wildcard? Is there a GUI application for Windows suited for this task?

StarGeek

Exiftool is written in Perl so it has excellent regex support.  You just need to know enough Perl to use it, which isn't too hard.

You would use the -if option in this manner to check files, changing the double quotes to single quotes if your using Mac/Linux/Powershell
exiftool -if "$Subject=~/.*search term.*/" -Subject /path/to/files/

If you're looking for an exact match, things can get tricky.  The XMP:Subject tag (which is where keywords are stored in XMP) is treated as string in the above command, but it is stored as a list.  The the regex match is compared against the full string of keywords, not against individual keywords.  To get an exact match of a keyword, you would have to take into account the separation characters (by default, a (comma)(space) unless the -sep option is used) as well as start/end of line

Exact match
exiftool -if "$Subject=~/(^|, )exact search term(, |$)/" -Subject /path/to/files/

As for a GUI, I'm not sure how many programs have regex support for keywords.  It's not something I've check for when testing programs out.  The only one I know of is the one I use, which is Imatch by Photools, which has the best metadata support of anything I've seen.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

swarup

thanks, this is AMAZING!!! basically i oughta put the regex /here/
ive used regex in python which is largely perl compatible so it shouldnt be a problem!

something's bothering me though. ive been saving keywords under the prism namespace all this time (which is not listed as non-standard btw). but you just told me that subject is the canon tag for the job, possibly you mean the subject tag under dublin code namespace. just how important is it to store under a well-known tag? and ive already updated xmp:keyword (prism) to many images; if its necessary, how do i move them from there to xmp:subject?

--context if that matters--
ive a habit of sending screenshots i took from games to friends online, when the images fit the context of the conversation. it is a fun activity, i was originally inspired by another friend of mine. but in practice ive seen that i take a lot of screenshots (moreso because i play visual novels). so, i decided to identify them with text somehow. renaming filenames isnt such a great idea because similar filenames may occur and not all special characters are supported. hence i am here, seeking exiftool's aide and its been great!

originally i sought to rely on exif:xpkeywords cuz windows has built-in support for searching xpkeywords. but only for jpegs for whatever reason. plus xpkeywords is not a list so it must be super hard to manipulate using exiftool. besides, i need to store images in png format cuz every time i send jpegs they get compressed (games i play have minimal graphics, so a degradation becomes really noticable).

now i just gotta build a gui that can pass commands to exiftool and open images by filenames returned by exiftool. it might be a difficult job still, but ive a huge head start on that compared to the actual metadata manipulation. yay!
-----

StarGeek

Quote from: swarup on May 03, 2022, 03:55:18 AM
something's bothering me though. ive been saving keywords under the prism namespace all this time (which is not listed as non-standard btw). but you just told me that subject is the canon tag for the job, possibly you mean the subject tag under dublin code namespace.

Yes.  Using just Subject is enough.  Exiftool will write to XMP-dc:Subject by default.  IMO, when writing it's always best to keep the tags names as simple as possible unless you know exactly what you're doing.  Just the tag name if possible, then Group 0. Group 1 only if you really need to.  For example, writing Subject to a PDF will write to the Dublin Core tag by default, when you might actually want XMP-pdf:Subject, which is marked as Avoid.  That would be the time to use the full group name.  This can especially be problematic when writing to EXIF tags, as it really isn't obvious if something should go in ExifIFD, IFD0, IFD1 (or higher), SubIFD, SubIFD1 (or higher), etc.

The complete lists of groups can be found under the GetAllGroups function or by using the -listg option.

Quotejust how important is it to store under a well-known tag? and ive already updated xmp:keyword (prism) to many images; if its necessary, how do i move them from there to xmp:subject?

It depends.  If it works for you and the programs you use, then that's great.  But if your files need to be shared with someone else or if you ever decide to migrate your files to another program, then you would want to use the more common tags which are part of a standard.  The IPTC Photo Metadata Standard is the most widely used standard.

To copy from XMP-prism:Keyword to XMP-dc:Subject, you would use this command
exiftool "-XMP:Subject<XMP:Keyword" /path/to/files/

Quoteoriginally i sought to rely on exif:xpkeywords cuz windows has built-in support for searching xpkeywords

All the XP* tags (XPKeywords, XPComment, etc) are really terrible places to put important data, because they only work with Windows.  Almost no other program supports them.

But Windows will also read from the more common locations in IPTC IIM and XMP.  See this post for a list of what tags Windows will read the the properties that it fills.

Quotebut only for jpegs for whatever reason.

And tiff, but tiff is not as common except in printing, unfortunately.  But I'm guessing by this comment, you're referring to PNGs.  PNG files have truly terrible support for metadata in most programs.  Windows, for example, will read one tag and one tag only from a PNG file.  See the above link.

Quotei need to store images in png format cuz every time i send jpegs they get compressed

Heh, should have read all the way through before the above paragraph.

Quotenow i just gotta build a gui that can pass commands to exiftool and open images by filenames returned by exiftool. it might be a difficult job still, but ive a huge head start on that compared to the actual metadata manipulation. yay!

You might want to look around and see what's out there.  There are a lot of programs designed for dealing with image collections.  For simple editing, there's jExifToolGUIAdobe Bridge is free and writes to a large range of common and not so common metadata.  After that, you could step up to a full blown Digital Asset Management (DAM) program such as Lightroom, ACDSee, or Imatch (all paid) or digiKam or Darktable (both free).

After reading all of this, I get the feeling that you're not using a program that will read/write the XMP-prism tags.  I'd suggest migrating away from them.  Copying to Subject will allow you to search for files in Windows, as Windows will read that tag.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype