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
1.76k stars 93 forks source link

AAE export doesn't work with --update #1526

Closed odedia closed 1 month ago

odedia commented 1 month ago

It seems like exporting AAE files alongside the JPEGs send an error message on a second run with --update as if it wasn't supposed to be there. The sample error below happens for every edited file with an .AAE on the second run:

Error exporting photo (9DA859AF-063F-4307-B105-9439BA87BDD5: _DSC0353.NEF) as _DSC0353.NEF: Error copying file /Volumes/ExternalData/Users/odedia/Pictures/Photo Library.photoslibrary/resources/renders/9/9DA859AF-063F-4307-B105-9439BA87BDD5.plist to /Volumes/ExternalData/Users/odedia/Pictures/OSXPhotos/Originals/2019/2019-10-15/_DSC0353.AAE: Error Domain=NSCocoaErrorDomain Code=516 "“9DA859AF-063F-4307-B105-9439BA87BDD5.plist” couldn’t be copied to “2019-10-15” because an item with the same name already exists." UserInfo={NSSourceFilePathErrorKey=/Volumes/ExternalData/Users/odedia/Pictures/Photo Library.photoslibrary/resources/renders/9/9DA859AF-063F-4307-B105-9439BA87BDD5.plist, NSUserStringVariant=(
    Copy
), NSDestinationFilePath=/Volumes/ExternalData/Users/odedia/Pictures/OSXPhotos/Originals/2019/2019-10-15/_DSC0353.AAE, NSFilePath=/Volumes/ExternalData/Users/odedia/Pictures/Photo Library.photoslibrary/resources/renders/9/9DA859AF-063F-4307-B105-9439BA87BDD5.plist, NSUnderlyingError=0x600003ee0270 {Error Domain=NSPOSIXErrorDomain Code=17 "File exists"}} (photoexporter.pyc: 1227)

It's possible osxphotos cannot identify that it's updating the existing AAE. The errors go away when you disable export_aae in the toml file.

RhetTbull commented 1 month ago

I've replicated this. The export_aae part of the code just copies the AAE file but doesn't check if it exists first. There's not a way for OSXPhotos to know if the AAE changed or not currently. It could theoretically look at last modification date or store a signature of the AAE but this isn't currently stored. I think the best option is the following:

  1. If photo is up to date and there is an AAE, skip updating the AAE
  2. If photo is up to date and there is no AAE, export the AAE
  3. If photo is being exported/updated, delete the AAE if it exists, and export a new copy
RhetTbull commented 1 month ago

@all-contributors please add @odedia for bug

allcontributors[bot] commented 1 month ago

@RhetTbull

I've put up a pull request to add @odedia! :tada:

RhetTbull commented 1 month ago

Actually, I can make this work with the normal --update logic as the export database stores a record associated with each exported file, thus I can store the signature of the AAE and update status in database without any modification to the database schema.

RhetTbull commented 1 month ago

I have this partially implemented:

osxphotos export ~/Desktop/export --verbose --export-aae --update --selected
Exporting 1 photo to /Users/rhet/Desktop/export...
Exporting wedding.jpg (E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51.jpeg) (1/1)
Skipping up to date AAE file /Users/rhet/Desktop/export/wedding.AAE
Skipped up to date file /Users/rhet/Desktop/export/wedding.jpg
Exporting edited version of wedding.jpg (E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51.jpeg)
Skipped up to date file /Users/rhet/Desktop/export/wedding_edited.jpeg
Exporting 1 photos ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
Processed: 1 photo, exported: 0, updated: 0, skipped: 2, updated EXIF data: 0, missing: 0, error: 0
Elapsed time: 0:00:00
Cleaning up lock files
RhetTbull commented 1 month ago

Fix in main and will be included in next release

odedia commented 1 month ago

Thank you!

RhetTbull commented 1 month ago

By the way, this change also adds new aae_written and aae_skipped fields to the export report.

finestream commented 1 week ago

How funny, I just spotted the same bug and when checking the sourcecode on GitHub I saw that it was already fixed! Cool & looking forward to the next release with the fix!

RhetTbull commented 1 week ago

@finestream I'm close to a new release -- have been focused on a complete rewrite of the osxphotos import code that allows the import command to recreate a library from an export. This should be very useful in many use cases but it has required extensive work and testing. I think I'm close!