RhetTbull / osxphotos

Python app to work with pictures and associated metadata from Apple Photos on macOS. Also includes a package to provide programmatic access to the Photos library, pictures, and metadata.
MIT License
2.04k stars 95 forks source link

`osxphotos export --exiftool` does not always overwrite the creation date of the photo #1377

Open maximzasorin opened 8 months ago

maximzasorin commented 8 months ago

First of all, thanks for a great tool!

Describe the bug The osxphotos export command with the --exiftool option does not always write the adjusted creation date of photo to meta tags. The adjusted creation date is not written if the photo was edited in the built-in Photos editor. However, the original file is exported correctly.

How to reproduce

  1. Import a photo into Photos in the normal way (photo has creation date of 2024-01-01).
  2. Change the creation date via the "Adjust date and time" (set creation date to 2024-01-05).
  3. Edit it in the editor, e.g. crop it.
  4. Export the photo with osxphotos export --exiftool.
  5. Import the edited photo with the _edited suffix into Photos in the normal way.
  6. See that Photos recognizes the original creation date of the photo (2024-01-01), not the adjusted one (2024-01-05).
I did a little research to give you more information. I have a photo IMG_1244.JPG with a creation date of 2024-01-01, I import it into the Photos app in the normal way. Next, I change the creation date of the photo from 2024-01-01 to 2024-01-05 through the "Adjust date and time" in the Photos app and export the photo: ``` % osxphotos export --exiftool --uuid XXX ./exported ``` I expect that with `--exiftool` option it will write the adjusted creation date into the meta tags of the photo, and I can check the result with `exiftool`. Everything works as I expected, the date I adjust is written to the meta tags. Original file: ``` % exiftool -G -a ./IMG_1244.JPG | grep Date [File] File Modification Date/Time : 2024:01:09 20:29:39+03:00 [File] File Access Date/Time : 2024:01:09 21:07:10+03:00 [File] File Inode Change Date/Time : 2024:01:09 20:29:39+03:00 [EXIF] Modify Date : 2024:01:01 12:34:56 [EXIF] Date/Time Original : 2024:01:01 12:34:56 [EXIF] Create Date : 2024:01:01 12:34:56 [MakerNotes] Date Stamp Mode : Off ``` Exported file: ``` % exiftool -G -a ./exported/IMG_1244.JPG | grep Date [File] File Modification Date/Time : 2024:01:09 20:29:39+03:00 [File] File Access Date/Time : 2024:01:09 21:08:31+03:00 [File] File Inode Change Date/Time : 2024:01:09 21:08:30+03:00 [EXIF] Modify Date : 2024:01:05 12:34:56 [EXIF] Date/Time Original : 2024:01:05 12:34:56 [EXIF] Create Date : 2024:01:05 12:34:56 [MakerNotes] Date Stamp Mode : Off [IPTC] Date Created : 2024:01:05 [Composite] Date/Time Original : 2024:01:05 12:34:56+03:00 [Composite] Date/Time Created : 2024:01:05 12:34:56+03:00 ``` But it work differently with an edited photo. Next, I edit the same photo in the built-in Photos editor, for example, I crop the photo to the aspect ratio I want, and then export the same photo but to a new directory: ``` % osxphotos export --exiftool --uuid XXX ./exported2 ``` In the exported2 directory I get two files IMG_1244.JPG and IMG_1244_edited.jpeg, the results of running `exiftool` is as follows: ``` % exiftool -G -a ./exported2/IMG_1244.JPG | grep Date [File] File Modification Date/Time : 2024:01:09 20:29:39+03:00 [File] File Access Date/Time : 2024:01:09 21:12:48+03:00 [File] File Inode Change Date/Time : 2024:01:09 21:12:46+03:00 [EXIF] Modify Date : 2024:01:09 21:12:27 [EXIF] Date/Time Original : 2024:01:05 12:34:56 [EXIF] Create Date : 2024:01:05 12:34:56 [MakerNotes] Date Stamp Mode : Off [IPTC] Date Created : 2024:01:05 [Composite] Date/Time Original : 2024:01:05 12:34:56+03:00 [Composite] Date/Time Created : 2024:01:05 12:34:56+03:00 ``` ``` % exiftool -G -a ./exported2/IMG_1244_edited.jpeg | grep Date [File] File Modification Date/Time : 2024:01:09 21:12:28+03:00 [File] File Access Date/Time : 2024:01:09 21:12:47+03:00 [File] File Inode Change Date/Time : 2024:01:09 21:12:46+03:00 [EXIF] Modify Date : 2024:01:09 21:12:27 [EXIF] Date/Time Original : 2024:01:05 12:34:56 [EXIF] Create Date : 2024:01:05 12:34:56 [IPTC] Date Created : 2024:01:05 [XMP] Date Created : 2024:01:01 12:34:56 [XMP] Create Date : 2024:01:01 12:34:56 [XMP] Modify Date : 2024:01:01 12:34:56 [ICC_Profile] Profile Date Time : 2022:01:01 00:00:00 [Composite] Date/Time Original : 2024:01:05 12:34:56+03:00 [Composite] Date/Time Created : 2024:01:05 12:34:56+03:00 ``` The edited file (the one with the _edited suffix) has XMP meta tags that contain the original creation date of the photo, even though I used the `--exiftool` option when exporting. The "[XMP] Date Created" meta tag contains the date 2024-01-01 (original), and the "[IPTC] Date Created" contains the date 2024-01-05 (adjusted by me in Photos).

