1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 18:53:21 +01:00

merge #6001: [e621] cache pool metadata API calls

This commit is contained in:
Mike Fährmann 2024-08-12 18:04:52 +02:00
commit 54e1023046
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

View File

@ -10,6 +10,7 @@
from .common import Message from .common import Message
from . import danbooru from . import danbooru
from ..cache import memcache
from .. import text, util from .. import text, util
@ -44,16 +45,11 @@ class E621Extractor(danbooru.DanbooruExtractor):
self.root[8:], md5[0:2], md5[2:4], md5, file["ext"]) self.root[8:], md5[0:2], md5[2:4], md5, file["ext"])
if notes and post.get("has_notes"): if notes and post.get("has_notes"):
url = "{}/notes.json?search[post_id]={}".format( post["notes"] = self._get_notes(post["id"])
self.root, post["id"])
post["notes"] = self.request(url).json()
if pools and post["pools"]: if pools and post["pools"]:
url = "{}/pools.json?search[id]={}".format( post["pools"] = self._get_pools(
self.root, ",".join(map(str, post["pools"]))) ",".join(map(str, post["pools"])))
post["pools"] = _pools = self.request(url).json()
for pool in _pools:
pool["name"] = pool["name"].replace("_", " ")
post["filename"] = file["md5"] post["filename"] = file["md5"]
post["extension"] = file["ext"] post["extension"] = file["ext"]
@ -64,6 +60,18 @@ class E621Extractor(danbooru.DanbooruExtractor):
yield Message.Directory, post yield Message.Directory, post
yield Message.Url, file["url"], post yield Message.Url, file["url"], post
def _get_notes(self, id):
return self.request(
"{}/notes.json?search[post_id]={}".format(self.root, id)).json()
@memcache(keyarg=1)
def _get_pools(self, ids):
pools = self.request(
"{}/pools.json?search[id]={}".format(self.root, ids)).json()
for pool in pools:
pool["name"] = pool["name"].replace("_", " ")
return pools
BASE_PATTERN = E621Extractor.update({ BASE_PATTERN = E621Extractor.update({
"e621": { "e621": {