From 4279928d0b1d19ee8cda6d38ed40f335526a889e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 19 Jun 2025 19:09:21 +0200 Subject: [PATCH] [gelbooru_v02] extract 'total' / 'search_count' metadata (#7689) --- gallery_dl/extractor/gelbooru_v02.py | 17 +++++++++-------- test/results/rule34.py | 3 +++ test/results/safebooru.py | 11 +++++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/gallery_dl/extractor/gelbooru_v02.py b/gallery_dl/extractor/gelbooru_v02.py index 27618531..8a310a54 100644 --- a/gallery_dl/extractor/gelbooru_v02.py +++ b/gallery_dl/extractor/gelbooru_v02.py @@ -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): diff --git a/test/results/rule34.py b/test/results/rule34.py index f6b9b274..b1bd9b10 100644 --- a/test/results/rule34.py +++ b/test/results/rule34.py @@ -19,6 +19,9 @@ __tests__ = ( "622e80be3f496672c44aab5c47fbc6941c61bc79", "1e0dced55bcb5eefe5cc32f69c7a8df35547b459", ], + + "search_tags" : "danraku", + "search_count": 2, }, { diff --git a/test/results/safebooru.py b/test/results/safebooru.py index 3a217166..bce90e18 100644 --- a/test/results/safebooru.py +++ b/test/results/safebooru.py @@ -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), }, {