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.17k stars 100 forks source link

Exporting with edited=True not working properly #694

Closed KassiusKlay closed 2 years ago

KassiusKlay commented 2 years ago
photosdb = osxphotos.PhotosDB()
for photo in photosdb.photos():
     if photo.hasadjustments:
          saved_path = photo.export('./tmp', edited=True)
          print(saved_path) # OUTPUT: []
          saved_path = photo.export('./tmp')
          print(saved_path) # OUTPUT: ['tmp/IMG_213.HEIC'] -> ORIGINAL PICTURE NOT EDITED

Photo is not missing. I check in terminal and indeed, when I use the edited=True nothing is exported. How can I export the edited photo?

RhetTbull commented 2 years ago

Your code should work. I just tried it and it worked as expected for me. It is possible that the edited version is missing off disk and so even though the photo is reported as not missing, the edited version is absent. You can look at photo.path_edited and if it is None then the edited version of the photo is missing. Is this an iCloud-synched library? If so it's possible the edited version hasn't been downloaded from iCloud in which case you could try adding use_photos_export=True which uses AppleScript to interact with Photos and download the photo if needed instead of copying from the library. You could also use the more full-featured PhotoExporter interface.

import osxphotos

photosdb = osxphotos.PhotosDB("tests/Test-12.0.1.photoslibrary")
for photo in photosdb.photos():
    if photo.hasadjustments:
        saved_path = photo.export('/private/tmp', edited=True)
        print(f"path_edited: {photo.path_edited}")
        print(f"edited={saved_path}")
        saved_path = photo.export('/private/tmp')
        print(f"original={saved_path}")
path_edited: /osxphotos/tests/Test-12.0.1.photoslibrary/resources/renders/7/7783E8E6-9CAC-40F3-BE22-81FB7051C266_1_201_a.heic
edited=['/private/tmp/IMG_3092_edited (2).heic']
original=['/private/tmp/IMG_3092 (2).heic']
path_edited: /osxphotos/tests/Test-12.0.1.photoslibrary/resources/renders/6/6191423D-8DB8-4D4C-92BE-9BBBA308AAC4_1_201_a.jpeg
edited=['/private/tmp/Tulips_edited (2).jpeg']
original=['/private/tmp/Tulips (2).jpg']
path_edited: /osxphotos/tests/Test-12.0.1.photoslibrary/resources/renders/E/E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51_1_201_a.jpeg
edited=['/private/tmp/wedding_edited (2).jpeg']
original=['/private/tmp/wedding (2).jpg']
path_edited: /osxphotos/tests/Test-12.0.1.photoslibrary/resources/renders/D/DC99FBDD-7A52-4100-A5BB-344131646C30_1_201_a.jpeg
edited=['/private/tmp/St James Park_edited (2).jpeg']
original=['/private/tmp/St James Park (2).jpg']
RhetTbull commented 2 years ago

Hi @KassiusKlay Any luck getting this working?