[patreon] respect filters and sort order in query params (#711)
This commit is contained in:
@@ -205,7 +205,7 @@ class PatreonCreatorExtractor(PatreonExtractor):
|
|||||||
subcategory = "creator"
|
subcategory = "creator"
|
||||||
pattern = (r"(?:https?://)?(?:www\.)?patreon\.com"
|
pattern = (r"(?:https?://)?(?:www\.)?patreon\.com"
|
||||||
r"/(?!(?:home|join|posts|login|signup)(?:$|[/?&#]))"
|
r"/(?!(?:home|join|posts|login|signup)(?:$|[/?&#]))"
|
||||||
r"(?:user(?:/posts)?/?\?([^#]+)|([^/?&#]+)/?)")
|
r"([^/?&#]+)(?:/posts)?/?(?:\?([^#]+))?")
|
||||||
test = (
|
test = (
|
||||||
("https://www.patreon.com/koveliana", {
|
("https://www.patreon.com/koveliana", {
|
||||||
"range": "1-25",
|
"range": "1-25",
|
||||||
@@ -224,6 +224,10 @@ class PatreonCreatorExtractor(PatreonExtractor):
|
|||||||
"title" : str,
|
"title" : str,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
("https://www.patreon.com/koveliana/posts?filters[month]=2020-3", {
|
||||||
|
"count": 1,
|
||||||
|
"keyword": {"date": "dt:2020-03-30 21:21:44"},
|
||||||
|
}),
|
||||||
("https://www.patreon.com/kovelianot", {
|
("https://www.patreon.com/kovelianot", {
|
||||||
"exception": exception.NotFoundError,
|
"exception": exception.NotFoundError,
|
||||||
}),
|
}),
|
||||||
@@ -233,26 +237,33 @@ class PatreonCreatorExtractor(PatreonExtractor):
|
|||||||
|
|
||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
PatreonExtractor.__init__(self, match)
|
PatreonExtractor.__init__(self, match)
|
||||||
self.query, self.creator = match.groups()
|
self.creator, self.query = match.groups()
|
||||||
|
|
||||||
def posts(self):
|
def posts(self):
|
||||||
if self.creator:
|
query = text.parse_query(self.query)
|
||||||
url = "{}/{}".format(self.root, self.creator.lower())
|
|
||||||
|
creator_id = query.get("u")
|
||||||
|
if creator_id:
|
||||||
|
url = "{}/user?u={}".format(self.root, creator_id)
|
||||||
else:
|
else:
|
||||||
query = text.parse_query(self.query)
|
url = "{}/{}".format(self.root, self.creator.lower())
|
||||||
url = "{}/user?u={}".format(self.root, query.get("u"))
|
|
||||||
|
|
||||||
page = self.request(url, notfound="creator").text
|
page = self.request(url, notfound="creator").text
|
||||||
campaign_id = text.extract(page, "/campaign/", "/")[0]
|
campaign_id = text.extract(page, "/campaign/", "/")[0]
|
||||||
|
|
||||||
if not campaign_id:
|
if not campaign_id:
|
||||||
raise exception.NotFoundError("creator")
|
raise exception.NotFoundError("creator")
|
||||||
|
|
||||||
|
filters = "".join(
|
||||||
|
"&filter[{}={}".format(key[8:], text.escape(value))
|
||||||
|
for key, value in query.items()
|
||||||
|
if key.startswith("filters[")
|
||||||
|
)
|
||||||
|
|
||||||
url = self._build_url("posts", (
|
url = self._build_url("posts", (
|
||||||
"&sort=-published_at"
|
"&sort=" + query.get("sort", "-published_at") +
|
||||||
"&filter[is_draft]=false"
|
"&filter[is_draft]=false"
|
||||||
"&filter[contains_exclusive_posts]=true"
|
"&filter[contains_exclusive_posts]=true"
|
||||||
"&filter[campaign_id]=" + campaign_id
|
"&filter[campaign_id]=" + campaign_id + filters
|
||||||
))
|
))
|
||||||
return self._pagination(url)
|
return self._pagination(url)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user