Skip to content
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

Support shared libraries #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pneff
Copy link

@pneff pneff commented Nov 2, 2022

This supports the new iCloud shared libraries.

Example usage:

for library_name, library in api.photos.libraries.items():
    print(f'Library: {library_name}')
    for photo in library.all:
        print(f'{photo.asset_date} {photo} {photo.filename}')

This currently returns a photo album for each shared library. This can then be
used to iterate over all the photos in that library. For example:

    for library_name, album in api.photos.libraries.items():
        print(f'Library: {library_name}')
        for photo in album:
            print(f'{photo.asset_date} {photo} {photo.filename}')
The libraries are now returned as a new object type (PhotoLibrary). That
provides access to albums. This way the icloud-photos-downloader can also use
the Recently Deleted special album to sync deletions.

The list of non-special albums is currently returned empty for the
shared libraries. This also tracks with the fact that the iCloud web app
currently doesn't provide access to albums in shared libraries.
@AndreyNikiforov
Copy link

@pneff How do the proposed changes align with original pyicloud lib? There is a desire to remove the fork and go with upstream pyicloud (icloud-photos-downloader/icloud_photos_downloader#179) and I am wondering if this change may further diverge the fork if it does not match with similar changes in upstream. WDYT?

@mikeknoop
Copy link

@pneff a chance something changed in the last month or so as Apple rolled out their new icloud website? Consistently now getting errors with your patch eg. --list-libraries

# /usr/bin/icloudpd --list-libraries
2023-03-02 23:00:21 DEBUGAuthenticating...
iCloud Password:
2023-03-02 23:00:26 INFO Two-step/two-factor authentication is required!
0: SMS to ********XX
1: Enter two-factor authentication code 
Please choose an option: [0]: 1 
Please enter two-factor authentication code: XXXXXX 
2023-03-02 23:00:39 INFO Great, you're all set up. The script can now be run without user interaction until 2SA expires.
You can set up email notifications for when the two-step authentication expires.
(Use --help to view information about SMTP options.)
Traceback (most recent call last):
File "/usr/bin/icloudpd", line 33, in <module>
sys.exit(load_entry_point('icloudpd==1.7.2', 'console_scripts', 'icloudpd')())
File "/usr/lib/python3.10/site-packages/click/core.py", line 722, in __call__ 
return self.main(*args, **kwargs) 
File "/usr/lib/python3.10/site-packages/click/core.py", line 697, in main 
rv = self.invoke(ctx) 
File "/usr/lib/python3.10/site-packages/click/core.py", line 895, in invoke 
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3.10/site-packages/click/core.py", line 535, in invoke 
return callback(*args, **kwargs)
File "/usr/lib/python3.10/site-packages/icloudpd-1.7.2-py3.10.egg/icloudpd/base.py", line 293, in main
libraries_dict = icloud.photos.libraries
File "/usr/lib/python3.10/site-packages/pyicloud_ipd/services/photos.py", line 275, in libraries
libraries[zone_name] = PhotoLibrary(
File "/usr/lib/python3.10/site-packages/pyicloud_ipd/services/photos.py", line 154, in __init__ 
request = self.service.session.post(
File "/usr/lib/python3.10/site-packages/requests/sessions.py", line 635, in post
return self.request("POST", url, data=data, json=json, **kwargs)
File "/usr/lib/python3.10/site-packages/pyicloud_ipd/base.py", line 100, in request 
self._raise_error(code, reason) 
File "/usr/lib/python3.10/site-packages/pyicloud_ipd/base.py", line 122, in _raise_error
raise api_error 
pyicloud_ipd.exceptions.PyiCloudAPIResponseError: INTERNAL_ERROR (INTERNAL_ERROR) 

@timrettop
Copy link

timrettop commented Apr 10, 2023

Is there any plans to fix this PR and merge it? I had the same error as @mikeknoop

@mikeknoop
Copy link

With no apparent changed, shared library API calls started working again for me on May 26th.

@property
def libraries(self):
if not self._libraries:
url = ('%s/changes/database' %

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got this working again by using

            url = ('%s/zones/list' %

here.

Copy link

@Lutzifer Lutzifer Jun 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

independent of this, it should also work if one manually looks for the correct library name on iCloud.com when showing the photosotos and giving that to the --library parameter

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you find the shared library name on icloud.com? Thank you.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

open photos on iCloud.com and watch the network requests using developer mode.
Look for the zones/list call.
The shared library name is in the result json of this call.

@lonevvolf
Copy link

Any chance this will get merged in the near future?

@AndreyNikiforov
Copy link

Any chance this will get merged in the near future?

I don't see reasons for merging: pyicloud library is no longer used in main icloudpd project, so merging this PR will have no affect on icloudpd (will not add shared libraries support on its own).

@mikeknoop
Copy link

I think this may be the only open PR anywhere (right now) that has a working POC for icloud shared libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants