[danbooru] add 'favgroup' extractor
This commit is contained in:
@@ -1886,12 +1886,14 @@ Description
|
|||||||
|
|
||||||
extractor.[Danbooru].pool.order-posts
|
extractor.[Danbooru].pool.order-posts
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
|
extractor.[Danbooru].favgroup.order-posts
|
||||||
|
-----------------------------------------
|
||||||
Type
|
Type
|
||||||
``string``
|
``string``
|
||||||
Default
|
Default
|
||||||
``"pool"``
|
``"pool"``
|
||||||
Description
|
Description
|
||||||
Controls the order in which pool posts are returned.
|
Controls the order in which ``pool``/``favgroup`` posts are returned.
|
||||||
|
|
||||||
``"pool"`` | ``"pool_asc"`` | ``"asc"`` | ``"asc_pool"``
|
``"pool"`` | ``"pool_asc"`` | ``"asc"`` | ``"asc_pool"``
|
||||||
Pool order
|
Pool order
|
||||||
|
|||||||
@@ -792,6 +792,9 @@
|
|||||||
"threshold": "auto",
|
"threshold": "auto",
|
||||||
"ugoira" : false,
|
"ugoira" : false,
|
||||||
|
|
||||||
|
"favgroup": {
|
||||||
|
"order-posts": "pool"
|
||||||
|
},
|
||||||
"pool": {
|
"pool": {
|
||||||
"order-posts": "pool"
|
"order-posts": "pool"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1190,25 +1190,25 @@ Consider all listed sites to potentially be NSFW.
|
|||||||
<tr>
|
<tr>
|
||||||
<td>Danbooru</td>
|
<td>Danbooru</td>
|
||||||
<td>https://danbooru.donmai.us/</td>
|
<td>https://danbooru.donmai.us/</td>
|
||||||
<td>Artists, Artist Searches, Pools, Popular Images, Posts, Tag Searches</td>
|
<td>Artists, Artist Searches, Favorite Groups, Pools, Popular Images, Posts, Tag Searches</td>
|
||||||
<td>Supported</td>
|
<td>Supported</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>ATFBooru</td>
|
<td>ATFBooru</td>
|
||||||
<td>https://booru.allthefallen.moe/</td>
|
<td>https://booru.allthefallen.moe/</td>
|
||||||
<td>Artists, Artist Searches, Pools, Popular Images, Posts, Tag Searches</td>
|
<td>Artists, Artist Searches, Favorite Groups, Pools, Popular Images, Posts, Tag Searches</td>
|
||||||
<td>Supported</td>
|
<td>Supported</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Aibooru</td>
|
<td>Aibooru</td>
|
||||||
<td>https://aibooru.online/</td>
|
<td>https://aibooru.online/</td>
|
||||||
<td>Artists, Artist Searches, Pools, Popular Images, Posts, Tag Searches</td>
|
<td>Artists, Artist Searches, Favorite Groups, Pools, Popular Images, Posts, Tag Searches</td>
|
||||||
<td>Supported</td>
|
<td>Supported</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Booruvar</td>
|
<td>Booruvar</td>
|
||||||
<td>https://booru.borvar.art/</td>
|
<td>https://booru.borvar.art/</td>
|
||||||
<td>Artists, Artist Searches, Pools, Popular Images, Posts, Tag Searches</td>
|
<td>Artists, Artist Searches, Favorite Groups, Pools, Popular Images, Posts, Tag Searches</td>
|
||||||
<td>Supported</td>
|
<td>Supported</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
|||||||
@@ -175,6 +175,51 @@ class DanbooruExtractor(BaseExtractor):
|
|||||||
return [{"file": fmt(index), "delay": delay}
|
return [{"file": fmt(index), "delay": delay}
|
||||||
for index, delay in enumerate(delays)]
|
for index, delay in enumerate(delays)]
|
||||||
|
|
||||||
|
def _collection_posts(self, cid, ctype):
|
||||||
|
reverse = prefix = None
|
||||||
|
|
||||||
|
order = self.config("order-posts")
|
||||||
|
if not order or order in {"asc", "pool", "pool_asc", "asc_pool"}:
|
||||||
|
params = {"tags": "ord{}:{}".format(ctype, cid)}
|
||||||
|
elif order in {"id", "desc_id", "id_desc"}:
|
||||||
|
params = {"tags": "{}:{}".format(ctype, cid)}
|
||||||
|
prefix = "b"
|
||||||
|
elif order in {"desc", "desc_pool", "pool_desc"}:
|
||||||
|
params = {"tags": "ord{}:{}".format(ctype, cid)}
|
||||||
|
reverse = True
|
||||||
|
elif order in {"asc_id", "id_asc"}:
|
||||||
|
params = {"tags": "{}:{}".format(ctype, cid)}
|
||||||
|
reverse = True
|
||||||
|
|
||||||
|
posts = self._pagination("/posts.json", params, prefix)
|
||||||
|
if reverse:
|
||||||
|
self.log.info("Collecting posts of %s %s", ctype, cid)
|
||||||
|
return self._collection_enumerate_reverse(posts)
|
||||||
|
else:
|
||||||
|
return self._collection_enumerate(posts)
|
||||||
|
|
||||||
|
def _collection_metadata(self, cid, ctype, cname=None):
|
||||||
|
url = "{}/{}s/{}.json".format(self.root, cname or ctype, cid)
|
||||||
|
collection = self.request(url).json()
|
||||||
|
collection["name"] = collection["name"].replace("_", " ")
|
||||||
|
self.post_ids = collection.pop("post_ids", ())
|
||||||
|
return {ctype: collection}
|
||||||
|
|
||||||
|
def _collection_enumerate(self, posts):
|
||||||
|
pid_to_num = {pid: num for num, pid in enumerate(self.post_ids, 1)}
|
||||||
|
for post in posts:
|
||||||
|
post["num"] = pid_to_num[post["id"]]
|
||||||
|
yield post
|
||||||
|
|
||||||
|
def _collection_enumerate_reverse(self, posts):
|
||||||
|
posts = list(posts)
|
||||||
|
posts.reverse()
|
||||||
|
|
||||||
|
pid_to_num = {pid: num for num, pid in enumerate(self.post_ids, 1)}
|
||||||
|
for post in posts:
|
||||||
|
post["num"] = pid_to_num[post["id"]]
|
||||||
|
return posts
|
||||||
|
|
||||||
|
|
||||||
BASE_PATTERN = DanbooruExtractor.update({
|
BASE_PATTERN = DanbooruExtractor.update({
|
||||||
"danbooru": {
|
"danbooru": {
|
||||||
@@ -228,7 +273,7 @@ class DanbooruTagExtractor(DanbooruExtractor):
|
|||||||
|
|
||||||
|
|
||||||
class DanbooruPoolExtractor(DanbooruExtractor):
|
class DanbooruPoolExtractor(DanbooruExtractor):
|
||||||
"""Extractor for posts from danbooru pools"""
|
"""Extractor for Danbooru pools"""
|
||||||
subcategory = "pool"
|
subcategory = "pool"
|
||||||
directory_fmt = ("{category}", "pool", "{pool[id]} {pool[name]}")
|
directory_fmt = ("{category}", "pool", "{pool[id]} {pool[name]}")
|
||||||
filename_fmt = "{num:>04}_{id}_{filename}.{extension}"
|
filename_fmt = "{num:>04}_{id}_{filename}.{extension}"
|
||||||
@@ -237,50 +282,28 @@ class DanbooruPoolExtractor(DanbooruExtractor):
|
|||||||
example = "https://danbooru.donmai.us/pools/12345"
|
example = "https://danbooru.donmai.us/pools/12345"
|
||||||
|
|
||||||
def metadata(self):
|
def metadata(self):
|
||||||
self.pool_id = self.groups[-1]
|
return self._collection_metadata(self.groups[-1], "pool")
|
||||||
url = "{}/pools/{}.json".format(self.root, self.pool_id)
|
|
||||||
pool = self.request(url).json()
|
|
||||||
pool["name"] = pool["name"].replace("_", " ")
|
|
||||||
self.post_ids = pool.pop("post_ids", ())
|
|
||||||
return {"pool": pool}
|
|
||||||
|
|
||||||
def posts(self):
|
def posts(self):
|
||||||
reverse = prefix = None
|
return self._collection_posts(self.groups[-1], "pool")
|
||||||
|
|
||||||
order = self.config("order-posts")
|
|
||||||
if not order or order in ("asc", "pool", "pool_asc", "asc_pool"):
|
|
||||||
params = {"tags": "ordpool:" + self.pool_id}
|
|
||||||
elif order in ("id", "desc_id", "id_desc"):
|
|
||||||
params = {"tags": "pool:" + self.pool_id}
|
|
||||||
prefix = "b"
|
|
||||||
elif order in ("desc", "desc_pool", "pool_desc"):
|
|
||||||
params = {"tags": "ordpool:" + self.pool_id}
|
|
||||||
reverse = True
|
|
||||||
elif order in ("asc_id", "id_asc"):
|
|
||||||
params = {"tags": "pool:" + self.pool_id}
|
|
||||||
reverse = True
|
|
||||||
|
|
||||||
posts = self._pagination("/posts.json", params, prefix)
|
class DanbooruFavgroupExtractor(DanbooruExtractor):
|
||||||
if reverse:
|
"""Extractor for Danbooru favorite groups"""
|
||||||
return self._enumerate_posts_reverse(posts)
|
subcategory = "favgroup"
|
||||||
else:
|
directory_fmt = ("{category}", "Favorite Groups",
|
||||||
return self._enumerate_posts(posts)
|
"{favgroup[id]} {favgroup[name]}")
|
||||||
|
filename_fmt = "{num:>04}_{id}_{filename}.{extension}"
|
||||||
|
archive_fmt = "fg_{favgroup[id]}_{id}"
|
||||||
|
pattern = BASE_PATTERN + r"/favorite_group(?:s|/show)/(\d+)"
|
||||||
|
example = "https://danbooru.donmai.us/favorite_groups/12345"
|
||||||
|
|
||||||
def _enumerate_posts(self, posts):
|
def metadata(self):
|
||||||
pid_to_num = {pid: num+1 for num, pid in enumerate(self.post_ids)}
|
return self._collection_metadata(
|
||||||
for post in posts:
|
self.groups[-1], "favgroup", "favorite_group")
|
||||||
post["num"] = pid_to_num[post["id"]]
|
|
||||||
yield post
|
|
||||||
|
|
||||||
def _enumerate_posts_reverse(self, posts):
|
def posts(self):
|
||||||
self.log.info("Collecting posts of pool %s", self.pool_id)
|
return self._collection_posts(self.groups[-1], "favgroup")
|
||||||
posts = list(posts)
|
|
||||||
posts.reverse()
|
|
||||||
|
|
||||||
pid_to_num = {pid: num+1 for num, pid in enumerate(self.post_ids)}
|
|
||||||
for post in posts:
|
|
||||||
post["num"] = pid_to_num[post["id"]]
|
|
||||||
return posts
|
|
||||||
|
|
||||||
|
|
||||||
class DanbooruPostExtractor(DanbooruExtractor):
|
class DanbooruPostExtractor(DanbooruExtractor):
|
||||||
|
|||||||
@@ -236,6 +236,7 @@ SUBCATEGORY_MAP = {
|
|||||||
},
|
},
|
||||||
"Danbooru": {
|
"Danbooru": {
|
||||||
"artist-search": "Artist Searches",
|
"artist-search": "Artist Searches",
|
||||||
|
"favgroup": "Favorite Groups",
|
||||||
},
|
},
|
||||||
"desktopography": {
|
"desktopography": {
|
||||||
"site": "",
|
"site": "",
|
||||||
|
|||||||
@@ -146,6 +146,23 @@ __tests__ = (
|
|||||||
"#class" : danbooru.DanbooruPoolExtractor,
|
"#class" : danbooru.DanbooruPoolExtractor,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"#url" : "https://danbooru.donmai.us/favorite_groups/14",
|
||||||
|
"#category": ("Danbooru", "danbooru", "favgroup"),
|
||||||
|
"#class" : danbooru.DanbooruFavgroupExtractor,
|
||||||
|
"#auth" : False,
|
||||||
|
"#count" : 24,
|
||||||
|
|
||||||
|
"favgroup": {
|
||||||
|
"created_at": "2015-06-29T13:59:10.808-04:00",
|
||||||
|
"creator_id": 65304,
|
||||||
|
"id" : 14,
|
||||||
|
"is_public" : True,
|
||||||
|
"name" : "Mecha",
|
||||||
|
"updated_at": "2019-07-07T07:21:50.677-04:00",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"#url" : "https://danbooru.donmai.us/posts/294929",
|
"#url" : "https://danbooru.donmai.us/posts/294929",
|
||||||
"#category": ("Danbooru", "danbooru", "post"),
|
"#category": ("Danbooru", "danbooru", "post"),
|
||||||
|
|||||||
Reference in New Issue
Block a user