'-CreateDate<filename' doesn't appear to work via et.execute
Closed this issue · 8 comments
You can use exiftool '-CreateDate<filename'
to attempt to parse the file name as a date and set that to the CreateDate tag, on the command line. However, I am running into difficulties with doing this via pyexiftool.
with exiftool.ExifToolHelper(config_file="./exiftool.config", logger = logging.getLogger()) as et:
et.execute("-CreateDate<filename", f)
I'm seeing 1 image files updated
when I print the return state but after running exiftool -time:all
on that file, the date has not been updated. There are also no warnings/errors in the debug log.
INFO 2022-09-04 17:31:21,743 - Method 'run': Exiftool version '12.42' (pid 42558) launched with args '['/usr/local/bin/exiftool', '-config', './exiftool.config', '-stay_open', 'True', '-@', '-', '-common_args', '-G', '-n']'
INFO 2022-09-04 17:31:21,743 - Method 'execute': Command sent = [b'-CreateDate<filename', b'redacted/20090506121211.png', b'-echo4', b'=${status}=post694948']
DEBUG 2022-09-04 17:31:21,928 - ExifToolHelper.execute: IN params = ('-CreateDate<filename', 'redacted/20090506121211.png')
DEBUG 2022-09-04 17:31:21,928 - ExifToolHelper.execute: OUT stdout = "1 image files updated
Could you assist? Thanks
Hey, thanks for reopening it here. Do you have anything private in your config file? Can you post it?
I'm going to write a test with one of the png files in the test directory to see if I can reproduce
Were you able to reproduce this? Thanks for your help!
Is this one related?
https://stackoverflow.com/questions/74305074/renaming-image-files-with-pyexiftool-0-5-4-exiftool-in-python
That's not related. That's a problem with their call. I can reply to that directly. Their execute call is used improperly on stackoverflow
now that I've set up the whole environment, I see the behavior, though I am trying to break down why it's happening...
@djhanggi I've figured it out... it has to do with the common_args='-G', '-n'
I've done the following... got a PNG and renamed it to be 20090506121211.png
Setup
exiftool -time:all 20090506121211.png
File Modification Date/Time : 2022:05:23 21:30:08-07:00 File Access Date/Time : 2022:12:30 00:00:00-08:00 File Creation Date/Time : 2022:12:30 14:04:33-08:00
exiftool -G -time:all 20090506121211.png
[File] File Modification Date/Time : 2022:05:23 21:30:08-07:00 [File] File Access Date/Time : 2022:12:30 00:00:00-08:00 [File] File Creation Date/Time : 2022:12:30 14:04:33-08:00
The failing test case
with exiftool.ExifToolHelper() as et:
et.execute("-CreateDate<filename", "20090506121211.png")
exiftool -time:all 20090506121211.png
File Modification Date/Time : 2022:12:30 14:18:40-08:00 File Access Date/Time : 2022:12:30 00:00:00-08:00 File Creation Date/Time : 2022:12:30 14:04:33-08:00 Create Date : 20090506121211.png
exiftool -G -time:all 20090506121211.png
[File] File Modification Date/Time : 2022:12:30 14:18:40-08:00 [File] File Access Date/Time : 2022:12:30 00:00:00-08:00 [File] File Creation Date/Time : 2022:12:30 14:04:33-08:00 [EXIF] Create Date : 20090506121211.png
The intended success
with exiftool.ExifToolHelper() as et:
et.execute("-PNG:CreateDate<filename", "20090506121211.png")
For some reason, when -n
print conversion is disabled, exiftool tries to store an arbitrary string into EXIF group. When print conversion is enabled, it finds the PNG group properly. The below code also works, but the above code is probably the proper way to do this.
with exiftool.ExifToolHelper(common_args=['-G']) as et:
et.execute("-CreateDate<filename", "20090506121211.png")
Both are solutions, but it's probably preferred to use the first solution to properly specify which CreateDate you're writing to, as there are multiple named the same thing in other subgroups.
exiftool -time:all 20090506121211.png
File Modification Date/Time : 2022:12:30 14:20:22-08:00 File Access Date/Time : 2022:12:30 00:00:00-08:00 File Creation Date/Time : 2022:12:30 14:04:33-08:00 Create Date : 2009:05:06 12:12:11
exiftool -G -time:all 20090506121211.png
[File] File Modification Date/Time : 2022:12:30 14:20:22-08:00 [File] File Access Date/Time : 2022:12:30 00:00:00-08:00 [File] File Creation Date/Time : 2022:12:30 14:04:33-08:00 [PNG] Create Date : 2009:05:06 12:12:11