Recursive copying/adding of certain tags to keywords

Started by timitalia, February 13, 2022, 09:20:14 AM

Previous topic - Next topic

timitalia

I would like to add the $Make and $Model tags into keywords for all photos in a folder (including Subfolders).
If one of these Tags does not exist, this should not cause the script to abort.

Similar to this command for example:

exiftool -r -sep ", " -keywords="keyword1, keyword2" $dir


Unlike the command above, I do not want to overwrite the existing keywords, but to add Make and Model tags from the photo.

I found and played arround wih this:

exiftool -r -addTagsFromFile @ "-keywords+<Make" "-keywords+<Model" $dir


It does not really work for me:

  • The + in "-keywords+<Make" does not seem to work:

    • When there is already a keyword in a photo (before executing the command) nothing is added
    • If there was no keyword yet, only the latter one, in my case Model, is added (instead of Make and Model)
  • In some cases I get copies of the images with "_original" at the end of the file extention and I don't yet understand why
But I think I should just ask how to do this right:
With which command could I recursively add $Make and $Model tags (only if present in the photo) to Keywords for all photos in a directory (so that existing keywords remain present)?

Cheers Tim


StarGeek

Quote from: timitalia on February 13, 2022, 09:20:14 AM
It does not really work for me:

The + in "-keywords+<Make" does not seem to work:
When there is already a keyword in a photo (before executing the command) nothing is added
If there was no keyword yet, only the latter one, in my case Model, is added (instead of Make and Model)

I can't duplicate that here.  Three files.  The first has Make, Model, and Keywords set.  The second is missing Model.  The third is missing Keywords.

C:\Programs\My_Stuff>exiftool -G1 -a -s -Make -Model -Keywords Y:\!temp\aaaa
======== Y:/!temp/aaaa/Test1.jpg
[IFD0]          Make                            : EXIF:Make
[IFD0]          Model                           : EXIF:Model
[IPTC]          Keywords                        : FirstKeyword
======== Y:/!temp/aaaa/Test2.jpg
[IFD0]          Make                            : EXIF:Make
[IPTC]          Keywords                        : FirstKeyword
======== Y:/!temp/aaaa/Test3.jpg
[IFD0]          Make                            : EXIF:Make
[IFD0]          Model                           : EXIF:Model
    1 directories scanned
    3 image files read

C:\Programs\My_Stuff>exiftool -ext jpg -P -overwrite_original -AddTagsFromFile @ "-Keywords+<Make" "-Keywords+<Model" Y:\!temp\aaaa
    1 directories scanned
    3 image files updated

C:\Programs\My_Stuff>exiftool -G1 -a -s -Make -Model -Keywords Y:\!temp\aaaa
======== Y:/!temp/aaaa/Test1.jpg
[IFD0]          Make                            : EXIF:Make
[IFD0]          Model                           : EXIF:Model
[IPTC]          Keywords                        : FirstKeyword, EXIF:Make, EXIF:Model
======== Y:/!temp/aaaa/Test2.jpg
[IFD0]          Make                            : EXIF:Make
[IPTC]          Keywords                        : FirstKeyword, EXIF:Make
======== Y:/!temp/aaaa/Test3.jpg
[IFD0]          Make                            : EXIF:Make
[IFD0]          Model                           : EXIF:Model
[IPTC]          Keywords                        : EXIF:Make, EXIF:Model
    1 directories scanned
    3 image files read


In all three cases, Make and Model were added to Keywords if they existed.

QuoteIn some cases I get copies of the images with "_original" at the end of the file extention and I don't yet understand why

From the docs
     By default the original files are preserved with _original appended to their names -- be sure to verify that the new files are OK before erasing the originals.

Add the -overwrite_original option to suppress the creation of backup files.  You can use the -delete_original option to delete them or delete them as you normally would through command line or desktop.
* 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).

timitalia

@StarGeek Many thanks for your answer! I liked your test setup and I have been able to learn from it: This test setup and your hint regarding the -overwrite_original option helped me figure out that it basically works, but it seems there is a problem with adding keywords to *.HEIC files.
Because what I didn't mention, in my first attempt today I only tried it with HEIC files. With HEIC Files it does not work.

But here now a new example to demonstrate, this time with 2 JPG files and 1 HEIC file:

  • IMG_A.JPG: Has Model, Make, and a keyword
  • IMG_B.JPG: Is missing Model and Make, but has a keyword
  • IMG_C.HEIC: Has Model and Make, but no keyword


