fix #192 support upload media to albums#421
fix #192 support upload media to albums#421lucemia wants to merge 3 commits intopicklepete:masterfrom
Conversation
based on the https://support.apple.com/en-ca/guide/icloud/mmb5dbaf376f/icloud so I switch to this solutions |
|
Thanks a lot - works for me, however, I can only upload to the main "Recents" album. Any idea if it is possible to select the album for the upload? |
Hi there, sorry for this little offtopic here, but do i understand correctly that you manage to upload directly to icloud Photos with https://github.com/RhetTbull/osxphotos ? if so, how? |
Hi Thomas, did you found a way to add photos to a specific album? |
I made some new progress, I found that uploading photos and adding them to a specific album are two steps. A simple code example is as follows: class MyService(PyiCloudService):
def upload_photo(self, photo_path, album_name="MyAlbum"):
# Skip the upload process, See https://github.com/lucemia/pyicloud/blob/96d9f26553ebdfb47f3cfbc8ec13b76e70ff0cff/pyicloud/services/photos.py#L231
# ...
photo_id = [x["recordName"] for x in request.json()["records"] if x["recordType"] == "CPLAsset"][0]
# Query the target album properties (Especially ZoneID, I don't quite understand the meaning of this field, but the existing Python API cannot get it.)
for folder in self.photos._fetch_folders():
folder_name = base64.b64decode(
folder.get("fields", {}).get("albumNameEnc", {}).get("value", "")
).decode("utf-8")
if folder_name == album_name:
album_id = folder["recordName"]
zone_id = folder["zoneID"]["ownerRecordName"]
album_len = len(self.photos.albums[album_name])
# Put photos into the specified album
url = f"{self.photos.service_endpoint}/records/modify?{urlencode(self.params)}"
json_data = {
"atomic": True,
"zoneID": {
"zoneName": "PrimarySync",
"ownerRecordName": zone_id,
"zoneType": "REGULAR_CUSTOM_ZONE"
},
"operations": [
{
"operationType": "create",
"record": {
"fields": {
"itemId": {
"value": photo_id
},
"position": {
"value": 1024 * (1 + album_len)
},
"containerId": {
"value": album_id
}
},
"recordType": "CPLContainerRelation",
"recordName": f"{photo_id}-IN-{album_id}"
}
}
]
}
request = self.session.post(
url, data=json.dumps(json_data), headers={"Content-type": "text/plain"}
) |
|
any chance to merge this? |
Proposed change
Add
.upload_filemethod toPhotosService.The PR is based on https://github.com/picklepete/pyicloud/pull/354/files work but:
KeyError: 'dsid'errorType of change
Example of code:
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: