Writing non-standard date tags to FileModifyDate

Started by Mizkreant, August 12, 2021, 08:13:03 AM

Previous topic - Next topic

Mizkreant

I'm hoping someone can help me. I use a program called Thumbsplus to manage my images. I've marked thousands of files with Thumbplus' own internal keywords. I want to write these to each file's metadata. I also want to preserve the file's Windows Date Modified. Thumbsplus offers a batch metadata tool to write the keywords to the metadata, unfortunately, it does not have an option to preserve the modification date. As a workaround, I wrote the Windows Date Modified to the tag XMP:ModifyDate for each file, then wrote the internal keywords to the metadata. I want to use Exiftool to write the ModifyDate tag back to the Windows Date Modified field. Here's where the big problem lies. Thumbsplus does not write dates in ISO format. It insists on using American mm/dd/YYYY format even if you change Windows' region settings. Here's an example file:

C:\Users\retrobox\Pictures>exiftool -s -G -*date 1skw3pp9bcv21.jpg_original
[File]          FileModifyDate                  : 2021:08:10 18:29:03-05:00
[File]          FileAccessDate                  : 2021:08:11 07:01:35-05:00
[File]          FileCreateDate                  : 2021:08:03 06:26:01-05:00
[XMP]           MetadataDate                    : 2021:08:10 18:29:03-05:00
[XMP]           ModifyDate                      : 8/10/2021 T6:27:20.507 PM


In this particular case, this is what happens if I try to write ModifyDate to FileModifyDate:

C:\Users\retrobox\Pictures>exiftool "-FileModifyDate<XMP:ModifyDate" 1skw3pp9bcv21.jpg_original
    1 image files updated

C:\Users\retrobox\Pictures>exiftool -s -G -*date 1skw3pp9bcv21.jpg_original
[File]          FileModifyDate                  : 2021:06:27 20:50:07-05:00
[File]          FileAccessDate                  : 2021:06:27 20:50:07-05:00
[File]          FileCreateDate                  : 2021:08:03 06:26:01-05:00
[XMP]           MetadataDate                    : 2021:08:10 18:29:03-05:00
[XMP]           ModifyDate                      : 8/10/2021 T6:27:20.507 PM


In this file's case, it "works," but only because of the hour/minute being a valid date (which is expected behavior given exiftool's default parsing of non-standard dates). Of couse if a file's hour or minute exceed expected ranges, I get this:

C:\Users\retrobox\Pictures>exiftool -s -G -*date* 782955.jpg
[File]          FileModifyDate                  : 2021:08:12 05:59:14-05:00
[File]          FileAccessDate                  : 2021:08:12 06:52:21-05:00
[File]          FileCreateDate                  : 2021:08:07 10:44:21-05:00
[EXIF]          DateTimeOriginal                : 2021:08:07 10:44:21
[XMP]           MetadataDate                    : 2021:08:12 05:40:47-05:00
[XMP]           ModifyDate                      : 8/7/2021 10:44:21 AM

C:\Users\retrobox\Pictures>exiftool "-FileModifyDate<ModifyDate" 782955.jpg
Warning: Day '44' out of range 1..31 in File:FileModifyDate (PrintConvInv) - 782955.jpg
Warning: No writable tags set from 782955.jpg
    0 image files updated
    1 image files unchanged

   
After searching and finding this thread (https://exiftool.org/forum/index.php?PHPSESSID=964310af8bc7a01e27e5a287a24cdda4&topic=5007.0) I tried this:

C:\Users\retrobox\Pictures>exiftool "-FileModifyDate<${XMP:ModifyDate;s/(\d{2})\/(\d{2})\/(\d{4}) (.*)/$3:$1:$2 $4/}" 782955.jpg
Warning: No writable tags set from 782955.jpg
    0 image files updated
    1 image files unchanged

   
There must be an error in my syntax somewhere, but I can't figure it out. I also don't know if the -d option could help with what I'm trying to do.

Phil Harvey

Try this:

exiftool "-filemodifydate<xmp:modifydate#" -d "%d/%m/%Y %H:%M:%S %p" -api strictdate=0 FILE

The trick here is to set the API StrictDate option to 0, otherwise ExifTool won't try to copy the invalid date/time value.  (Although it probably should because I have specified copying from the unformatted date/time value by adding "#" to the tag name.)

- 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 ($).

Mizkreant


StarGeek

Moral of the story?  Use exiftool in the first place to save the time stamp  ;)
exiftool "-xmp:ModifyDate<FileModifyDate" /path/to/files/

But I noticed one thing from one of your command outputs and that is the DateTimeOriginal tag seems to hold the correct time in the first place.  Which is quite likely if these images came from a camera.  So in those cases you could have used
exiftool "-FileModifyDate<DateTimeOriginal" /path/to/files/

You can see all the time related tags with
exiftool -time:all -g1 -a -s /path/to/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).

Mizkreant

#4
Quote from: StarGeek on August 12, 2021, 10:34:11 AM
Moral of the story?  Use exiftool in the first place to save the time stamp  ;)

