Repository: mandarons/icloud-drive-docker (python)

Issue:
[BUG] Inifinite overwrite when photos has same names
**Describe the bug**
Photo Library can contain multiple photos with same @property filename.
Eg. default names `IMG_xyza.HEIC` when using multiple phones.

**To Reproduce**
Add photos with same names to library and run docker image.
You will see three things:
1) number of downloaded files is different than in iCloud
2) docker constantly downloads same files
3) number of downloaded files is constant

**Expected behavior**
Docker downloads different files even if filenames are same. It should use @property id to differentiate photos.

**Screenshots**
![Screenshot_20221114_111059](https://user-images.githubusercontent.com/443698/201636199-7c2100d3-e54d-48f0-ba4e-03112c10d9eb.png)
**Configuration**
Backup all photos

**Additional context**
None


Pull request:
Added photo quality and unique id to local photo names
This fixes #98 as well as implements prerequisite for shared library support at individual photos level.

Patch:
diff --git a/src/sync_photos.py b/src/sync_photos.py
index 09c825da..f5d915af 100644
--- a/src/sync_photos.py
+++ b/src/sync_photos.py
@@ -1,5 +1,6 @@
 """Sync photos module."""
 ___author___ = "Mandar Patil <mandarons@pm.me>"
+import base64
 import os
 import shutil
 import time
@@ -12,18 +13,20 @@ from src import LOGGER, config_parser
 def generate_file_name(photo, file_size, destination_path):
     """Generate full path to file."""
     filename = photo.filename
-    if file_size != "original":
-        tokens = photo.filename.rsplit(".", 1)
-        tokens.insert(len(tokens) - 1, file_size)
-        filename = "__".join(tokens[:-1]) + "." + tokens[-1]
-    else:
-        tokens = photo.filename.rsplit(".", 1)
-        tokens.insert(len(tokens) - 1, file_size)
-        original_filename = "__".join(tokens[:-1]) + "." + tokens[-1]
-        original_file_path = os.path.join(destination_path, original_filename)
-        if os.path.isfile(original_file_path):
-            os.rename(original_file_path, os.path.join(destination_path, filename))
-    return os.path.abspath(os.path.join(destination_path, filename))
+    name, extension = filename.rsplit(".", 1)
+    file_path = os.path.join(destination_path, filename)
+    file_size_path = os.path.join(
+        destination_path, 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}',
+    )
+    if os.path.isfile(file_path):
+        os.rename(file_path, file_size_id_path)
+    if os.path.isfile(file_size_path):
+        os.rename(file_size_path, file_size_id_path)
+    return file_size_id_path
 
 
 def photo_exists(photo, file_size, local_path):


Test patch:
diff --git a/tests/data/__init__.py b/tests/data/__init__.py
index d6c57554..caf374b7 100644
--- a/tests/data/__init__.py
+++ b/tests/data/__init__.py
@@ -3801,7 +3801,7 @@ class ICloudPySessionMock(base.ICloudPySession):
                                 "query?remapEnums=True&getCurrentSyncToken=True"
                             ][2]["response"]
                         )
