Skip to content

Commit

Permalink
[patreon] small fixes and adjustments (#226)
Browse files Browse the repository at this point in the history
- fix datetime parsing
- rename 'user' to 'creator'
- convert 'id' to integer
- improve tests
  • Loading branch information
mikf committed May 17, 2019
1 parent fb09dd9 commit ca3bad1
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions gallery_dl/extractor/patreon.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ class PatreonExtractor(Extractor):
"""Base class for patreon extractors"""
category = "patreon"
root = "https://www.patreon.com"
directory_fmt = ("{category}", "{user[full_name]}")
directory_fmt = ("{category}", "{creator[full_name]}")
filename_fmt = "{id}_{title}_{num:>02}.{extension}"
archive_fmt = "{id}_{num}"
_warning = True

def items(self):
yield Message.Version, 1

if self._warning and "session_id" not in self.session.cookies:
self.log.warning("no 'session_id' cookie set")
if self._warning:
if "session_id" not in self.session.cookies:
self.log.warning("no 'session_id' cookie set")
PatreonExtractor._warning = False

for post in self.posts():
Expand Down Expand Up @@ -73,9 +74,10 @@ def _pagination(self, url):
# update posts
for post in posts["data"]:
attr = post["attributes"]
attr["id"] = post["id"]
attr["date"] = text.parse_timestamp(attr["published_at"])
attr["user"] = self._user(
attr["id"] = text.parse_int(post["id"])
attr["date"] = text.parse_datetime(
attr["published_at"], "%Y-%m-%dT%H:%M:%S.%f%z")
attr["creator"] = self._user(
post["relationships"]["user"]["links"]["related"])

# add attachments to post attributes
Expand All @@ -99,6 +101,8 @@ def _user(self, url):
user = self.request(url).json()["data"]
attr = user["attributes"]
attr["id"] = user["id"]
attr["date"] = text.parse_datetime(
attr["created"], "%Y-%m-%dT%H:%M:%S.%f%z")
return attr

@staticmethod
Expand Down Expand Up @@ -134,6 +138,18 @@ class PatreonCreatorExtractor(PatreonExtractor):
test = ("https://www.patreon.com/koveliana", {
"range": "1-25",
"count": ">= 25",
"keyword": {
"attachments": list,
"comment_count": int,
"content": str,
"creator": dict,
"date": "type:datetime",
"id": int,
"like_count": int,
"post_type": str,
"published_at": str,
"title": str,
},
})

def __init__(self, match):
Expand Down

0 comments on commit ca3bad1

Please sign in to comment.