RhetTbull / PhotoScript

Automate Apple / MacOS Photos app with python. Wraps applescript calls in python to allow automation of Photos from python code.
MIT License
45 stars 5 forks source link

Accessing "shared with you" photos on macOS 14.2.1 by uuid raises invalid uuid exception #46

Open disaac opened 6 months ago

disaac commented 6 months ago

Describe the bug Currently when processing photos in my Photos Library via the API an exception is raised on a small subset of photos that I attempt to fetch by the uuid. I experienced an exception in the following methods when attempting to access the photo by its uuid.

photoscript Photo

from photoscript import Photo, PhotosLibrary
photos = PhotosDB().photos(movies=False)
for photo in photos:
    photo_ = Photo(photo.uuid)
...

photoscript PhotosLibrary

from photoscript import Photo, PhotosLibrary
selection = PhotosLibrary().selection if selected else []

There are only 3 out of my entire library that have this issue and all three are "Shared with You" photos in my library.

To Reproduce Steps to reproduce the behavior:

  1. With shared with you photos in your photo library execute the following code once you have a uuid for one of those photos.
    from photoscript import Photo
    photo_ = Photo('A6D366D2-5889-431F-A09C-82A17254FA10')
  2. Observe the following exception will be raised
    │                                                                                                  │
    │    993 │   │   │   self.id = id_                                                                 │
    │    994 │   │   │   self._uuid = uuid                                                             │
    │    995 │   │   else:                                                                             │
    │ ❱  996 │   │   │   raise ValueError(f"Invalid photo id: {uuid}")          
    Invalid photo id: A6D366D2-5889-431F-A09C-82A17254FA10

    Expected behavior When referencing a photo that osxphotos cli can query and return information on using the Photo or photolibrary should not return an exception attempting to access the photo by the same uuid.

successfully returns photo information

osxphotos query --uuid A6D366D2-5889-431F-A09C-82A17254FA10 --json

Desktop (please complete the following information):

Additional context

RhetTbull commented 6 months ago

Thanks for the detailed report. This should really go on the photoscript repo so I'll cross-post there.

Unfortunately, there's nothing osxphotos or photoscript can do about this as it's how the Photos AppleScript interface behaves. Photos in shared albums and in "Shared for You" show up in the library but they are note really in the library (e.g. assets under management of Photos and iCloud) until they are imported to the main library. The Photos AppleScript interface, which is used by photoscript to interact with Photos, cannot access photos in the "Shared with you" or shared albums. That's an Apple issue and not one that osxphotos or photoscript can work around.

You can access these photos via osxphotos and export them, get the path, etc. but you cannot access them via AppleScript or photoscript. If a Shared with you photo has been imported to the library then you can access it as you've demonstrated.