From e34fa05202a4f24be067d0076f50e49a05e9df67 Mon Sep 17 00:00:00 2001 From: patrickkfkan Date: Mon, 8 Jan 2024 16:15:08 +0800 Subject: [PATCH 1/2] 500px: fallback when extended photo info missing --- gallery_dl/extractor/500px.py | 40 ++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/gallery_dl/extractor/500px.py b/gallery_dl/extractor/500px.py index 41cc0debfe..c665bcb41f 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 From 264fdb85b23fcfd67ca2d3dc9347758339182c7a Mon Sep 17 00:00:00 2001 From: patrickkfkan Date: Mon, 8 Jan 2024 16:50:05 +0800 Subject: [PATCH 2/2] Lint --- gallery_dl/extractor/500px.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gallery_dl/extractor/500px.py b/gallery_dl/extractor/500px.py index c665bcb41f..2b9e909c4d 100644 --- a/gallery_dl/extractor/500px.py +++ b/gallery_dl/extractor/500px.py @@ -79,7 +79,7 @@ def _extend(self, edges): result.append(fallbacks[pid]) else: self.log.warning("Unable to fetch photo %s", pid) - + return result def _request_api(self, url, params):