[e621] return pool posts in order (closes #1195)
… and add a 'num' enumeration index. A bit more code than the PR version, but it prints some helpful messages and doesn't call 'metadata()' twice.
This commit is contained in:
parent
e7d446a8f7
commit
d781e6ac44
@ -146,12 +146,13 @@ class DanbooruPoolExtractor(DanbooruExtractor):
|
|||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
super().__init__(match)
|
super().__init__(match)
|
||||||
self.pool_id = match.group(2)
|
self.pool_id = match.group(2)
|
||||||
|
self.post_ids = ()
|
||||||
|
|
||||||
def metadata(self):
|
def metadata(self):
|
||||||
url = "{}/pools/{}.json".format(self.root, self.pool_id)
|
url = "{}/pools/{}.json".format(self.root, self.pool_id)
|
||||||
pool = self.request(url).json()
|
pool = self.request(url).json()
|
||||||
pool["name"] = pool["name"].replace("_", " ")
|
pool["name"] = pool["name"].replace("_", " ")
|
||||||
del pool["post_ids"]
|
self.post_ids = pool.pop("post_ids")
|
||||||
return {"pool": pool}
|
return {"pool": pool}
|
||||||
|
|
||||||
def posts(self):
|
def posts(self):
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
from .common import Extractor, Message
|
from .common import Extractor, Message
|
||||||
from . import danbooru
|
from . import danbooru
|
||||||
|
|
||||||
|
|
||||||
BASE_PATTERN = r"(?:https?://)?e(621|926)\.net"
|
BASE_PATTERN = r"(?:https?://)?e(621|926)\.net"
|
||||||
|
|
||||||
|
|
||||||
@ -39,9 +38,9 @@ class E621Extractor(danbooru.DanbooruExtractor):
|
|||||||
file = post["file"]
|
file = post["file"]
|
||||||
|
|
||||||
if not file["url"]:
|
if not file["url"]:
|
||||||
ihash = file["md5"]
|
md5 = file["md5"]
|
||||||
file["url"] = "https://static1.{}/data/{}/{}/{}.{}".format(
|
file["url"] = "https://static1.{}/data/{}/{}/{}.{}".format(
|
||||||
self.root[8:], ihash[0:2], ihash[2:4], ihash, file["ext"])
|
self.root[8:], md5[0:2], md5[2:4], md5, file["ext"])
|
||||||
|
|
||||||
post["filename"] = file["md5"]
|
post["filename"] = file["md5"]
|
||||||
post["extension"] = file["ext"]
|
post["extension"] = file["ext"]
|
||||||
@ -69,12 +68,33 @@ class E621PoolExtractor(E621Extractor, danbooru.DanbooruPoolExtractor):
|
|||||||
pattern = BASE_PATTERN + r"/pool(?:s|/show)/(\d+)"
|
pattern = BASE_PATTERN + r"/pool(?:s|/show)/(\d+)"
|
||||||
test = (
|
test = (
|
||||||
("https://e621.net/pools/73", {
|
("https://e621.net/pools/73", {
|
||||||
"url": "842f2fb065c7c339486a9b1d689020b8569888ed",
|
"url": "1bd09a72715286a79eea3b7f09f51b3493eb579a",
|
||||||
"content": "c2c87b7a9150509496cddc75ccab08109922876a",
|
"content": "91abe5d5334425d9787811d7f06d34c77974cd22",
|
||||||
}),
|
}),
|
||||||
("https://e621.net/pool/show/73"),
|
("https://e621.net/pool/show/73"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def posts(self):
|
||||||
|
self.log.info("Fetching posts of pool %s", self.pool_id)
|
||||||
|
|
||||||
|
id_to_post = {
|
||||||
|
post["id"]: post
|
||||||
|
for post in self._pagination(
|
||||||
|
"/posts.json", {"tags": "pool:" + self.pool_id})
|
||||||
|
}
|
||||||
|
|
||||||
|
posts = []
|
||||||
|
append = posts.append
|
||||||
|
for num, pid in enumerate(self.post_ids, 1):
|
||||||
|
if pid in id_to_post:
|
||||||
|
post = id_to_post[pid]
|
||||||
|
post["num"] = num
|
||||||
|
append(post)
|
||||||
|
else:
|
||||||
|
self.log.warning("Post %s is unavailable", pid)
|
||||||
|
|
||||||
|
return posts
|
||||||
|
|
||||||
|
|
||||||
class E621PostExtractor(E621Extractor, danbooru.DanbooruPostExtractor):
|
class E621PostExtractor(E621Extractor, danbooru.DanbooruPostExtractor):
|
||||||
"""Extractor for single e621 posts"""
|
"""Extractor for single e621 posts"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user