Skip to content

Commit

Permalink
[500px] skip unavailable photos (#1335)
Browse files Browse the repository at this point in the history
instead of crashing with a KeyError exception
  • Loading branch information
mikf committed Mar 4, 2021
1 parent 6cfc961 commit 9785c55
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions gallery_dl/extractor/500px.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ 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]

url = "https://api.500px.com/v1/photos"
params = {
"expanded_user_info" : "true",
Expand All @@ -62,14 +64,14 @@ def _extend(self, edges):
"liked_by" : "1",
"following_sample" : "100",
"image_size" : "4096",
"ids" : ",".join(
str(edge["node"]["legacyId"]) for edge in edges),
"ids" : ",".join(ids),
}

data = self._request_api(url, params)["photos"]
photos = self._request_api(url, params)["photos"]
return [
data[str(edge["node"]["legacyId"])]
for edge in edges
photos[pid] for pid in ids
if pid in photos or
self.log.warning("Unable to fetch photo %s", pid)
]

def _request_api(self, url, params, csrf_token=None):
Expand Down Expand Up @@ -142,6 +144,10 @@ class _500pxGalleryExtractor(_500pxExtractor):
"user": dict,
},
}),
# unavailable photos (#1335)
("https://500px.com/p/Light_Expression_Photography/galleries/street", {
"count": 0,
}),
("https://500px.com/fashvamp/galleries/lera"),
)

Expand Down

0 comments on commit 9785c55

Please sign in to comment.