Add Make and four-digit year from DateTimeOriginal to keywords

Started by timitalia, January 19, 2023, 04:53:56 AM

Previous topic - Next topic

timitalia

Hi all

In addition to the Make tag, I would like to add the four-digit year from DateTimeOriginal to the keywords recursively for all images underneath a path.

My assumption is that is best to choose DateTimeOriginal, as every image file should have it?

exiftool -P -overwrite_original -AddTagsFromFile @  "-Keywords+<Make" "-Keywords+<${DateTimeOriginal#;DateFmt('%Y')}" ~/path/to/folder

My approach with the DateFmt does not work => "0 image files updated"

An example of how my use case would work in one command, adding the Make Tag and the four-digit year as keywords to all images underneath a path would be much appreciated

Thank you in advance,
Tim

Phil Harvey

Hi Tim,

Your command looks good.  (Except that you should use single quotes if you are on Mac or Linux.)

What do you get for this command?:

exiftool -make -datetimeoriginal ~/path/to/folder

Are the image files in this folder?  Or in folders in this folder?  If the latter, you need to add -r to your command.

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

timitalia

Hi Phil,

for my PoC the images are directly in this folder ~/path/to/folder. Once the command works I want to use it with -r, thanks for the hint.

gives me:
Make                            : Apple
Date/Time Original              : 2022:01:03 21:33:50
======== /Users/me/path/to/folder/IMG_9694.JPG
Make                            : Snowcorp
Date/Time Original              : 2019:09:07 12:09:50
======== /Users/me/path/to/folder/DSCF3831.JPG
Make                            : FUJIFILM
Date/Time Original              : 2016:08:07 10:58:50
======== /Users/me/path/to/folder/IMG_6952.JPG
Make                            : NIKON CORPORATION
Date/Time Original              : 2015:02:08 18:05:49
======== /Users/me/path/to/folder/IMG_2334.JPG
Make                            : Apple
Date/Time Original              : 2018:03:02 20:09:13
======== /Users/me/path/to/folder/D5H_1039.JPG
Make                            : NIKON CORPORATION
Date/Time Original              : 2017:04:11 01:12:44
======== /Users/me/path/to/folder/DSC_0038-2.JPG
Make                            : NIKON CORPORATION
Date/Time Original              : 2012:05:12 14:17:07

timitalia

Hi Phil, I've got it!

Indeed I see now that my command indeed works and that was all I wanted.
Sorry for the confusion, I was inaccurate in reporting this issue.

Originally I came from this command, to check how it generally works to add multiple tags to keywords:

exiftool -P -overwrite_original -AddTagsFromFile @ "-Keywords+<Make" "-Keywords+<DateTimeOriginal" ~/path/to/folder

Then I tried out to extract the year of DateTimeOriginal, isolated, without adding the Make tag to the keywords, just for testing:

exiftool -P -overwrite_original -AddTagsFromFile @  "-Keywords+<{$DateTimeOriginal#;DateFmt('%Y')}" ~/path/to/folder

And this line above resulted in the behavior => 0 image files updated

Strangely the "-Keywords+<Make" alone works (all files get updated):

exiftool -P -overwrite_original -AddTagsFromFile @  "-Keywords+<Make" ~/path/to/folder

Although my use case is satisfied, I would be interested why "-Keywords+<{$DateTimeOriginal#;DateFmt('%Y')}" alone does not work.

Cheers, Tim

StarGeek

You have the braces set wrong.
${DateTimeOriginal#;DateFmt('%Y')}
not
{$DateTimeOriginal#;DateFmt('%Y')}
* 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

Thank you StarGeek!

but still with braces set right:

exiftool -P -overwrite_original -AddTagsFromFile @  "-Keywords+<${DateTimeOriginal#;DateFmt('%Y')}" ~/path/to/folder
I get => 0 image files updated ( whereas together with "-Keywords+<Make" it updates correctly)

But "-Keywords+<Make" alone:

exiftool -P -overwrite_original -AddTagsFromFile @  "-Keywords+<Make" ~/path/to/folder

works / updates files.

timitalia

And a small additional question:

How do I combine deleting (or adding) a normal string keyword (i.e. not Make, Model, or other Exif Tag) in the same command?

What I mean is combining

exiftool -r -keywords-=someCustomKeyword ~/path/to/folder

with
exiftool -r -P -overwrite_original -AddTagsFromFile @  "-Keywords+<Make" "-Keywords+<${DateTimeOriginal#;DateFmt('%Y')}" ~/path/to/folder

Is that possible?


StarGeek

C:\>exiftool -P -overwrite_original -AddTagsFromFile @  "-Keywords+<${DateTimeOriginal#;DateFmt('%Y')}" y:\!temp\Test4.jpg
    1 image files updated


C:\>exiftool -G1 -a -s -keywords -DateTimeOriginal y:\!temp\Test4.jpg
[IPTC]          Keywords                        : 2023
[ExifIFD]      DateTimeOriginal                : 2023:01:19 08:13:54

I suspect the problem is

Quote from: Phil Harvey on January 19, 2023, 08:51:20 AMHi Tim,

Your command looks good.  (Except that you should use single quotes if you are on Mac or Linux.)
* 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).

StarGeek

Quote from: timitalia on January 19, 2023, 10:57:08 AMHow do I combine deleting (or adding) a normal string keyword (i.e. not Make, Model, or other Exif Tag) in the same command?

Just add it in, though I think you want += to add a keyword.  -= removes a keyword.  It can go anywhere except between a two part option, i.e. not between -AddTagsFromFile and @
C:\>exiftool -P -overwrite_original -keywords+=someCustomKeyword -AddTagsFromFile @  "-Keywords+<Make" "-Keywords+<${DateTimeOriginal#;DateFmt('%Y')}" y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -G1 -a -s -keywords y:\!temp\Test4.jpg
[IPTC]          Keywords                        : someCustomKeyword, My Camera, 2023

FAQ #17 deals with list type tags such as Keywords.
* 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

Thank you Phil and StarGeek, all is sorted out now.

I realized it was indeed the single/double quote issue and had nothing to do with whether it is run with or without "-Keywords+<Make"

So this works now as expected:

exiftool -P -overwrite_original -AddTagsFromFile @ '-Keywords+<${DateTimeOriginal#;DateFmt("%Y")}' ~/path/to/folder
 

Learned a lot, thank you!
As always: what a great tool!