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 Dec 21, 2024
1 parent 1b5269c commit 8f6cd8e
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/icloudpd/xmp_sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,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 @@ -86,7 +86,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 8f6cd8e

Please sign in to comment.