-
-
Notifications
You must be signed in to change notification settings - Fork 28
feat: add support for libraries that are shared with the user #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ | |
| FindMyiPhoneServiceManager, | ||
| PhotosService, | ||
| RemindersService, | ||
| SharedPhotosService, | ||
| ) | ||
| from icloudpy.utils import get_password_from_keyring | ||
|
|
||
|
|
@@ -642,6 +643,14 @@ def photos(self): | |
| self._photos = PhotosService(service_root, self.session, self.params) | ||
| return self._photos | ||
|
|
||
| @property | ||
| def shared_photos(self): | ||
| """Gets the Shared 'Photo' service.""" | ||
| if not self._photos: | ||
| service_root = self._get_webservice_url("ckdatabasews") | ||
| self._shared_photos = SharedPhotosService(service_root, self.session, self.params) | ||
| return self._shared_photos | ||
|
Comment on lines
+646
to
+652
|
||
|
|
||
| @property | ||
| def calendar(self): | ||
| """Gets the 'Calendar' service.""" | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -274,6 +274,71 @@ def libraries(self): | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return self._libraries | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| class SharedPhotosService(PhotoLibrary): | ||||||||||||||||||||||||||||||||
| """The 'Photos' iCloud service. | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| This also acts as the shared library if I am not the owner of the library. | ||||||||||||||||||||||||||||||||
|
Comment on lines
+278
to
+280
|
||||||||||||||||||||||||||||||||
| """The 'Photos' iCloud service. | |
| This also acts as the shared library if I am not the owner of the library. | |
| """The 'Shared Photos' iCloud service. | |
| Provides access to shared photo libraries, such as shared albums or libraries | |
| that the user does not own. This is distinct from the regular PhotosService, | |
| which provides access to the user's primary photo library. |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._libraries is assigned None twice (lines 288 and 294). The duplicate assignment on line 294 should be removed.
| self._libraries = None |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented-out code should be removed. If the alternative URL is needed for reference, it should be documented in a comment explaining why the current URL is used instead.
| # url = f"{self._service_endpoint}/zones/list" |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable zones may not be defined if the exception occurs on line 308. This will cause a NameError when checking if not zones: on line 313. Initialize zones = [] before the try block to ensure the variable is always defined.
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The super().__init__() call only happens if zones is truthy (line 315). This means if there are no zones or an exception occurs, the SharedPhotosService instance will not be properly initialized as a PhotoLibrary, lacking essential attributes like self.zone_id and self._albums. This could cause AttributeError when accessing properties inherited from PhotoLibrary. Consider how to handle the no-zones case - either raise an exception or initialize with a default/empty zone_id.
| # The call to `/records/query` requires the `ownerRecordName` to be provided, which is known only after obtaining it from the API. | |
| if not zones: | |
| return | |
| raise ICloudPyServiceNotActivatedException( | |
| "Unable to fetch shared photo zones: " + str(e), None | |
| ) | |
| # The call to `/records/query` requires the `ownerRecordName` to be provided, which is known only after obtaining it from the API. | |
| if not zones: | |
| raise ICloudPyServiceNotActivatedException( | |
| "No shared photo zones found for this account.", None | |
| ) |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The libraries property has multiple issues:
- If an exception occurs on line 329,
zonesmay not be defined, causing aNameErrorwhen iterating withfor zone in zones:on line 333. Initializezones = []before the try block. - The method doesn't assign
self._libraries = librariesbefore returning (compare with PhotosService.libraries line 273), which means subsequent calls won't use the cached value. - Missing explicit return statement - should
return librariesat the end.
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new SharedPhotosService class lacks test coverage. Following the project's testing pattern (as seen in tests/test_photos.py for PhotosService), tests should be added to verify:
- Service initialization with correct params
- Zone ID handling for shared photos
- The
librariesproperty - Exception handling in
__init__when zones cannot be fetched - The service endpoint structure for shared photos
Add fixtures to tests/const_photos.py for shared photo zones/list responses and update tests/__init__.py::ICloudPySessionMock.request() to handle the shared photo URLs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition
if not self._photos:should checkif not self._shared_photos:instead. This bug causes the method to incorrectly check the wrong instance variable, which would prevent proper lazy initialization of the shared photos service and could cause the regular photos service to be incorrectly overwritten.