Combine adding multiple keywords with NoDups?

Started by mazeckenrode, October 04, 2020, 10:32:06 PM

Previous topic - Next topic

mazeckenrode

Is there a way to combine adding multiple (arbitrary number of) keywords with using NoDups? I'm trying to get one or more words from a certain region/location in my filenames, add them all as individual keywords, and use NoDups in case any of them are already keywords. Examples:






Filenames
Keywords to add
2020-10-04 21;55;59 - Application - 00 Start.pngStart
2020-10-04 21;55;59 - Application - 02 Residence Status.pngResidence, Status
2020-10-04 21;55;59 - Application - 03 John Name Phone.pngJohn, Name, Phone

In the case of the third file above, John was already a keyword, so I was hoping to use NoDups in the same command line to skip adding it. Neither of my attempts so far worked:

ExifTool -sep " " "-EXIF:XPKeywords+<${FileName; m/.* - \d+ \[?(.*?)]?\.(?:jpe?g|png|tiff?)/; $_=$1;NoDups}" .

Resulted in all target words added as keywords, even if duplicates.

ExifTool -sep " " "-EXIF:XPKeywords+<$;NoDups{FileName; m/.* - \d+ \[?(.*?)]?\.(?:jpe?g|png|tiff?)/; $_=$1}" .

Resulted in $; NoDups{FileName; m/.*; -; \d+; \[?(.*?)]?\.(?:jpe?g|png|tiff?)/; =} added as keywords.

I have read ExifTool FAQ #17, the ExifTool Application Documentation on Helper functions, and various posts on adding multiple keywords and use of NoDups, but didn't see any examples of the two being combined the way I think I need to combine them.

StarGeek

I believe you'll have to run it as a separate command or create a user-defined tag to grab all the data and remove duplicates before copying.  NoDups only works on the tag it is embedded in.  So in the first case, it is embedded in FileName, where it does nothing as that tag is not a list type tag.  The second case just won't work as you discovered.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

mazeckenrode

Quote from: StarGeek on October 04, 2020, 10:44:36 PM
NoDups only works on the tag it is embedded in.

Ok, thanks. Now using NoDups in a separate, subsequent command line, but I must still be doing something wrong. Using command lines:

ExifTool -m -sep " " "-EXIF:XPKeywords+<${FileName; m/.* - \d+ \[?(.*?)]?\.(?:jpe?g|png|tiff?)/; $_=$1}" "-IPTC:Keywords+<${FileName; m/.* - \d+ \[?(.*?)]?\.(?:jpe?g|png|tiff?)/; $_=$1}" "-XMP:Subject+<${FileName; m/.* - \d+ \[?(.*?)]?\.(?:jpe?g|png|tiff?)/; $_=$1}" "-XMP:Keywords+<${FileName; m/.* - \d+ \[?(.*?)]?\.(?:jpe?g|png|tiff?)/; $_=$1}" .
ExifTool -sep "##" -overwrite_original "-EXIF:XPKeywords<${EXIF:XPKeywords;NoDups(1)}" "-IPTC:Keywords<${IPTC:Keywords;NoDups(1)}" "-XMP:Subject<${XMP:Subject;NoDups(1)}" "-XMP:Keywords+<${XMP:Subject;NoDups(1)}" .


Results as exported to JSON:


"XMP:Subject": ["<tag1>, <tag2>, <tag3>, John","John","Name","Phone"],
"XMP:Keywords": "<tag1>, <tag2>, <tag3>, John",
"EXIF:XPKeywords": "<tag1>, <tag2>, <tag3>, John",
"IPTC:Keywords": ["<tag1>, <tag2>, <tag3>, John","John","Name","Phone"]


Aside from the fact that the extra keywords from the filename didn't get added to XMP:Keywords or EXIF:XPKeywords at all, and NoDups didn't eliminate the duplicates from XMP:Subject or IPTC:Keywords, there's inconsistency in how the added tags are presented in the latter two compared to before the addition. Perhaps there's a flaw in the command line I've been using to tweak these keyword tags for the past two months?:

ExifTool -m -sep "##" "-IPTC:Keywords<${IPTC:Keywords;my $temp=$1 if $self->GetValue('FileName')=~m/ - 0*(\d+)(?!.* - ).*\.(?:jpe?g|png|tiff?)$/;s/(Page_?)\d+/$1$temp/}" "-XMP:Subject<${XMP:Subject;my $temp=$1 if $self->GetValue('FileName')=~m/ - 0*(\d+)(?!.* - ).*\.(?:jpe?g|png|tiff?)$/;s/(Page_?)\d+/$1$temp/}" "-XMP:Keywords<${XMP:Subject;my $temp=$1 if $self->GetValue('FileName')=~m/ - 0*(\d+)(?!.* - ).*\.(?:jpe?g|png|tiff?)$/;s/(Page_?)\d+/$1$temp/}" "-EXIF:XPKeywords<${IPTC:Keywords;my $temp=$1 if $self->GetValue('FileName')=~m/ - 0*(\d+)(?!.* - ).*\.(?:jpe?g|png|tiff?)$/;s/(Page_?)\d+/$1$temp/}" .

Phil Harvey

XMP-pdf:Keywords and EXIF:XPKeywords are simple strings, not list-type tags.  See FAQ 17 for a discussion of list-type tags.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

mazeckenrode

Quote from: Phil Harvey on October 13, 2020, 08:09:29 AM
XMP-pdf:Keywords and EXIF:XPKeywords are simple strings, not list-type tags.

Thanks, Phil. Yeah, I kind of suspected something like that, so ended up going back and re-reading the tag names/details some time after my last post. But the XMP Keywords tag I think I imagined I was using was the one listed in XMP xmp Tags. Anyway, I readily confess to not having paid enough attention to those kinds of details at the time, but think I'm slowly getting better. Of course, none of it brings much clarity on why there are tags with 'Keywords' in their names, but which don't function like other keywords tags — beyond your control, I know.

Quote
See FAQ 17 for a discussion of list-type tags.

Yep, saw that, too, and managed to fix the list-type tags I had previously screwed up by failing to use `-sep` in my command lines for writing them.

Phil Harvey

Quote from: mazeckenrode on October 13, 2020, 04:00:26 PM
the XMP Keywords tag I think I imagined I was using was the one listed in XMP xmp Tags.

That one is avoided unless the specific group is used (indicated by the "/" after Writable type).  But it isn't a list-type tag anyway.

Quotenone of it brings much clarity on why there are tags with 'Keywords' in their names, but which don't function like other keywords tags

Yes.  It is a bit of a mess.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

mazeckenrode

Quote from: Phil Harvey on October 13, 2020, 06:25:52 PM
Quote from: mazeckenrode on October 13, 2020, 04:00:26 PM
the XMP Keywords tag I think I imagined I was using was the one listed in XMP xmp Tags.

That one is avoided unless the specific group is used (indicated by the "/" after Writable type). But it isn't a list-type tag anyway.

Yes, got them now, but both of those were among the various finer points I'd failed to pick up on when I originally chose to try to use that specific tag. It's a guess for me at this point, but I probably just saw 'Keywords' at the time and figured it was what I wanted.