Skip to content

Commit

Permalink
Check more carefully for 'isFavorite' since it's not always there
Browse files Browse the repository at this point in the history
Fixes #1058, see that issue for an example of a file where this would
throw an exception before.
  • Loading branch information
euank committed Jan 18, 2025
1 parent 337ea77 commit b7ce1f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/icloudpd/xmp_sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def build_metadata(asset_record: dict[str, Any]) -> XMPMetadata:
):
rating = -1 # -1 means rejected: https://www.iptc.org/std/photometadata/specification/IPTC-PhotoMetadata#image-rating
# only mark photo as favorite if not hidden or deleted
elif asset_record["fields"]["isFavorite"]["value"] == 1:
elif "isFavorite" in asset_record["fields"] and asset_record["fields"]["isFavorite"]["value"] == 1:
rating = 5

return XMPMetadata(
Expand Down
5 changes: 5 additions & 0 deletions tests/test_xmp_sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ def test_build_metadata(self) -> None:
metadata = build_metadata(assetRecordStub)
assert metadata.Rating == 5

# Test favorites not present
del assetRecordStub["fields"]["isFavorite"]
metadata = build_metadata(assetRecordStub)
assert metadata.Rating is None

# Test Deleted
assetRecordStub["fields"]["isDeleted"]["value"] = 1
metadata = build_metadata(assetRecordStub)
Expand Down

0 comments on commit b7ce1f7

Please sign in to comment.