diff --git a/gallery_dl/extractor/500px.py b/gallery_dl/extractor/500px.py index 41cc0debfe..2b9e909c4d 100644 --- a/gallery_dl/extractor/500px.py +++ b/gallery_dl/extractor/500px.py @@ -28,7 +28,7 @@ def items(self): for photo in self.photos(): url = photo["images"][-1]["url"] - photo["extension"] = photo["image_format"] + photo["extension"] = photo["image_format"] if "image_format" in photo else None if data: photo.update(data) yield Message.Directory, photo @@ -42,7 +42,17 @@ def photos(self): def _extend(self, edges): """Extend photos with additional metadata and higher resolution URLs""" - ids = [str(edge["node"]["legacyId"]) for edge in edges] + + """Sometimes v1 API does not return all the requested photos, so keep edges + data as fallback (mapped by legacyId for easy retrieval)""" + fallbacks = {} + for edge in edges: + id = str(edge["node"]["legacyId"]) + fallbacks[id] = edge["node"] + """Replace v2 ID with legacyId to keep filenames consistent""" + fallbacks[id]["id"] = id + + ids = list(fallbacks.keys()) url = "https://api.500px.com/v1/photos" params = { @@ -60,11 +70,17 @@ def _extend(self, edges): } photos = self._request_api(url, params)["photos"] - return [ - photos[pid] for pid in ids - if pid in photos or - self.log.warning("Unable to fetch photo %s", pid) - ] + + result = list() + for pid in ids: + if pid in photos: + result.append(photos[pid]) + elif "images" in fallbacks[pid]: + result.append(fallbacks[pid]) + else: + self.log.warning("Unable to fetch photo %s", pid) + + return result def _request_api(self, url, params): headers = { @@ -415,7 +431,7 @@ def photos(self): buttonName externalUrl cover { - images(sizes: [35, 33]) { + images(sizes: [33, 35]) { size webpUrl jpegUrl @@ -453,7 +469,7 @@ def photos(self): id } cover { - images(sizes: [33, 32, 36, 2048]) { + images(sizes: [32, 33, 36, 2048]) { url size webpUrl @@ -498,7 +514,7 @@ def photos(self): isFollowedByMe } } - images(sizes: [33, 32]) { + images(sizes: [32, 33, 35]) { size url webpUrl @@ -540,7 +556,7 @@ def photos(self): id } cover { - images(sizes: [33, 32, 36, 2048]) { + images(sizes: [32, 33, 36, 2048]) { url size webpUrl @@ -585,7 +601,7 @@ def photos(self): isFollowedByMe } } - images(sizes: [33, 32]) { + images(sizes: [32, 33, 35]) { size url webpUrl