Skip to content

Commit

Permalink
[szurubooru] support empty tag searches (#5711)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Jun 11, 2024
1 parent 40c685d commit 86f0c3b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 4 additions & 8 deletions gallery_dl/extractor/szurubooru.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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]),)
12 changes: 12 additions & 0 deletions test/results/foalcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 86f0c3b

Please sign in to comment.