Expected behavior I expect that the date I set via Photos will go into the edited photo during export with osxphotos export --exiftool, and if it is re-imported, the adjusted date will be used.

I don't sure if this is the correct behavior or not, but XMP meta tags are added to the edited photo, which osxphotos export does not overwrite when exporting with the --exiftool option. If I then import the file with the _edited suffix into Photos, the app identifies creation date of the photo from the XMP meta tag as 2024-01-01 and not as 2024-01-05.

Desktop (please complete the following information):

% osxphotos --version
osxphotos, version 0.67.2
Python 3.12.1 (main, Dec  8 2023, 19:21:52) [Clang 14.0.3 (clang-1403.0.22.14.1)]
macOS 13.6.3, x86_64
RhetTbull commented 8 months ago

Thanks for detailed bug report. I see the issue in the code. osxphotos sets IPTC:DateCreated and EXIF:DateTimeOriginal when using --exiftool but it does not set XMP:DateCreated or XMP:DateTimeOriginal and apparently Photos is prioritizing these. I'll fix this as soon as I get a chance.

RhetTbull commented 8 months ago

This will need to be fixed in the sidecar generation as well.

RhetTbull commented 8 months ago

The problem appeared only in the edited file because Photos wrote the XMP tags when editing the file and osxphotos/exiftool did not overwrite these. The XMP tags were not present in the original so Photos defaulted to the EXIF or IPTC date.

RhetTbull commented 8 months ago

I've not been able to reproduce this behavior. I've tested on macOS 13.6.1 and 14.0 and Photos does not appear to write the XMP fields that are shown in your example and thus the import works as expected -- the date is read from the EXIF data and is adjusted correctly in Photos.

Did you edit the photos in an external editor? Did you do any processing on the photos after the export?

Before I blindly fix something I cannot reproduce I want to ensure the correct date/time fields are being set by osxphotos and that I understand the behavior.

RhetTbull commented 8 months ago

The mystery deepens. I tried manually setting each of the 3 XMP tags in your example but when I import into Photos, Photos uses the "correct" date that's in the EXIF data. Photos (at least on Ventura) does not appear to be reading the XMP dates. If you're able to share a sample image that is doing this, both original and exported, that would be helpful: osxphotos.py@gmail.com

maximzasorin commented 8 months ago

Did you edit the photos in an external editor? Did you do any processing on the photos after the export?

No, I didn't edit the photo in an external editor, only through the built-in Photos editor. And no, I didn't process the photo after export.

If you're able to share a sample image that is doing this, both original and exported, that would be helpful

I've sent the files to the email.

***

Before I blindly fix something I cannot reproduce I want to ensure the correct date/time fields are being set by osxphotos and that I understand the behavior.

Yes, the issue is strange. I tried another random photo from the internet, and the issue did not repeat. Maybe this is some rare situation, I don't know, or maybe I miss something.

RhetTbull commented 8 months ago

I received the sample files, thanks. I am able to replicate this behavior. Interestingly, I cannot get Photos to write the XMP:DateCreated field but if this field is removed from your edited image, then Photos uses the correct date/time on import. If I set the XMP:DateCreated to a new value and import the photo, Photos uses this new date/time.

Thus, I guess osxphotos should write XMP:DateCreated, XMP:CreateDate, and XMP:ModifyDate to be consistent with what you're seeing from Photos. I do not have the most current version of Sonoma (only a VM running the beta) so I cannot test to see exactly what Photos is doing but it appears from the screencast you sent that Photos, sometime after 14.0.0 beta, is writing these XMP fields which it did not previously do.

RhetTbull commented 8 months ago

Something weird is happening. If I change the XMP:DateCreated on the photo you sent and import it, Photos uses the new date. If I add XMP:DateCreated and/or XMP:CreateDate to a photo from my library and import it, Photos uses the date in the EXIF field. There's more going on that just XMP data.

RhetTbull commented 8 months ago

More testing and I am able to replicate that adding XMP:DateCreated to a photo causes Photos to use this date on import. Not sure what happened before but I may have mistyped the exiftool command. So XMP:DateCreated takes precedence over any other dates in the files. Photos appears to add XMP:CreateDate and XMP:ModifyDate but does not appear to read these.

osxphotos should probably write all 3 XMP date fields.

Note: unlike other exiftool date/time fields, these should be formatted as ISO 8601

ingmferrer commented 8 months ago

I’m experiencing the same issue. Everything works perfectly, except for the ‘adjusted’ creation date, which is set to the exported date.