-                    if data.get("query").get("filterBy")[0]["fieldValue"]["value"] == 5:
+                    if data.get("query").get("filterBy")[0]["fieldValue"]["value"] == 6:
                         return ResponseMock(
                             photos_data.DATA[
                                 "query?remapEnums=True&getCurrentSyncToken=True"
@@ -3815,28 +3815,48 @@ class ICloudPySessionMock(base.ICloudPySession):
                 )
         # Photos download
         if (
-            "https://cvws.icloud-content.com/B/AeGlt2PppPTgd0Q7mp8GuxIugSh6" in url
-            or "https://cvws.icloud-content.com/B/ARKzBUr-DdmTaP_SAVglTurWtsmr" in url
-            or "https://cvws.icloud-content.com/B/ASTSuc7S58IPmVCJIUslbeCRjsno" in url
-            or "https://cvws.icloud-content.com/B/ATTRy6p-Q3U1HqcF6BUKrrOMnjvn" in url
-            or "https://cvws.icloud-content.com/B/ARZd_GzpY62XRtXt-jP6UsV4fBZH" in url
+            # IMG_3327.JPG
+            "https://cvws.icloud-content.com/B/ARKzBUr-DdmTaP_SAVglTurWtsmrAb5Vyk36t2jwuON7WSxvon_DvGtK"
+            in url
+            # IMG_3322.JPG
+            or "https://cvws.icloud-content.com/B/ASTSuc7S58IPmVCJIUslbeCRjsnoASIoOBi88potAS0gE8tfnojuSlrb"
+            in url
+            # IMG_3306.JPG
+            or "https://cvws.icloud-content.com/B/ATTRy6p-Q3U1HqcF6BUKrrOMnjvnATqG89bMsXhtmMRMw009uhyJc_Kh"
+            in url
+            # IMG_3148.JPG
+            or "https://cvws.icloud-content.com/B/ARZd_GzpY62XRtXt+jP6UsV4fBZHATi6BbOzDuHl6RONNFCub9eqZqSm"
+            in url
             # IMG_3328.JPG
             or "https://cvws.icloud-content.com/B/EeGlt2PppPTgd0Q7mp8GenIugSh7AQYmx-DRYXnMs0tkDZ3rorp4IB99"
             in url
+            # IMG_3148.JPG another device
+            or "https://cvws.icloud-content.com/B/ATTRy6p-Q3U1HqcF6BUKrrOMnjvoATqG89bMsXhtmMRMw009uhyJc_Kh"
+            in url
         ):
             return ResponseMock(
                 {},
                 raw=open(os.path.join(os.path.dirname(__file__), "medium.jpeg"), "rb"),
             )
         if (
-            "https://cvws.icloud-content.com/B/AT1v8eGiHYXP_aKUkMuGtSf0P1BN" in url
-            or "https://cvws.icloud-content.com/B/AUvKU8j-Z5pfqGI_fe-9tibuqfVR" in url
-            or "https://cvws.icloud-content.com/B/AUxVFT2yVsQ5739tmU5c1497duFD" in url
-            or "https://cvws.icloud-content.com/B/Ab_8kUAhnGzSxnl9yWvh8JKBpOvV" in url
-            or "https://cvws.icloud-content.com/B/AVx3_VKkbWPdNbWw68mrWzSuemXg" in url
+            # IMG_3327.JPG
+            "https://cvws.icloud-content.com/B/AUvKU8j-Z5pfqGI_fe-9tibuqfVRAd0I2qxdsqlGuSLlqtTBgoKndHE_"
+            in url
+            # IMG_3322.JPG
+            or "https://cvws.icloud-content.com/B/AUxVFT2yVsQ5739tmU5c1497duFDAdkoZP1534bwlULpwCdn2fd44LAt"
+            in url
+            # IMG_3306.JPG
+            or "https://cvws.icloud-content.com/B/Ab_8kUAhnGzSxnl9yWvh8JKBpOvVAVLSGMHt-PAQ9_krqqfXATNX57d5"
+            in url
+            # IMG_3148.JPG
+            or "https://cvws.icloud-content.com/B/AVx3_VKkbWPdNbWw68mrWzSuemXgAdUIDFzHC2rVOvwTz0jPi_tKihnb"
+            in url
             # IMG_3328.JPG
             or "https://cvws.icloud-content.com/B/YN1v8eGiHYYZ_aKUkMuGtSf0P1BNAXKVYPcDa-9Mjvnap0ZS-p2Z24V3"
             in url
+            # IMG_3148.JPG another device
+            or "https://cvws.icloud-content.com/B/Ab_8kUAhnGzSxnl9yWvh8JKBpOvWAVLSGMHt-PAQ9_krqqfXATNX57d5"
+            in url
         ):
             return ResponseMock(
                 {},
@@ -3845,14 +3865,24 @@ class ICloudPySessionMock(base.ICloudPySession):
                 ),
             )
         if (
-            "https://cvws.icloud-content.com/B/AfK0xzSiAUNFrAsZYAvby7QHrMOb" in url
-            or "https://cvws.icloud-content.com/B/ASy6f_leU1-xkR1aPmQyvYmwHUpE" in url
-            or "https://cvws.icloud-content.com/B/ASPVZ_Pft6gIN2VEA_oUbqQzh6Wy" in url
-            or "https://cvws.icloud-content.com/B/AQNND5zpteAXnnBP2BmDd0ropjY9" in url
-            or "https://cvws.icloud-content.com/B/ARpHiouI3Ib_ziuZYTCiSikohvMY" in url
+            # IMG_3327.JPG
+            "https://cvws.icloud-content.com/B/ASy6f_leU1-xkR1aPmQyvYmwHUpEARHOzkI3sbX3SZDmNQgttNJ9DqQa"
+            in url
+            # IMG_3322.JPG
+            or "https://cvws.icloud-content.com/B/ASPVZ_Pft6gIN2VEA_oUbqQzh6WyAXd258pYF6LLhmADLoZAumNqI-8M"
+            in url
+            # IMG_3306.JPG
+            or "https://cvws.icloud-content.com/B/AQNND5zpteAXnnBP2BmDd0ropjY9AV2Zh7WygJu74eNWVuuMT4lM8qme"
+            in url
+            # IMG_3148.JPG
+            or "https://cvws.icloud-content.com/B/ARpHiouI3Ib_ziuZYTCiSikohvMYARtMrcvA8cbMefPDnmwSWQwe-mBd"
+            in url
             # IMG_3328.JPG
             or "https://cvws.icloud-content.com/B/DmK0xzSiAUSFrAsYYAvby7QHrMDeAR5TiM9Qko4rHwmoDH1BgNRVZpF4"
             in url
+            # IMG_3148.JPG another device
+            or "https://cvws.icloud-content.com/B/AQNND5zpteAXnnBP2BmDd0ropjY0AV2Zh7WygJu74eNWVuuMT4lM8qme"
+            in url
         ):
             return ResponseMock(
                 {},
diff --git a/tests/data/photos_data.py b/tests/data/photos_data.py
index d72f8671..eea05db2 100644
--- a/tests/data/photos_data.py
+++ b/tests/data/photos_data.py
@@ -762,7 +762,7 @@ DATA = {
                                     "wrappingKey": "dmZqsyvxEA4s3CvifNMApA==",
                                     "referenceChecksum": "ATi6BbOzDuHl6RONNFCub9eqZqSm",
                                     # pylint: disable=C0321
-                                    "downloadURL": "https://cvws.icloud-content.com/B/ARZd_GzpY62XRtXt-jP6UsV4fBZHATi6BbOzDuHl6RONNFCub9eqZqSm/${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
+                                    "downloadURL": "https://cvws.icloud-content.com/B/ARZd_GzpY62XRtXt+jP6UsV4fBZHATi6BbOzDuHl6RONNFCub9eqZqSm/${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",
                             },
@@ -836,6 +836,101 @@ DATA = {
                             "zoneType": "REGULAR_CUSTOM_ZONE",
                         },
                     },
