1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 10:42:34 +01:00

[patreon] raise proper exception if creator/post doesn't exist

This commit is contained in:
Mike Fährmann 2019-12-12 01:14:32 +01:00
parent 9e63804347
commit 76e60d10a6
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

View File

@ -9,7 +9,7 @@
"""Extractors for https://www.patreon.com/"""
from .common import Extractor, Message
from .. import text
from .. import text, exception
from ..cache import memcache
import collections
import json
@ -173,23 +173,28 @@ class PatreonCreatorExtractor(PatreonExtractor):
pattern = (r"(?:https?://)?(?:www\.)?patreon\.com"
r"/(?!(?:home|join|posts|login|signup)(?:$|[/?&#]))"
r"([^/?&#]+)/?")
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,
"images": list,
"like_count": int,
"post_type": str,
"published_at": str,
"title": str,
},
})
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,
"images" : list,
"like_count" : int,
"post_type" : str,
"published_at" : str,
"title" : str,
},
}),
("https://www.patreon.com/kovelianot", {
"exception": exception.NotFoundError,
}),
)
def __init__(self, match):
PatreonExtractor.__init__(self, match)
@ -197,9 +202,12 @@ class PatreonCreatorExtractor(PatreonExtractor):
def posts(self):
url = "{}/{}".format(self.root, self.creator)
page = self.request(url).text
page = self.request(url, notfound="creator").text
campaign_id = text.extract(page, "/campaign/", "/")[0]
if not campaign_id:
raise exception.NotFoundError("creator")
url = self._build_url("posts", (
"&sort=-published_at"
"&filter[is_draft]=false"
@ -228,9 +236,14 @@ class PatreonPostExtractor(PatreonExtractor):
subcategory = "post"
pattern = (r"(?:https?://)?(?:www\.)?patreon\.com"
r"/posts/[^/?&#]*?(\d+)")
test = ("https://www.patreon.com/posts/precious-metal-23563293", {
"count": 4,
})
test = (
("https://www.patreon.com/posts/precious-metal-23563293", {
"count": 4,
}),
("https://www.patreon.com/posts/not-found-123", {
"exception": exception.NotFoundError,
}),
)
def __init__(self, match):
PatreonExtractor.__init__(self, match)
@ -238,7 +251,7 @@ class PatreonPostExtractor(PatreonExtractor):
def posts(self):
url = "{}/posts/{}".format(self.root, self.post_id)
page = self.request(url).text
page = self.request(url, notfound="post").text
data = text.extract(page, "window.patreon.bootstrap,", "\n});")[0]
post = json.loads(data + "}")["post"]