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

fix problem : photos of Recently Deleted won't be expunged with --album "Recently Deleted“ --delete-after-download #931

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions src/icloudpd/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ def delete_photo(
post_data = json.dumps(
{
"atomic": True,
"desiredKeys": ["isDeleted"],
#"desiredKeys": ["isDeleted"],#this is not needed,2024-07-29
"operations": [
{
"operationType": "update",
Expand Down Expand Up @@ -1331,8 +1331,9 @@ def should_break(counter: Counter) -> bool:
break
item = next(photos_iterator)
if download_photo(consecutive_files_found, item) and delete_after_download:
del_photo=expunge_photo if album == "Recently Deleted" else delete_photo
delete_local = partial(
delete_photo_dry_run if dry_run else delete_photo,
delete_photo_dry_run if dry_run else del_photo,
logger,
icloud.photos,
library_object,
Expand Down Expand Up @@ -1395,3 +1396,37 @@ def should_break(counter: Counter) -> bool:
break # pragma: no cover

return 0


def expunge_photo(
logger: logging.Logger,
photo_service: PhotosService,
library_object: PhotoLibrary,
photo: PhotoAsset,
) -> None:
"""Expunge a photo from the Recently Deleted."""
clean_filename_local = photo.filename
logger.debug("Expunging %s in Recently Deleted...", clean_filename_local)
url = (
f"{photo_service._service_endpoint}/records/modify?"
f"{urllib.parse.urlencode(photo_service.params)}"
)
post_data = json.dumps(
{
"atomic": True,
"operations": [
{
"operationType": "update",
"record": {
"fields": {"isExpunged": {"value": 1}},
"recordChangeTag": photo._asset_record["recordChangeTag"],
"recordName": photo._asset_record["recordName"],
"recordType": "CPLAsset",
},
}
],
"zoneID": library_object.zone_id,
}
)
photo_service.session.post(url, data=post_data, headers={"Content-type": "application/json"})
logger.info("Expunged %s in Recently Deleted", clean_filename_local)
Loading