Yeah, I won't use Thumbsplus for anything metadata or keyword related anymore. I would switch to DigiKam, but scanning takes forever.

QuoteBut I noticed one thing from one of your command outputs and that is the DateTimeOriginal tag seems to hold the correct time in the first place.  Which is quite likely if these images came from a camera.  So in those cases you could have used
exiftool "-FileModifyDate<DateTimeOriginal" /path/to/files/

They just happened to match in that case. It's really a mess. Some files have a malformed XMP:ModifyDate tag. Some inexplicably have the correct ISO date format. Some don't have an XMP:ModifyDate tag, but they do have an EXIF:ModifyDate tag with the correct date format. I don't know which was written by Thumbsplus anymore. I'll check again.

EDIT: Thumbsplus writes the XMP:Modify tag.

Mizkreant

Quote from: Phil Harvey on August 12, 2021, 08:37:18 AM
Try this:

exiftool "-filemodifydate<xmp:modifydate#" -d "%d/%m/%Y %H:%M:%S %p" -api strictdate=0 FILE

The trick here is to set the API StrictDate option to 0, otherwise ExifTool won't try to copy the invalid date/time value.  (Although it probably should because I have specified copying from the unformatted date/time value by adding "#" to the tag name.)

- Phil

Thumbsplus is very inconsistent in how it writes dates. This works if the date is like this:

======== ./1skw3pp9bcv21.jpg
[File]          FileModifyDate                  : 2021:08:03 06:26:01-05:00
[File]          FileAccessDate                  : 2021:08:12 11:09:12-05:00
[File]          FileCreateDate                  : 2021:08:03 06:26:01-05:00
[EXIF]          ModifyDate                      : 2021:08:03 06:26:01
[EXIF]          DateTimeOriginal                : 2021:08:03 06:26:01
[XMP]           CreateDate                      : 8/3/2021  6:26:01 AM
[XMP]           MetadataDate                    : 2021:08:12 05:19:09-05:00
[XMP]           ModifyDate                      : 2021:08:03 06:26:01-05:00


In this case the CreateDate tag was written by Thumbsplus. The ModifyDate has the correct format, which was not written by Thumbsplus. I was experiementing with XnviewMP, which might have written this, I can't remember. I already used Phil's solution to write CreateDate to ModifyDate on this file, that's why it worked and the dates match.

======== ./1skw3pp9bcv212.jpg
[File]          FileModifyDate                  : 2021:06:27 20:50:07-05:00
[File]          FileAccessDate                  : 2021:08:12 11:09:12-05:00
[File]          FileCreateDate                  : 2021:08:03 06:26:01-05:00
[XMP]           MetadataDate                    : 2021:08:10 18:29:03-05:00
[XMP]           ModifyDate                      : 8/10/2021 T6:27:20.507 PM


Thumbsplus put a "T" in the ModifyDate above. In this case it doesn't work and exiftool uses the default behavior and writes the hour and minute as month/day.

======== ./782969.jpg
[File]          FileModifyDate                  : 2021:08:12 10:55:58-05:00
[File]          FileAccessDate                  : 2021:08:12 11:09:12-05:00
[File]          FileCreateDate                  : 2021:08:07 10:45:04-05:00
[XMP]           ModifyDate                      : 8/7/2021 10:45:07.619 AM
[XMP]           MetadataDate                    : 2021:08:12 10:55:58-05:00
[XMP]           CreateDate                      : 8/12/2021 10:53:32.028 AM


This time ModifyDate and CreateDate have milliseconds added.

C:\Users\retrobox\Pictures>exiftool "-filemodifydate<xmp:modifydate#" -d "%m/%d/%Y %H:%M:%S %p" -api strictdate=0 782969.jpg
Warning: Day '45' out of range 1..31 in File:FileModifyDate (PrintConvInv) - 782969.jpg
Warning: No writable tags set from 782969.jpg
    0 image files updated
    1 image files unchanged


This also causes exiftool to use the default behavior and interpret the minute as day.

Phil Harvey

...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 ($).

Mizkreant

For anyone reading this in the future who uses Thumbsplus, I managed to solve the problem. My initial regex substitution command didn't work because it copied the time verbatim instead of accounting for all the ways Thumbsplus could screw up the time. The following command covers all possible scenarios:

exiftool "-FileModifyDate<${XMP:ModifyDate;s/(\d{1,2})\/(\d{1,2})\/(\d{4})\s+T?(\d{1,2}):(\d{2}):(\d{2})/$3:$1:$2 $4:$5:$6/}" FILE

This works regardless if there's a T or milliseconds added. If the tag is in correct format, it doesn't match the regex and works normally. If the file doesn't have an XMP:ModifyDate tag, then it won't write anything. I was initially worried that it wouldn't work because Thumbsplus doesn't write some of the preceeding 0s. Thankfully exiftool is smart enough to read the delimiting characters and interpret everything correctly.