From 86f0c3baafcfc09e5e15706457f8e964b866d204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 11 Jun 2024 20:25:06 +0200 Subject: [PATCH] [szurubooru] support empty tag searches (#5711) --- gallery_dl/extractor/szurubooru.py | 12 ++++-------- test/results/foalcon.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/gallery_dl/extractor/szurubooru.py b/gallery_dl/extractor/szurubooru.py index 08cccab6b1..bba1ece9d2 100644 --- a/gallery_dl/extractor/szurubooru.py +++ b/gallery_dl/extractor/szurubooru.py @@ -98,13 +98,13 @@ class SzurubooruTagExtractor(SzurubooruExtractor): subcategory = "tag" directory_fmt = ("{category}", "{search_tags}") archive_fmt = "t_{search_tags}_{id}_{version}" - pattern = BASE_PATTERN + r"/posts/query=([^/?#]+)" + pattern = BASE_PATTERN + r"/posts(?:/query=([^/?#]*))?" example = "https://booru.foalcon.com/posts/query=TAG" def __init__(self, match): SzurubooruExtractor.__init__(self, match) - query = match.group(match.lastindex) - self.query = text.unquote(query.replace("+", " ")) + query = self.groups[-1] + self.query = text.unquote(query.replace("+", " ")) if query else "" def metadata(self): return {"search_tags": self.query} @@ -119,9 +119,5 @@ class SzurubooruPostExtractor(SzurubooruExtractor): pattern = BASE_PATTERN + r"/post/(\d+)" example = "https://booru.foalcon.com/post/12345" - def __init__(self, match): - SzurubooruExtractor.__init__(self, match) - self.post_id = match.group(match.lastindex) - def posts(self): - return (self._api_request("/post/" + self.post_id),) + return (self._api_request("/post/" + self.groups[-1]),) diff --git a/test/results/foalcon.py b/test/results/foalcon.py index 7639c0dfb2..f2ee3a3af4 100644 --- a/test/results/foalcon.py +++ b/test/results/foalcon.py @@ -17,6 +17,18 @@ "#count" : 150, }, +{ + "#url" : "https://booru.foalcon.com/posts/query=", + "#category": ("szurubooru", "foalcon", "tag"), + "#class" : szurubooru.SzurubooruTagExtractor, +}, + +{ + "#url" : "https://booru.foalcon.com/posts", + "#category": ("szurubooru", "foalcon", "tag"), + "#class" : szurubooru.SzurubooruTagExtractor, +}, + { "#url" : "https://booru.foalcon.com/post/30092", "#category": ("szurubooru", "foalcon", "post"),