Last active
December 17, 2023 03:40
-
-
Save Tatsh/0b5a10a2d25f6c8466290401d2026055 to your computer and use it in GitHub Desktop.
Use pyicloud to delete all photos from iCloud (may need to be run multiple times)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import json | |
import sys | |
from authentication import authenticate | |
from future.moves.urllib.parse import urlencode | |
if __name__ == '__main__': | |
username = sys.argv[1] | |
password = sys.argv[2] | |
smtp_username = smtp_password = smtp_host = smtp_port = smtp_no_tls = notification_email = None | |
print('Logging in') | |
icloud = authenticate(username, password, smtp_username, smtp_password, smtp_host, smtp_port, smtp_no_tls, notification_email) | |
photos = icloud.photos.all | |
operations = [] | |
url = '{}/records/modify?{}'.format(icloud.photos._service_endpoint, urlencode(icloud.photos.params)) | |
headers = {'Content-type': 'text/plain'} | |
seen_record_names = [] | |
for photo in photos: | |
# Avoid duplicate operations | |
if photo._asset_record['recordName'] in seen_record_names: | |
continue | |
seen_record_names.append(photo._asset_record['recordName']) | |
mr = {'fields': {'isDeleted': {'value': 1}}} | |
mr['recordChangeTag'] = photo._asset_record['recordChangeTag'] | |
mr['recordName'] = photo._asset_record['recordName'] | |
mr['recordType'] = 'CPLAsset' | |
op = dict( | |
operationType='update', | |
record=mr, | |
) | |
operations.append(op) | |
# Limit to 100 photos at a time | |
if len(operations) >= 100: | |
post_data = json.dumps(dict( | |
atomic=True, | |
desiredKeys=['isDeleted'], | |
operations=operations, | |
zoneID={'zoneName': 'PrimarySync'}, | |
)) | |
print('Deleting 100 photos') | |
print(icloud.photos.session.post(url, | |
data=post_data, | |
headers=headers).json()) | |
operations = [] |
I just had a similar issue. Made a quick script to do it :
https://github.com/zakirangwala/icloud-photo-manager
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i am getting below error
File "delall-icloud-photos.py", line 10, in
username = sys.argv[1]
IndexError: list index out of range