+                    # IMG_3148.JPG - from another device (actual IMG_3206.JPG)
+                    {
+                        "recordName": "Ab/8kUAhnGzSxnl9yWvh8JKBpOvW",
+                        "recordType": "CPLMaster",
+                        "fields": {
+                            "itemType": {"value": "public.jpeg", "type": "STRING"},
+                            "filenameEnc": {
+                                "value": "SU1HXzMxNDguSlBH",
+                                "type": "ENCRYPTED_BYTES",
+                            },
+                            "dataClassType": {"value": 1, "type": "INT64"},
+                            "resJPEGThumbRes": {
+                                "value": {
+                                    "fileChecksum": "ATTRy6p+Q3U1HqcF6BUKrrOMnjvo",
+                                    "size": 1074354,
+                                    "wrappingKey": "pYDpdhqdaL9SAxHilZEj3Q==",
+                                    "referenceChecksum": "ATqG89bMsXhtmMRMw009uhyJc/Kh",
+                                    # pylint: disable=C0321
+                                    "downloadURL": "https://cvws.icloud-content.com/B/ATTRy6p-Q3U1HqcF6BUKrrOMnjvoATqG89bMsXhtmMRMw009uhyJc_Kh/${f}?o=AovA4TUyNl2kYkqOdInhEXGZ_6Lgkx1fTEsqpkkMh3hm&v=1&x=3&a=CAogVnr-sKWlefxaxarlxJ-k7EPRB-Q851T9df9zyhCvis0SbRC7kq2nty8Yu--IqbcvIgEAUgSMnjvnWgSJc_KhaiZCiMEZuykdl4ex2Ra8y53DbEEtJi6ItoX1e6b8TOoWXYiLA-mkr3Im7aDvMFg_m7tYuslgLZFXL8hxJftHL4oTy1ZpuVaP__2nTQTPLp4&e=1629757781&fl=&r=4d5c62f6-c81b-4e60-a785-4139aad087a7-1&k=pYDpdhqdaL9SAxHilZEj3Q&ckc=com.apple.photos.cloud&ckz=PrimarySync&y=1&p=104&s=IKz0oqClwHpM9shdTb3e5liYV5E",  # noqa: E501
+                                },
+                                "type": "ASSETID",
+                            },
+                            "resJPEGThumbHeight": {"value": 1781, "type": "INT64"},
+                            "resJPEGThumbWidth": {"value": 1765, "type": "INT64"},
+                            "resJPEGThumbFileType": {
+                                "value": "public.jpeg",
+                                "type": "STRING",
+                            },
+                            "resJPEGThumbFingerprint": {
+                                "value": "ATTRy6p+Q3U1HqcF6BUKrrOMnjvn",
+                                "type": "STRING",
+                            },
+                            "originalOrientation": {"value": 1, "type": "INT64"},
+                            "resJPEGMedRes": {
+                                "value": {
+                                    "fileChecksum": "Ab/8kUAhnGzSxnl9yWvh8JKBpOvW",
+                                    "size": 2194253,
+                                    "wrappingKey": "YIFaf0awZsX16khQaJ5pHw==",
+                                    "referenceChecksum": "AVLSGMHt+PAQ9/krqqfXATNX57d5",
+                                    # pylint: disable=C0321
+                                    "downloadURL": "https://cvws.icloud-content.com/B/Ab_8kUAhnGzSxnl9yWvh8JKBpOvWAVLSGMHt-PAQ9_krqqfXATNX57d5/${f}?o=AvHBwurT0LTKni3mzYNLu4FnSeLeXfxYgSThZ4ImxjO8&v=1&x=3&a=CAogTIPbEVbPukTNLTRMbKPr3KEw-OwlmwJ6E2P4TWSVmS0SbRC7kq2nty8Yu--IqbcvIgEAUgSBpOvWWgRX57d5aibAoDs2oxjwpsMmZzKDj2ndE0sAhXdcwzBu-U_oZGpb059mW6D0dnImIjbNA_Bqcyw_VKQmNxeLtnGtGwyFB16OPwFKYcs1KsSFvHFAD7Y&e=1629757781&fl=&r=4d5c62f6-c81b-4e60-a785-4139aad087a7-1&k=YIFaf0awZsX16khQaJ5pHw&ckc=com.apple.photos.cloud&ckz=PrimarySync&y=1&p=104&s=1bdqdYxBN6JqLAkjMyHSEGNkqDA",  # noqa: E501
+                                },
+                                "type": "ASSETID",
+                            },
+                            "resJPEGMedWidth": {"value": 1995, "type": "INT64"},
+                            "resJPEGMedHeight": {"value": 2013, "type": "INT64"},
+                            "resJPEGMedFileType": {
+                                "value": "public.jpeg",
+                                "type": "STRING",
+                            },
+                            "resJPEGMedFingerprint": {
+                                "value": "Ab/8kUAhnGzSxnl9yWvh8JKBpOvW",
+                                "type": "STRING",
+                            },
+                            "resOriginalFingerprint": {
+                                "value": "AQNND5zpteAXnnBP2BmDd0ropjY9",
+                                "type": "STRING",
+                            },
+                            "resOriginalHeight": {"value": 417, "type": "INT64"},
+                            "resOriginalWidth": {"value": 413, "type": "INT64"},
+                            "resOriginalFileType": {
+                                "value": "public.jpeg",
+                                "type": "STRING",
+                            },
+                            "resOriginalRes": {
+                                "value": {
+                                    "fileChecksum": "AQNND5zpteAXnnBP2BmDd0ropjY0",
+                                    "size": 340532,
+                                    "wrappingKey": "lxLQBw46n1nvea4s30UY+A==",
+                                    "referenceChecksum": "AV2Zh7WygJu74eNWVuuMT4lM8qme",
+                                    # pylint: disable=C0321
+                                    "downloadURL": "https://cvws.icloud-content.com/B/AQNND5zpteAXnnBP2BmDd0ropjY0AV2Zh7WygJu74eNWVuuMT4lM8qme/${f}?o=ArcD2SL9b5Gy5zcnrnT2luycDRZzFLjOiX-8u9IWdQM2&v=1&x=3&a=CAogfF6-sW-XhnsFDy-vqHQjR8LXVO4OmxBUqG4CZf1zmOwSbRC8kq2nty8YvO-IqbcvIgEAUgTopjY9WgRM8qmeaibiG79B2YhfcchV4W9EgxQXAN4Bpi57NX82WXqo_YW-xi1qLAH9-HImRd8oYhd7r27sXPkUL3GT-rKGSKG-leLeNevi3ay090liNNZH-2U&e=1629757781&fl=&r=4d5c62f6-c81b-4e60-a785-4139aad087a7-1&k=lxLQBw46n1nvea4s30UY-A&ckc=com.apple.photos.cloud&ckz=PrimarySync&y=1&p=104&s=34vgVK6vLEdlpYceHAmIfqIp1Fk",  # noqa: E501
+                                },
+                                "type": "ASSETID",
+                            },
+                        },
+                        "pluginFields": {},
+                        "recordChangeTag": "2wtv",
+                        "created": {
+                            "timestamp": 1574869225887,
+                            "userRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
+                            "deviceID": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23_1d5r3c201b3a4r5daac8ff7e7fbc0c24",
+                        },
+                        "modified": {
+                            "timestamp": 1595187513229,
+                            "userRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
+                            "deviceID": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23_1d5r3c201b3a4r5daac8ff7e7fbc0c24",
+                        },
+                        "deleted": False,
+                        "zoneID": {
+                            "zoneName": "PrimarySync",
+                            "ownerRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
+                            "zoneType": "REGULAR_CUSTOM_ZONE",
+                        },
+                    },
                     # Reference to IMG_3328.JPG
                     {
                         "recordName": "248AFAAE-062C-40BB-92C6-B47084527A9E",
@@ -1111,6 +1206,61 @@ DATA = {
                             "zoneType": "REGULAR_CUSTOM_ZONE",
                         },
                     },