➜  Pictures exiftool -G1 -a -s -Make -Model -Keywords ~/Pictures/poc
======== /Users/t9836/Pictures/poc/IMG_A.JPG
[IFD0]          Make                            : FUJIFILM
[IFD0]          Model                           : X-T3
[IPTC]          Keywords                        : somekeyword
======== /Users/t9836/Pictures/poc/IMG_B.JPG
[IPTC]          Keywords                        : somekeyword
======== /Users/t9836/Pictures/poc/IMG_C.HEIC
[IFD0]          Make                            : Apple
[IFD0]          Model                           : iPhone 7
    1 directories scanned
    3 image files read


After running this command:

exiftool -P -overwrite_original -AddTagsFromFile @ "-Keywords+<Make" "-Keywords+<Model" ~/Pictures/poc


It worked except for the HEIC file:


➜  Pictures exiftool -G1 -a -s -Make -Model -Keywords ~/Pictures/poc
======== /Users/t9836/Pictures/poc/IMG_A.JPG
[IFD0]          Make                            : FUJIFILM
[IFD0]          Model                           : X-T3
[IPTC]          Keywords                        : somekeyword, FUJIFILM, X-T3
======== /Users/t9836/Pictures/poc/IMG_B.JPG
[IPTC]          Keywords                        : somekeyword
======== /Users/t9836/Pictures/poc/IMG_C.HEIC
[IFD0]          Make                            : Apple
[IFD0]          Model                           : iPhone 7
    1 directories scanned
    3 image files read



  • IMG_A.JPG: Added Model and Make to existing keyword => fine
  • IMG_B.JPG: Added Nothing to existing keyword as Make and Model not present => fine
  • IMG_C.JPG: Hmm, should have added Make and Model to Keywords

Then I added a keyword to this HEIC file by "brute force":


exiftool -Keywords="somekeyword" ~/Pictures/poc/IMG_C.HEIC

E voilà:

➜  Pictures exiftool -Keywords  ~/Pictures/poc/IMG_C.HEIC
Keywords                        : somekeyword


But wait, this here revealed:

➜  Pictures exiftool -G1 -a -s -Make -Model -Keywords ~/Pictures/poc/IMG_C.HEIC
[IFD0]          Make                            : Apple
[IFD0]          Model                           : iPhone 7
[XMP-pdf]       Keywords                        : somekeyword


So the conclusion is

  • The direct assignement added the keywort at least, but to [XMP-pdf] (not as with JPGs to [IFD0]) 
  • The preferred -AddTagsFromFile way from above added nothing, not to  [XMP-pdf] , not to [IFD0]

Why all this / Background

What is my use case for all this: As EXIF keywords are used as tags within Synology Photos Application, I wanted to be able to filter for Make and Model over their GUI. Although I have mainly JPGs I also have quite a view HEICs. I know I can convert them into JPG. But I wanted to avoid that.

So two thoughts remain for me

  • Is there a way to also add keywords to HEIC files with the "... -AddTagsFromFile @ "-Keywords+<Make" "-Keywords+<Model" ..." approach?
  • I wonder if Synology Photos might also read the [XMP-pdf] Keywords as tags





StarGeek

Quote from: timitalia on February 13, 2022, 03:34:24 PM
@StarGeek Many thanks for your answer! I liked your test setup and I have been able to learn from it: This test setup and your hint regarding the -overwrite_original option helped me figure out that it basically works, but it seems there is a problem with adding keywords to *.HEIC files.

See the Supported File Types table.  If you check there, you'll see that HEIC files cannot contain IPTC IIM/Legacy tags, of which includes IPTC:Keywords.  The only Keywords option for an HEIC file is the XMP-pdf:Keywords, which you discovered, which would be inappropriate for an image file.

QuoteWhat is my use case for all this: As EXIF keywords are used as tags within Synology Photos Application,

Minor correction, Keywords are not EXIF tags, except for XPKeywords which is a Microsoft specific tag of which very few programs beside Windows supports.

QuoteIs there a way to also add keywords to HEIC files with the "... -AddTagsFromFile @ "-Keywords+<Make" "-Keywords+<Model" ..." approach?
I wonder if Synology Photos might also read the [XMP-pdf] Keywords as tags

Hopefully, Synology will support it, but the tag you'll want to use is the XMP:Subject tag.  The modern IPTC Core/Ext tags are XMP tags and exiftool can write those in HEIC files. But there is the possibility that Synology won't read it directly and need to read it from an XMP sidecar file. See Metadata Sidecar Files.
* 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).