[danbooru] use alternate subdomains; support safebooru
This commit is contained in:
@@ -11,32 +11,43 @@
|
||||
from . import booru
|
||||
|
||||
|
||||
BASE_PATTERN = (
|
||||
r"(?:https?://)?"
|
||||
r"(?P<subdomain>danbooru|hijiribe|sonohara|safebooru)"
|
||||
r"\.donmai\.us")
|
||||
|
||||
|
||||
class DanbooruExtractor(booru.JsonParserMixin,
|
||||
booru.DanbooruPageMixin,
|
||||
booru.BooruExtractor):
|
||||
"""Base class for danbooru extractors"""
|
||||
category = "danbooru"
|
||||
api_url = "https://danbooru.donmai.us/posts.json"
|
||||
page_limit = 1000
|
||||
|
||||
def __init__(self, match):
|
||||
super().__init__(match)
|
||||
self.subdomain = match.group("subdomain")
|
||||
self.scheme = "https" if self.subdomain == "danbooru" else "http"
|
||||
self.api_url = "{scheme}://{subdomain}.donmai.us/posts.json".format(
|
||||
scheme=self.scheme, subdomain=self.subdomain)
|
||||
|
||||
|
||||
class DanbooruTagExtractor(booru.TagMixin, DanbooruExtractor):
|
||||
"""Extractor for images from danbooru based on search-tags"""
|
||||
pattern = [r"(?:https?://)?(?:danbooru|hijiribe|sonohara)\.donmai\.us"
|
||||
r"/posts\?(?:[^&#]*&)*tags=(?P<tags>[^&#]+)"]
|
||||
pattern = [BASE_PATTERN + r"/posts\?(?:[^&#]*&)*tags=(?P<tags>[^&#]+)"]
|
||||
test = [
|
||||
("https://danbooru.donmai.us/posts?tags=bonocho", {
|
||||
"content": "b196fb9f1668109d7774a0a82efea3ffdda07746",
|
||||
}),
|
||||
("https://hijiribe.donmai.us/posts?tags=bonocho", None),
|
||||
("https://sonohara.donmai.us/posts?tags=bonocho", None),
|
||||
("https://safebooru.donmai.us/posts?tags=bonocho", None),
|
||||
]
|
||||
|
||||
|
||||
class DanbooruPoolExtractor(booru.PoolMixin, DanbooruExtractor):
|
||||
"""Extractor for image-pools from danbooru"""
|
||||
pattern = [r"(?:https?://)?(?:danbooru|hijiribe|sonohara)\.donmai\.us"
|
||||
r"/pools/(?P<pool>\d+)"]
|
||||
pattern = [BASE_PATTERN + r"/pools/(?P<pool>\d+)"]
|
||||
test = [("https://danbooru.donmai.us/pools/7659", {
|
||||
"content": "b16bab12bea5f7ea9e0a836bf8045f280e113d99",
|
||||
})]
|
||||
@@ -44,8 +55,7 @@ class DanbooruPoolExtractor(booru.PoolMixin, DanbooruExtractor):
|
||||
|
||||
class DanbooruPostExtractor(booru.PostMixin, DanbooruExtractor):
|
||||
"""Extractor for single images from danbooru"""
|
||||
pattern = [r"(?:https?://)?(?:danbooru|hijiribe|sonohara)\.donmai\.us"
|
||||
r"/posts/(?P<post>\d+)"]
|
||||
pattern = [BASE_PATTERN + "/posts/(?P<post>\d+)"]
|
||||
test = [("https://danbooru.donmai.us/posts/294929", {
|
||||
"content": "5e255713cbf0a8e0801dc423563c34d896bb9229",
|
||||
})]
|
||||
@@ -53,8 +63,7 @@ class DanbooruPostExtractor(booru.PostMixin, DanbooruExtractor):
|
||||
|
||||
class DanbooruPopularExtractor(booru.PopularMixin, DanbooruExtractor):
|
||||
"""Extractor for popular images from danbooru"""
|
||||
pattern = [r"(?:https?://)?(?:danbooru|hijiribe|sonohara)\.donmai\.us"
|
||||
r"/explore/posts/popular(?:\?(?P<query>[^#]*))?"]
|
||||
pattern = [BASE_PATTERN + r"/explore/posts/popular(?:\?(?P<query>[^#]*))?"]
|
||||
test = [
|
||||
("https://danbooru.donmai.us/explore/posts/popular", None),
|
||||
(("https://danbooru.donmai.us/explore/posts/popular"
|
||||
@@ -62,4 +71,9 @@ class DanbooruPopularExtractor(booru.PopularMixin, DanbooruExtractor):
|
||||
"count": 20,
|
||||
}),
|
||||
]
|
||||
api_url = "https://danbooru.donmai.us/explore/posts/popular.json"
|
||||
|
||||
def __init__(self, match):
|
||||
super().__init__(match)
|
||||
urlfmt = "{scheme}://{subdomain}.donmai.us/explore/posts/popular.json"
|
||||
self.api_url = urlfmt.format(
|
||||
scheme=self.scheme, subdomain=self.subdomain)
|
||||
|
||||
Reference in New Issue
Block a user