+                    # Reference to IMG_3148.JPG from another device (actual IMG_3206.JPG)
+                    {
+                        "recordName": "97362090-90E4-4F54-A564-14F7ECC02707",
+                        "recordType": "CPLAsset",
+                        "fields": {
+                            "assetDate": {"value": 1574840964935, "type": "TIMESTAMP"},
+                            "orientation": {"value": 1, "type": "INT64"},
+                            "addedDate": {"value": 1574840964970, "type": "TIMESTAMP"},
+                            "assetSubtypeV2": {"value": 0, "type": "INT64"},
+                            "assetHDRType": {"value": 0, "type": "INT64"},
+                            "timeZoneOffset": {"value": 19800, "type": "INT64"},
+                            "masterRef": {
+                                "value": {
+                                    "recordName": "Ab/8kUAhnGzSxnl9yWvh8JKBpOvW",
+                                    "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": "2wtw",
+                        "created": {
+                            "timestamp": 1574869225891,
+                            "userRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
+                            "deviceID": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23_1d5r3c201b3a4r5daac8ff7e7fbc0c24",
+                        },
+                        "modified": {
+                            "timestamp": 1595187513229,
+                            "userRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
+                            "deviceID": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23_1d5r3c201b3a4r5daac8ff7e7fbc0c24",
+                        },
+                        "deleted": False,
+                        "zoneID": {
+                            "zoneName": "PrimarySync",
+                            "ownerRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
+                            "zoneType": "REGULAR_CUSTOM_ZONE",
+                        },
+                    },
                     # IMG_3328.JPG IN album 2
                     {
                         "recordName": "248AFAAE-062C-40BB-92C6-B47084527A9E-IN-E4RT4FB7-4A35-4958-1D42-5769E66BE407",
@@ -1286,6 +1436,41 @@ DATA = {
                             "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",
+                        "recordType": "CPLContainerRelation",
+                        "fields": {
+                            "itemId": {
+                                "value": "97362090-90E4-4F54-A564-14F7ECC02707",
+                                "type": "STRING",
+                            },
+                            "isKeyAsset": {"value": 0, "type": "INT64"},
+                            "position": {"value": 3072, "type": "INT64"},
+                            "containerId": {
+                                "value": "E4RT4FB7-4A35-4958-1D42-5769E66BE407",
+                                "type": "STRING",
+                            },
+                        },
+                        "pluginFields": {},
+                        "recordChangeTag": "3f4w",
+                        "created": {
+                            "timestamp": 1574869421700,
+                            "userRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
+                            "deviceID": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23_1d5r3c201b3a4r5daac8ff7e7fbc0c24",
+                        },
+                        "modified": {
+                            "timestamp": 1595190034254,
+                            "userRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
+                            "deviceID": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23_1d5r3c201b3a4r5daac8ff7e7fbc0c24",
+                        },
+                        "deleted": False,
+                        "zoneID": {
+                            "zoneName": "PrimarySync",
+                            "ownerRecordName": "_1d5r3c201b3a4r5daac8ff7e7fbc0c23",
+                            "zoneType": "REGULAR_CUSTOM_ZONE",
+                        },
+                    },
                 ],
                 "syncToken": "AQAAAAAAArKjf//////////fSxWSKv5JfZ34edrt875d",
             },
diff --git a/tests/test_sync_photos.py b/tests/test_sync_photos.py
index 7b8ac050..49bfd489 100644
--- a/tests/test_sync_photos.py
+++ b/tests/test_sync_photos.py
@@ -87,7 +87,12 @@ class TestSyncPhotos(unittest.TestCase):
         )
         sync_photos.sync_photos(config=config, photos=mock_service.photos)
 
-        os.remove(os.path.join(album_1_path, "IMG_3148.JPG"))
+        os.remove(
+            os.path.join(
+                album_1_path,
+                "IMG_3148__medium__QVZ4My9WS2tiV1BkTmJXdzY4bXJXelN1ZW1YZw==.JPG",
+            )
+        )
         # Download missing file
         with self.assertLogs() as captured:
             self.assertIsNone(
@@ -95,7 +100,15 @@ class TestSyncPhotos(unittest.TestCase):
             )
             self.assertTrue(len(captured.records) > 0)
             self.assertIsNotNone(
-                next((s for s in captured[1] if "album-1/IMG_3148.JPG ..." in s), None)
+                next(
+                    (
+                        s
+                        for s in captured[1]
+                        if "album-1/IMG_3148__medium__QVZ4My9WS2tiV1BkTmJXdzY4bXJXelN1ZW1YZw==.JPG ..."
+                        in s
+                    ),
+                    None,
+                )
             )
         self.assertTrue(os.path.isdir(album_0_path))
         self.assertTrue(os.path.isdir(album_1_path))
@@ -128,7 +141,12 @@ class TestSyncPhotos(unittest.TestCase):
         )
         sync_photos.sync_photos(config=config, photos=mock_service.photos)
         # Download changed file
