[Danbooru] add 'random' extractor
Adds a new `DanbooruRandomExtractor` to support downloading from `danbooru.donmai.us/posts/random?tags=` URLs.
This commit is contained in:
@@ -1252,25 +1252,25 @@ Consider all listed sites to potentially be NSFW.
|
||||
<tr id="danbooru" title="danbooru">
|
||||
<td>Danbooru</td>
|
||||
<td>https://danbooru.donmai.us/</td>
|
||||
<td>Artists, Artist Searches, Favorite Groups, Pools, Popular Images, Posts, Tag Searches</td>
|
||||
<td>Artists, Artist Searches, Favorite Groups, Pools, Popular Images, Posts, Random Posts, Tag Searches</td>
|
||||
<td>Supported</td>
|
||||
</tr>
|
||||
<tr id="atfbooru" title="atfbooru">
|
||||
<td>ATFBooru</td>
|
||||
<td>https://booru.allthefallen.moe/</td>
|
||||
<td>Artists, Artist Searches, Favorite Groups, Pools, Popular Images, Posts, Tag Searches</td>
|
||||
<td>Artists, Artist Searches, Favorite Groups, Pools, Popular Images, Posts, Random Posts, Tag Searches</td>
|
||||
<td>Supported</td>
|
||||
</tr>
|
||||
<tr id="aibooru" title="aibooru">
|
||||
<td>AIBooru</td>
|
||||
<td>https://aibooru.online/</td>
|
||||
<td>Artists, Artist Searches, Favorite Groups, Pools, Popular Images, Posts, Tag Searches</td>
|
||||
<td>Artists, Artist Searches, Favorite Groups, Pools, Popular Images, Posts, Random Posts, Tag Searches</td>
|
||||
<td>Supported</td>
|
||||
</tr>
|
||||
<tr id="booruvar" title="booruvar">
|
||||
<td>Booruvar</td>
|
||||
<td>https://booru.borvar.art/</td>
|
||||
<td>Artists, Artist Searches, Favorite Groups, Pools, Popular Images, Posts, Tag Searches</td>
|
||||
<td>Artists, Artist Searches, Favorite Groups, Pools, Popular Images, Posts, Random Posts, Tag Searches</td>
|
||||
<td>Supported</td>
|
||||
</tr>
|
||||
|
||||
|
||||
@@ -278,6 +278,23 @@ class DanbooruTagExtractor(DanbooruExtractor):
|
||||
return self._pagination("/posts.json", {"tags": self.tags}, prefix)
|
||||
|
||||
|
||||
class DanbooruRandomExtractor(DanbooruTagExtractor):
|
||||
"""Extractor for a random danbooru post"""
|
||||
subcategory = "random"
|
||||
pattern = BASE_PATTERN + r"/posts/random(?:\?(?:[^&#]*&)*tags=([^&#]*))?"
|
||||
example = "https://danbooru.donmai.us/posts/random?tags=TAG"
|
||||
|
||||
def metadata(self):
|
||||
tags = self.groups[-1] or ""
|
||||
self.tags = text.unquote(tags.replace("+", " "))
|
||||
return {"search_tags": self.tags}
|
||||
|
||||
def posts(self):
|
||||
posts = self.request_json(self.root + "/posts/random.json",
|
||||
params={"tags": self.tags or None})
|
||||
return (posts,) if isinstance(posts, dict) else posts
|
||||
|
||||
|
||||
class DanbooruPoolExtractor(DanbooruExtractor):
|
||||
"""Extractor for Danbooru pools"""
|
||||
subcategory = "pool"
|
||||
|
||||
@@ -264,6 +264,7 @@ SUBCATEGORY_MAP = {
|
||||
},
|
||||
"Danbooru": {
|
||||
"favgroup": "Favorite Groups",
|
||||
"random" : "Random Posts",
|
||||
},
|
||||
"desktopography": {
|
||||
"site": "",
|
||||
|
||||
@@ -80,4 +80,24 @@ __tests__ = (
|
||||
"#class" : danbooru.DanbooruPopularExtractor,
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://aibooru.online/posts/random?tags=center_frills&z=1",
|
||||
"#category": ("Danbooru", "aibooru", "random"),
|
||||
"#class" : danbooru.DanbooruRandomExtractor,
|
||||
"#pattern" : "https://cdn.aibooru.download/original/.+",
|
||||
"#count" : 1,
|
||||
|
||||
"search_tags": "center_frills",
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://aibooru.online/posts/random",
|
||||
"#category": ("Danbooru", "aibooru", "random"),
|
||||
"#class" : danbooru.DanbooruRandomExtractor,
|
||||
"#pattern" : "https://cdn.aibooru.download/original/.+",
|
||||
"#count" : 1,
|
||||
|
||||
"search_tags": "",
|
||||
},
|
||||
|
||||
)
|
||||
|
||||
@@ -36,4 +36,16 @@ __tests__ = (
|
||||
"#class" : danbooru.DanbooruPopularExtractor,
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://booru.allthefallen.moe/posts/random?tags=yume_shokunin",
|
||||
"#category": ("Danbooru", "atfbooru", "random"),
|
||||
"#class" : danbooru.DanbooruRandomExtractor,
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://booru.allthefallen.moe/posts/random",
|
||||
"#category": ("Danbooru", "atfbooru", "random"),
|
||||
"#class" : danbooru.DanbooruRandomExtractor,
|
||||
},
|
||||
|
||||
)
|
||||
|
||||
@@ -37,4 +37,16 @@ __tests__ = (
|
||||
"#class" : danbooru.DanbooruPopularExtractor,
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://booru.borvar.art/posts/random?tags=chibi&z=1",
|
||||
"#category": ("Danbooru", "booruvar", "random"),
|
||||
"#class" : danbooru.DanbooruRandomExtractor,
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://booru.borvar.art/posts/random",
|
||||
"#category": ("Danbooru", "booruvar", "random"),
|
||||
"#class" : danbooru.DanbooruRandomExtractor,
|
||||
},
|
||||
|
||||
)
|
||||
|
||||
@@ -382,4 +382,24 @@ __tests__ = (
|
||||
"other_names": list,
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://danbooru.donmai.us/posts/random?tags=bonocho",
|
||||
"#category": ("Danbooru", "danbooru", "random"),
|
||||
"#class" : danbooru.DanbooruRandomExtractor,
|
||||
"#pattern" : "https://cdn.donmai.us/original/.+",
|
||||
"#count" : 1,
|
||||
|
||||
"search_tags": "bonocho",
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://danbooru.donmai.us/posts/random",
|
||||
"#category": ("Danbooru", "danbooru", "random"),
|
||||
"#class" : danbooru.DanbooruRandomExtractor,
|
||||
"#pattern" : "https://cdn.donmai.us/original/.+",
|
||||
"#count" : 1,
|
||||
|
||||
"search_tags": "",
|
||||
},
|
||||
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user