Skip to content

Commit

Permalink
Fix crash when creating xmp sidecar: Some images come with a plist in…
Browse files Browse the repository at this point in the history
… the 'adjustmentSimpleDataEnc' field
  • Loading branch information
chkuendig committed Jan 14, 2025
1 parent 01a2226 commit 92dbd99
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Change log

## Unreleased
- Fix: crash when downloading files with `--xmp-sidecar` caused by files having non-JSON adjustment data. [#1056](https://github.com/icloud-photos-downloader/icloud_photos_downloader/issues/1056)

## 1.26.0 (2025-01-13)

Expand Down
16 changes: 8 additions & 8 deletions src/icloudpd/xmp_sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ def generate_xmp_file(
# decode asset record fields
# for k in asset_record['fields']:
# if asset_record["fields"][k]['type'] == "ENCRYPTED_BYTES":
# try:
# asset_record["fields"][k]['decoded'] = plistlib.loads(base64.b64decode(asset_record['fields'][k]['value']), fmt=plistlib.FMT_BINARY)
# except plistlib.InvalidFileException:
# try:
# asset_record["fields"][k]['decoded'] = json.loads(zlib.decompress(base64.b64decode(asset_record['fields'][k]['value']),-zlib.MAX_WBITS))
# except Exception as e:
# asset_record["fields"][k]['decoded'] = base64.b64decode(asset_record['fields'][k]['value']).decode("utf-8")
# try:
# asset_record["fields"][k]['decoded'] = plistlib.loads(base64.b64decode(asset_record['fields'][k]['value']), fmt=plistlib.FMT_BINARY)
# except plistlib.InvalidFileException:
# try:
# asset_record["fields"][k]['decoded'] = json.loads(zlib.decompress(base64.b64decode(asset_record['fields'][k]['value']),-zlib.MAX_WBITS))
# except Exception as e:
# asset_record["fields"][k]['decoded'] = base64.b64decode(asset_record['fields'][k]['value']).decode("utf-8")
# json.dump(asset_record["fields"], open(download_path + ".ar.json", "w"), indent=4, default=str, sort_keys=True)

if can_write_file:
Expand All @@ -87,7 +87,7 @@ def build_metadata(asset_record: dict[str, Any]) -> XMPMetadata:
)

orientation = None
if "adjustmentSimpleDataEnc" in asset_record["fields"]:
if "adjustmentSimpleDataEnc" in asset_record["fields"] and not asset_record["fields"]["adjustmentSimpleDataEnc"]["value"].startswith("YnBsaXN0MD"): # not a plist
adjustments = json.loads(
zlib.decompress(
base64.b64decode(asset_record["fields"]["adjustmentSimpleDataEnc"]["value"]),
Expand Down

0 comments on commit 92dbd99

Please sign in to comment.