-        os.remove(os.path.join(album_1_path, "IMG_3148.JPG"))
+        os.remove(
+            os.path.join(
+                album_1_path,
+                "IMG_3148__medium__QVZ4My9WS2tiV1BkTmJXdzY4bXJXelN1ZW1YZw==.JPG",
+            )
+        )
         shutil.copyfile(
             os.path.join(DATA_DIR, "thumb.jpeg"),
             os.path.join(album_1_path, "IMG_3148.JPG"),
@@ -139,7 +157,15 @@ class TestSyncPhotos(unittest.TestCase):
             )
             self.assertTrue(len(captured.records) > 0)
             self.assertIsNotNone(
-                next((s for s in captured[1] if "album-1/IMG_3148.JPG ..." in s), None)
+                next(
+                    (
+                        s
+                        for s in captured[1]
+                        if "album-1/IMG_3148__medium__QVZ4My9WS2tiV1BkTmJXdzY4bXJXelN1ZW1YZw==.JPG ..."
+                        in s
+                    ),
+                    None,
+                )
             )
         self.assertTrue(os.path.isdir(album_0_path))
         self.assertTrue(os.path.isdir(album_1_path))
@@ -202,7 +228,28 @@ class TestSyncPhotos(unittest.TestCase):
 
         # Rename previous original files - upgrade to newer version
         os.rename(
+            os.path.join(
+                album_1_path,
+                "IMG_3148__original__QVZ4My9WS2tiV1BkTmJXdzY4bXJXelN1ZW1YZw==.JPG",
+            ),
             os.path.join(album_1_path, "IMG_3148.JPG"),
+        )
+
+        with self.assertLogs(logger=LOGGER, level="DEBUG") as captured:
+            self.assertIsNone(
+                sync_photos.sync_photos(config=config, photos=mock_service.photos)
+            )
+            self.assertTrue(len(captured.records) > 0)
+            self.assertIsNone(
+                next((s for s in captured[1] if "Downloading /" in s), None)
+            )
+
+        # Rename previous __original files - upgrade to newer version
+        os.rename(
+            os.path.join(
+                album_1_path,
+                "IMG_3148__original__QVZ4My9WS2tiV1BkTmJXdzY4bXJXelN1ZW1YZw==.JPG",
+            ),
             os.path.join(album_1_path, "IMG_3148__original.JPG"),
         )
 
