NicholasDawson / ArchiverForGooglePhotos

A tool to maintain an archive/mirror of your Google Photos library for backup purposes.
GNU General Public License v3.0
190 stars 30 forks source link

🐛 Fix issue where 'mediaItems' is missing from request #8

Closed Snuggle closed 3 years ago

Snuggle commented 3 years ago

Very small fix, only add mediaItems to the list if they actually exist.

This exception is caused by a request looking like below, missing the mediaItems but still having a nextPageToken:

>>> print(request)
{'nextPageToken': 'abcabc'}
>>> media_items_list += request["mediaItems"]

Traceback (most recent call last):
  File "/Volumes/Homesweet/GooglePhotoArchiver/gparch_cli.py", line 127, in <module>
    account.download_library()
  File "/Volumes/Homesweet/GooglePhotoArchiver/gparch.py", line 281, in download_library
    items = self.process_media_items(self.list_media_items(), self.lib_dir)
  File "/Volumes/Homesweet/GooglePhotoArchiver/gparch.py", line 356, in list_media_items
    media_items_list += request["mediaItems"]
KeyError: 'mediaItems'

Fixes #6

Snuggle commented 3 years ago

@NicholasDawson - I have tested with your new debug mode, I have up to media235.json when downloading my entire library of 14,000 images, with the final JSON being a blank {} and the batch that causes my issue (#6) is in media224.json. Not sure why that batch specifically. All other media*.json files have a mediaItems key present.

Screenshots

Unusual batches

image

File listing

image
NicholasDawson commented 3 years ago

Thanks so much for the fix! Works great.

Your efforts will be greatly appreciated by the community!