Skip to content

Commit

Permalink
Merge branch 'main' into normalize_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
tymmej authored Aug 23, 2023
2 parents 2887630 + eddd49e commit 9e2d20a
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/sync_photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ def photo_wanted(photo, extensions):
def generate_file_name(photo, file_size, destination_path):
"""Generate full path to file."""
filename = photo.filename
name, extension = filename.rsplit(".", 1)
name, extension = filename.rsplit(".", 1) if "." in filename else [filename, ""]
file_path = os.path.join(destination_path, filename)
file_size_path = os.path.join(
destination_path, f'{"__".join([name, file_size])}.{extension}'
destination_path,
f'{"__".join([name, file_size])}'
if extension == ""
else f'{"__".join([name, file_size])}.{extension}',
)
file_size_id_path = os.path.join(
destination_path,
f'{"__".join([name, file_size, base64.urlsafe_b64encode(photo.id.encode()).decode()])}.{extension}',
f'{"__".join([name, file_size, base64.urlsafe_b64encode(photo.id.encode()).decode()])}'
if extension == ""
else f'{"__".join([name, file_size, base64.urlsafe_b64encode(photo.id.encode()).decode()])}.{extension}',
)

file_size_id_path_norm = unicodedata.normalize('NFC', file_size_id_path)
Expand Down Expand Up @@ -88,7 +93,7 @@ def process_photo(photo, file_size, destination_path, files):
f"File size {file_size} not found on server. Skipping the photo {photo_path} ..."
)
return False
if not files is None:
if files is not None:
files.add(photo_path)
if photo_exists(photo, file_size, photo_path):
return False
Expand Down
11 changes: 10 additions & 1 deletion tests/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3843,7 +3843,7 @@ def request(self, method, url, **kwargs):
"query?remapEnums=True&getCurrentSyncToken=True"
][2]["response"]
)
if data.get("query").get("filterBy")[0]["fieldValue"]["value"] == 6:
if data.get("query").get("filterBy")[0]["fieldValue"]["value"] == 7:
return ResponseMock(
photos_data.DATA[
"query?remapEnums=True&getCurrentSyncToken=True"
Expand All @@ -3869,6 +3869,9 @@ def request(self, method, url, **kwargs):
# IMG_3148.JPG
or "https://cvws.icloud-content.com/B/ARZd_GzpY62XRtXt+jP6UsV4fBZHATi6BbOzDuHl6RONNFCub9eqZqSm"
in url
# no-extension
or "https://cvws.icloud-content.com/B/ARZd_GzpY62XRtXt+jP6UsV4fBZIATi6BbOzDuHl6RONNFCub9eqZqSn"
in url
# IMG_3328.JPG
or "https://cvws.icloud-content.com/B/EeGlt2PppPTgd0Q7mp8GenIugSh7AQYmx-DRYXnMs0tkDZ3rorp4IB99"
in url
Expand All @@ -3893,6 +3896,9 @@ def request(self, method, url, **kwargs):
# IMG_3148.JPG
or "https://cvws.icloud-content.com/B/AVx3_VKkbWPdNbWw68mrWzSuemXgAdUIDFzHC2rVOvwTz0jPi_tKihnb"
in url
# no-extension
or "https://cvws.icloud-content.com/B/AVx3_VKkbWPdNbWw68mrWzSuemXiAdUIDFzHC2rVOvwTz0jPi_tKihnn"
in url
# IMG_3328.JPG
or "https://cvws.icloud-content.com/B/YN1v8eGiHYYZ_aKUkMuGtSf0P1BNAXKVYPcDa-9Mjvnap0ZS-p2Z24V3"
in url
Expand All @@ -3919,6 +3925,9 @@ def request(self, method, url, **kwargs):
# IMG_3148.JPG
or "https://cvws.icloud-content.com/B/ARpHiouI3Ib_ziuZYTCiSikohvMYARtMrcvA8cbMefPDnmwSWQwe-mBd"
in url
# no-extension
or "https://cvws.icloud-content.com/B/ARpHiouI3Ib_ziuZYTCiSikohvMZARtMrcvA8cbMefPDnmwSWQwe-mBe"
in url
# IMG_3328.JPG
or "https://cvws.icloud-content.com/B/DmK0xzSiAUSFrAsYYAvby7QHrMDeAR5TiM9Qko4rHwmoDH1BgNRVZpF4"
in url
Expand Down
185 changes: 185 additions & 0 deletions tests/data/photos_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,101 @@
"zoneType": "REGULAR_CUSTOM_ZONE",
},
},
# no-extension
{
"recordName": "AVx3/VKkbWPdNbWw68mrWzSuemXh",
"recordType": "CPLMaster",
"fields": {
"itemType": {"value": "public.jpeg", "type": "STRING"},
"resJPEGThumbFingerprint": {
"value": "ARpHiouI3Ib/ziuZYTCiSikohvMZ",
"type": "STRING",
},
"filenameEnc": {
"value": "bm8tZXh0ZW5zaW9u",
"type": "ENCRYPTED_BYTES",
},
"resJPEGMedRes": {
"value": {
"fileChecksum": "ARZd/GzpY62XRtXt+jP6UsV4fBZI",
"size": 1074354,
"wrappingKey": "dmZqsyvxEA4s3CvifNMApA==",
"referenceChecksum": "ATi6BbOzDuHl6RONNFCub9eqZqSm",
# pylint: disable=C0321
"downloadURL": "https://cvws.icloud-content.com/B/ARZd_GzpY62XRtXt+jP6UsV4fBZIATi6BbOzDuHl6RONNFCub9eqZqSn/${f}?o=AkMi62tflbXgUrgSyQZ94SinXG9TYXZ6tydGOmDQx9HG&v=1&x=3&a=CAogc8yqpMgxKnf363cp0n1CujaxnsWY_KrZ3VEN9QchlhcSbRDGkq2nty8Yxu-IqbcvIgEAUgR4fBZHWgSqZqSmaiaxcg1zIsiESwGaEOecYR84r83ltACA6SY5ypGyvYxKD0M3LmqI8HIm7n2S2UL6EBM2Z3a9YFIGX8MrKABFDMA5TXFPUVUP6AfsnKigVMc&e=1629757781&fl=&r=4d5c62f6-c81b-4e60-a785-4139aad087a7-1&k=dmZqsyvxEA4s3CvifNMApA&ckc=com.apple.photos.cloud&ckz=PrimarySync&y=1&p=104&s=rYmwpGBg6DPYHSGj6UAOnCfuMPk", # noqa: E501
},
"type": "ASSETID",
},
"originalOrientation": {"value": 1, "type": "INT64"},
"resJPEGMedHeight": {"value": 1747, "type": "INT64"},
"resOriginalRes": {
"value": {
"fileChecksum": "AVx3/VKkbWPdNbWw68mrWzSuemXi",
"size": 2194253,
"wrappingKey": "Nz2a7ohpe3KPptCk0J0lWA==",
"referenceChecksum": "AdUIDFzHC2rVOvwTz0jPi/tKihnb",
# pylint: disable=C0321
"downloadURL": "https://cvws.icloud-content.com/B/AVx3_VKkbWPdNbWw68mrWzSuemXiAdUIDFzHC2rVOvwTz0jPi_tKihnn/${f}?o=AksMTyqi4NosuW50ei90oXcv82fP1r-6QocLorp20RpO&v=1&x=3&a=CAogfvU0-_8L-3qRcy6jZsj3Vuqt4aL2rk5xVXF7lwVV6A8SbRDGkq2nty8Yxu-IqbcvIgEAUgSuemXgWgRKihnbaiZoWboa3qYl3KVDo1VGIHrRDoySixw8lzXtf1Y-AnoVN1Pd4hLkPnImXYuLGS8iK7BRJcQg25R5hk54OD04duy2TscnYu1mACOSERXpXEI&e=1629757781&fl=&r=4d5c62f6-c81b-4e60-a785-4139aad087a7-1&k=Nz2a7ohpe3KPptCk0J0lWA&ckc=com.apple.photos.cloud&ckz=PrimarySync&y=1&p=104&s=t3NT5mCLmsRjPqAGvROVsMrAjfg", # noqa: E501
},
"type": "ASSETID",
},
"resJPEGMedFileType": {
"value": "public.jpeg",
"type": "STRING",
},
"resJPEGThumbHeight": {"value": 409, "type": "INT64"},
"resJPEGThumbWidth": {"value": 421, "type": "INT64"},
"resOriginalWidth": {"value": 2132, "type": "INT64"},
"resJPEGThumbFileType": {
"value": "public.jpeg",
"type": "STRING",
},
"dataClassType": {"value": 1, "type": "INT64"},
"resOriginalFingerprint": {
"value": "AVx3/VKkbWPdNbWw68mrWzSuemXh",
"type": "STRING",
},
"resJPEGMedWidth": {"value": 1799, "type": "INT64"},
"resJPEGThumbRes": {
"value": {
"fileChecksum": "ARpHiouI3Ib/ziuZYTCiSikohvMZ",
"size": 340532,
"wrappingKey": "UiIQr3rRvyIcoAz/sxDugQ==",
"referenceChecksum": "ARtMrcvA8cbMefPDnmwSWQwe+mBd",
# pylint: disable=C0321
"downloadURL": "https://cvws.icloud-content.com/B/ARpHiouI3Ib_ziuZYTCiSikohvMZARtMrcvA8cbMefPDnmwSWQwe-mBe/${f}?o=Auh2MA-6wuqdRGUDQ4kZL3fuuuMVWVVnTnTcThej9ad5&v=1&x=3&a=CAogaHp1wKKc8QF3MI-2OrLYdQx8V4PIVZvFQyuN1m6pXFMSbRDHkq2nty8Yx--IqbcvIgEAUgQohvMYWgQe-mBdaibQsOQuSEfHUK0xs9nLWG6nHKAvRCwkkmsvXL1Ku9aCARYpDg4mWHImDCoL_RiyOC-KXU_0Jpntuid9MdC08bvpHUp5hkzlctbjsBvT654&e=1629757781&fl=&r=4d5c62f6-c81b-4e60-a785-4139aad087a7-1&k=UiIQr3rRvyIcoAz_sxDugQ&ckc=com.apple.photos.cloud&ckz=PrimarySync&y=1&p=104&s=Rx2sZoVhs_Phm_Ps3RvVwJ2mgvA", # noqa: E501
},
"type": "ASSETID",
},
"resOriginalFileType": {
"value": "public.jpeg",
"type": "STRING",
},
"resOriginalHeight": {"value": 2070, "type": "INT64"},
"resJPEGMedFingerprint": {
"value": "ARZd/GzpY62XRtXt+jP6UsV4fBZH",
"type": "STRING",
},
},
"pluginFields": {},
"recordChangeTag": "2wwt",
"created": {
"timestamp": 1572285894332,
"userRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
"deviceID": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
},
"modified": {
"timestamp": 1595187518048,
"userRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
"deviceID": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
},
"deleted": False,
"zoneID": {
"zoneName": "PrimarySync",
"ownerRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
"zoneType": "REGULAR_CUSTOM_ZONE",
},
},
# IMG_3148.JPG - from another device (actual IMG_3206.JPG)
{
"recordName": "Ab/8kUAhnGzSxnl9yWvh8JKBpOvW",
Expand Down Expand Up @@ -1206,6 +1301,61 @@
"zoneType": "REGULAR_CUSTOM_ZONE",
},
},
# Reference to no-extension
{
"recordName": "986F607D-E8E0-45C4-B230-EF37B7E40B78",
"recordType": "CPLAsset",
"fields": {
"assetDate": {"value": 1572285626625, "type": "TIMESTAMP"},
"orientation": {"value": 1, "type": "INT64"},
"addedDate": {"value": 1572285626635, "type": "TIMESTAMP"},
"assetSubtypeV2": {"value": 0, "type": "INT64"},
"assetHDRType": {"value": 0, "type": "INT64"},
"timeZoneOffset": {"value": -25200, "type": "INT64"},
"masterRef": {
"value": {
"recordName": "AVx3/VKkbWPdNbWw68mrWzSuemXh",
"action": "DELETE_SELF",
"zoneID": {
"zoneName": "PrimarySync",
"ownerRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
"zoneType": "REGULAR_CUSTOM_ZONE",
},
},
"type": "REFERENCE",
},
"adjustmentRenderType": {"value": 0, "type": "INT64"},
"vidComplDispScale": {"value": 0, "type": "INT64"},
"isHidden": {"value": 0, "type": "INT64"},
"duration": {"value": 0, "type": "INT64"},
"burstFlags": {"value": 0, "type": "INT64"},
"assetSubtype": {"value": 0, "type": "INT64"},
"vidComplDurScale": {"value": 0, "type": "INT64"},
"vidComplDurValue": {"value": 0, "type": "INT64"},
"vidComplVisibilityState": {"value": 0, "type": "INT64"},
"customRenderedValue": {"value": 0, "type": "INT64"},
"isFavorite": {"value": 0, "type": "INT64"},
"vidComplDispValue": {"value": 0, "type": "INT64"},
},
"pluginFields": {},
"recordChangeTag": "2wwu",
"created": {
"timestamp": 1572285894335,
"userRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
"deviceID": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
},
"modified": {
"timestamp": 1595187518048,
"userRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
"deviceID": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
},
"deleted": False,
"zoneID": {
"zoneName": "PrimarySync",
"ownerRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
"zoneType": "REGULAR_CUSTOM_ZONE",
},
},
# Reference to IMG_3148.JPG from another device (actual IMG_3206.JPG)
{
"recordName": "97362090-90E4-4F54-A564-14F7ECC02707",
Expand Down Expand Up @@ -1436,6 +1586,41 @@
"zoneType": "REGULAR_CUSTOM_ZONE",
},
},
# no-extension in album 2
{
"recordName": "986F607D-E8E0-45C4-B230-EF37B7E40B77-IN-E4RT4FB7-4A35-4958-1D42-5769E66BE408",
"recordType": "CPLContainerRelation",
"fields": {
"itemId": {
"value": "986F607D-E8E0-45C4-B230-EF37B7E40B78",
"type": "STRING",
},
"isKeyAsset": {"value": 0, "type": "INT64"},
"position": {"value": 2048, "type": "INT64"},
"containerId": {
"value": "E4RT4FB7-4A35-4958-1D42-5769E66BE407",
"type": "STRING",
},
},
"pluginFields": {},
"recordChangeTag": "3f7a",
"created": {
"timestamp": 1572285894336,
"userRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
"deviceID": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
},
"modified": {
"timestamp": 1595190039047,
"userRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
"deviceID": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
},
"deleted": False,
"zoneID": {
"zoneName": "PrimarySync",
"ownerRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
"zoneType": "REGULAR_CUSTOM_ZONE",
},
},
# IMG_3148.JPG in album 2 from another device (actual IMG_3206.JPG)
{
"recordName": "97362090-90E4-4F54-A564-14F7ECC02706-IN-E4RT4FB7-4A35-4958-1D42-5769E66BE408",
Expand Down

0 comments on commit 9e2d20a

Please sign in to comment.