@@ -240,7 +287,15 @@ class TestSyncPhotos(unittest.TestCase):
             )
             self.assertTrue(len(captured.records) > 0)
             self.assertIsNotNone(
-                next((s for s in captured[1] if "all/IMG_3148.JPG ..." in s), None)
+                next(
+                    (
+                        s
+                        for s in captured[1]
+                        if "all/IMG_3148__original__QVZ4My9WS2tiV1BkTmJXdzY4bXJXelN1ZW1YZw==.JPG ..."
+                        in s
+                    ),
+                    None,
+                )
             )
 
         self.assertTrue(os.path.isdir(os.path.join(self.destination_path, "all")))
@@ -300,9 +355,13 @@ class TestSyncPhotos(unittest.TestCase):
         """Test if medium photo size is missing."""
 
         class MockPhoto:
+            @property
+            def id(self):
+                return "some-random-id"
+
             @property
             def filename(self):
-                return "filename"
+                return "filename.JPG"
 
             @property
             def versions(self):
@@ -320,9 +379,13 @@ class TestSyncPhotos(unittest.TestCase):
         """Test if thumbnail size is missing."""
 
         class MockPhoto:
+            @property
+            def id(self):
+                return "some-random-id"
+
             @property
             def filename(self):
-                return "filename"
+                return "filename.JPG"
 
             @property
             def versions(self):