Skip to content

Commit

Permalink
[patreon] make retrieving user info nonfatal (#508)
Browse files Browse the repository at this point in the history
… and fall back to the included data if an error occurs.
  • Loading branch information
mikf committed Dec 11, 2019
1 parent 964dc57 commit 9e63804
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions gallery_dl/extractor/patreon.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ def _process(self, post, included):
attr["attachments"] = self._files(post, included, "attachments")
attr["date"] = text.parse_datetime(
attr["published_at"], "%Y-%m-%dT%H:%M:%S.%f%z")
uid = post["relationships"]["user"]["data"]["id"]
attr["creator"] = included["user"][uid]
user = post["relationships"]["user"]
attr["creator"] = (
self._user(user["links"]["related"]) or
included["user"][user["data"]["id"]])
return attr

@staticmethod
Expand All @@ -123,7 +125,10 @@ def _files(post, included, key):
@memcache(keyarg=1)
def _user(self, url):
"""Fetch user information"""
user = self.request(url).json()["data"]
response = self.request(url, fatal=False)
if response.status_code >= 400:
return None
user = response.json()["data"]
attr = user["attributes"]
attr["id"] = user["id"]
attr["date"] = text.parse_datetime(
Expand Down
2 changes: 1 addition & 1 deletion test/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"exhentai", "kissmanga", "mangafox", "dynastyscans", "nijie", "bobx",
"archivedmoe", "archiveofsins", "thebarchive", "fireden", "4plebs",
"sankaku", "idolcomplex", "mangahere", "readcomiconline", "mangadex",
"sankakucomplex", "warosu", "fuskator", "patreon",
"sankakucomplex", "warosu", "fuskator",
}

# temporary issues, etc.
Expand Down

0 comments on commit 9e63804

Please sign in to comment.