Sync the RegionName to the Keywords fields

Started by brunos, November 01, 2022, 10:49:54 AM

Previous topic - Next topic

brunos

Hi all,

In thousands of photos in the archive I manage, the RegionName content and the Keywords content are not synced.

There are tags in two formats:
• The format A is for the RegionName field and it is "code space name space last name", set automatically by Picasa.
• The format B is for the Keywords field. It uses the same code, name and last name, but starting with the prefix "t:" and the colons instead of spaces (requirements for phrase searches)

I would need to synchronize the Keywords field with the RegionName field, respecting the following conditions:
1. Keep the RegionName tag "as is".
2. Convert in memory the copy of the RegionName tag into the format B.
3. Check if the converted tag exists in the Keywords – in that case, skip it and go to the next tag if any.
4. If the converted tag does not exist, add it to the Keywords field. Note that the order of tags in the RegionName and Keywords is not important.
5. Go to the next photo and repeat all.

I tried to adapt the following examples, but the first one doesn't convert and doesn't avoid duplicates, and the second one doesn't replace spaces with colons...
exiftool "-keywords+<xmp:RegionName" -m -r -ext jpg e:\aa\ev\
exiftool "-keywords<${keywords@;/^t:/ or s/^:?/t:/}" -sep "||" -r -ext jpg -overwrite_original E:\AA\

EXAMPLE OF THE ACTUAL SITUATION
RegionName: aN0M John Doe, aN0F Jane Doe
Keywords: t:aN0F:Jane:Doe

EXAMPLE OF THE SITUATION AFTER PROCESSING
RegionName: aN0M John Doe, aN0F Jane Doe
Keywords: t:aN0F:Jane:Doe, t:aN0M:John:Doe

NOTES
The 0 in aN0* codes is zero. The caps are to be preserved.

Thanks a million!
Bruno

PS. I would know how to write this in VB, in VBA and in Autoit, unfortunatelly the exiftool is still a darkwood for me... sigh...

StarGeek

The first part regarding duplicates is covered in FAQ #17.  You have to remove the keyword you're adding and then add it back in to avoid duplication. You also have to use -AddTagsFromFile @ (this is something that always throws me off). Using your first example command, the command would be
exiftool "-keywords-<xmp:RegionName" "-keywords+<xmp:RegionName" -m -r -ext jpg e:\aa\ev\

Personally, I'm lazy and I don't worry about duplicates and add everything that I need to.  After I'm finished processing those files, I then run a final command using the NoDups helper function.  But then, I do a lot of things manually and in a script, the above command would be simpler.

Adding region names with a t: prefix and spaces changed to colons is a bit more complex.  Personally, I would use the -api Filter option.  This would affect all regions to be added.  The downside is that it would also edit any other tag copy operation, so you would have to use it separately from anything else.  You also have to use -AddTagsFromFile @
exiftool -api "Filter=s/^/t:/;s/ /:/g" -addtagsfromfile @ "-keywords-<xmp:RegionName" "-keywords+<xmp:RegionName" -m -r -ext jpg e:\aa\ev\

Example output
C:\>exiftool -sep "||" -G1 -a -s -RegionName -Keywords y:\!temp\Test4.jpg
[XMP-mwg-rs]    RegionName                      : aN0M John Doe||aN0F Jane Doe
[IPTC]          Keywords                        : t:aN0F:Jane:Doe

C:\>exiftool -P -overwrite_original -api "Filter=s/^/t:/;s/ /:/g" -addtagsfromfile @ "-keywords-<xmp:RegionName" "-keywords+<xmp:RegionName" y:\!temp\Test4.jpg
Warning: Shift value for XMP-xmp:Keywords is not a number - y:/!temp/Test4.jpg
    1 image files updated

C:\>exiftool -sep "||" -G1 -a -s -RegionName -Keywords y:\!temp\Test4.jpg
[XMP-mwg-rs]    RegionName                      : aN0M John Doe||aN0F Jane Doe
[IPTC]          Keywords                        : t:aN0M:John:Doe||t:aN0F:Jane:Doe


"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

brunos

#2
Thanks, Stargeek! You did it all already! Just tested your three commands on a sample pic which initially had only two tags in the RegionName and nothing oin Keywords. It got them both converted and added. Then I run it again on the same pic and no duplicates appeared. Perfect! Thank again for the quick resolution!

Kindest regards
Bruno