[gelbooru_v02] extract 'total' / 'search_count' metadata (#7689)

This commit is contained in:
Mike Fährmann
2025-06-19 19:09:21 +02:00
parent fcd1b8a155
commit 4279928d0b
3 changed files with 23 additions and 8 deletions

View File

@@ -47,7 +47,9 @@ class GelbooruV02Extractor(booru.BooruExtractor):
if total is None:
try:
total = int(root.attrib["count"])
self.kwdict["total"] = total = int(root.attrib["count"])
if "search_tags" in self.kwdict:
self.kwdict["search_count"] = total
self.log.debug("%s posts in total", total)
except Exception as exc:
total = 0
@@ -161,14 +163,13 @@ class GelbooruV02TagExtractor(GelbooruV02Extractor):
pattern = BASE_PATTERN + r"/index\.php\?page=post&s=list&tags=([^&#]*)"
example = "https://safebooru.org/index.php?page=post&s=list&tags=TAG"
def metadata(self):
self.tags = tags = text.unquote(self.groups[-1].replace("+", " "))
return {"search_tags": tags}
def posts(self):
if self.tags == "all":
self.tags = ""
return self._pagination({"tags": self.tags})
self.kwdict["search_tags"] = tags = text.unquote(
self.groups[-1].replace("+", " "))
if tags == "all":
tags = ""
return self._pagination({"tags": tags})
class GelbooruV02PoolExtractor(GelbooruV02Extractor):

View File

@@ -19,6 +19,9 @@ __tests__ = (
"622e80be3f496672c44aab5c47fbc6941c61bc79",
"1e0dced55bcb5eefe5cc32f69c7a8df35547b459",
],
"search_tags" : "danraku",
"search_count": 2,
},
{

View File

@@ -14,6 +14,15 @@ __tests__ = (
"#class" : gelbooru_v02.GelbooruV02TagExtractor,
"#sha1_url" : "17c61b386530cf4c30842c9f580d15ef1cd09586",
"#sha1_content": "e5ad4c5bf241b1def154958535bef6c2f6b733eb",
"#results" : (
"https://safebooru.org/images/344/3894735145db4f94cc6a3839004ebf4f16a9bc10.jpg",
"https://safebooru.org/images/344/ae7198cbc41bed9b282fe5ec00b5b91509c53b30.jpg",
"https://safebooru.org/images/264/458a42a01ca7090aca27a85c814557bee9e22a63.jpg",
"https://safebooru.org/images/263/00a74a8736a7691dc1df3def867c32d5ad0fadeb.jpg",
),
"search_tags" : "bonocho",
"search_count": 4,
},
{
@@ -22,6 +31,8 @@ __tests__ = (
"#class" : gelbooru_v02.GelbooruV02TagExtractor,
"#range" : "1-3",
"#count" : 3,
"total": range(5_600_000, 6_000_000),
},
{