icloud-photos-downloader / icloud_photos_downloader

A command-line tool to download photos from iCloud
MIT License
7.02k stars 563 forks source link

Add Export of metadata via XMP Sidecar #984

Closed chkuendig closed 1 hour ago

chkuendig commented 3 weeks ago

There have been multiple requests over time ( #448, #102, #789, probably more) to export some of the metadata that can be changed in Photos. This PR tries to address as many of these as possible but focused on the most common ones:

I tested this on my 50'000+ images library and it processed all of them. If the Exif Tags are supported by Immich they also match. (this helped a ton to sort the images in the correct order and add missing location tags to pictures taken without embedded location info - e.g. from DSLR etc)

PS: This also would replace/close #915 I guess.

AndreyNikiforov commented 3 weeks ago

Thanks for taking initiative. Appreciate writing tests for new features.

Can you implement all these features without external dependency on exiftool, pls? icloudpd is distributed as standalone binary without any dependencies on all platforms and there is value in keeping it that way.

chkuendig commented 3 weeks ago

I understand the preference to keep this working without any external dependencies. Unfortunately for XMP handling I couldn't find a single library that wouldn't need external dependencies. I specifically looked at:

I couldn't find a single pure python library and I don't really have the bandwith to implement a fairly complex standard from scratch just for this. If any of the other 2 libraries are okay, I'm happy to re-implement the PR. Or maybe there's a better way I'm not aware of? Like many I use docker so external depencendies aren't really an issue for me.

AndreyNikiforov commented 3 weeks ago

is it reasonable too generated xmp file just from metadata received from Apple (without exif at all)? xmp will have to bed generated with the code i assume

chkuendig commented 3 weeks ago

Thats what I'm doing, I use exiftool just to write the sidecar file.

I'll check if its feasible to just write the XML by hand. As long as we stick to the +/- 10 fields, its cumbersome but probably doable by just generating the xml once with exiftool and then write code to replicate it in pure python.

AndreyNikiforov commented 3 weeks ago

what happens when metadata is updated in icloud? should local xmp be synchronized? what if local changed as well?

chkuendig commented 3 weeks ago

I currently assumed this to be mostly an archival function, so the iCloud data would overwrite local data.

Thinking more about this, I'd suggest we check the XMLToolkit tag to make sure the last edit was by icloudpd. It seems to be a tag thats changed if edited by another software.

I'll add this with the update to remove external dependencies.

chkuendig commented 4 days ago

I pushed an update that removes the dependency on exitfool and also checks if an xmp file exists before overwriting it (it only overwrites if the file is empty or was generated by icloudpd in the first place)

note: I updated the lint python version to 3.9 so I can use ElementTree.indent

AndreyNikiforov commented 2 days ago

note: I updated the lint python version to 3.9 so I can use ElementTree.indent

Does that mean we have to drop support for 3.8?

chkuendig commented 2 days ago

Yes. If thats an issue i'd suggest to remove that call and output unformatted xml instead.

AndreyNikiforov commented 2 days ago

Yes. If thats an issue i'd suggest to remove that call and output unformatted xml instead.

Thanks! I think maintaining 3.8 compatibility is higher value than pretty printed small xml file (which is not supposed to be viewed by humans)

chkuendig commented 1 day ago

Done.

PS: I also found a bug in the orientation field (it did not reflect possible adjustments). This should be corrected now.