From b90c77d8f12351f12bc532b0dcd22b088f84d17a Mon Sep 17 00:00:00 2001 From: Shelvacu Date: Thu, 5 Dec 2024 21:09:38 -0800 Subject: [PATCH] [itaku] add 'search' extractor --- gallery_dl/extractor/itaku.py | 50 +++++++++++++++++++++++++++++++++++ test/results/itaku.py | 23 ++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/gallery_dl/extractor/itaku.py b/gallery_dl/extractor/itaku.py index 1aef66e9..b5a8f356 100644 --- a/gallery_dl/extractor/itaku.py +++ b/gallery_dl/extractor/itaku.py @@ -78,6 +78,16 @@ class ItakuImageExtractor(ItakuExtractor): return (self.api.image(self.item),) +class ItakuSearchExtractor(ItakuExtractor): + subcategory = "search" + pattern = BASE_PATTERN + r"/home/images/?\?([^#]+)" + example = "https://itaku.ee/home/images?tags=SEARCH" + + def posts(self): + params = text.parse_query_list(self.item) + return self.api.search_images(params) + + class ItakuAPI(): def __init__(self, extractor): @@ -87,6 +97,46 @@ class ItakuAPI(): "Accept": "application/json, text/plain, */*", } + def search_images(self, params): + endpoint = "/galleries/images/" + required_tags = [] + negative_tags = [] + optional_tags = [] + tags = [] + tags_param = params.get("tags") + if isinstance(tags_param, str): + tags = [tags_param] + elif isinstance(tags_param, list): + tags = tags_param + + for tag in tags: + if len(tag) == 0: + pass + elif tag[0] == "-": + negative_tags.append(tag[1:]) + elif tag[0] == "~": + optional_tags.append(tag[1:]) + else: + required_tags.append(tag) + + # Every param is simply passed through to the api, except "tags" + if "tags" in params: + del params["tags"] + + api_params = { + "required_tags": required_tags, + "negative_tags": negative_tags, + "optional_tags": optional_tags, + "page": 1, + "page_size": 30, + "maturity_rating": ("SFW", "Questionable", "NSFW"), + "ordering": "-date_added", + "visibility": ("PUBLIC", "PROFILE_ONLY"), + **params + } + + return self._pagination(endpoint, api_params, self.image) + def galleries_images(self, username, section=None): endpoint = "/galleries/images/" params = { diff --git a/test/results/itaku.py b/test/results/itaku.py index 27b59414..b76a4cc8 100644 --- a/test/results/itaku.py +++ b/test/results/itaku.py @@ -78,4 +78,27 @@ __tests__ = ( "#urls" : "https://itaku.ee/api/media/gallery_vids/sleepy_af_OY5GHWw.mp4", }, +{ + "#url" : "https://itaku.ee/home/images?tags=cute", + "#comment" : "simple search", + "#category": ("", "itaku", "search"), + "#class" : itaku.ItakuSearchExtractor, + "#count" : "> 1", +}, + +{ + "#url" : "https://itaku.ee/home/images?maturity_rating=SFW&date_range=&ordering=-date_added&text=hello&is_video=true", + "#comment" : "search for videos", + "#category": ("", "itaku", "search"), + "#class" : itaku.ItakuSearchExtractor, + "#count" : 30, +}, + +{ + "#url" : "https://itaku.ee/home/images?tags=%2Bcute&tags=-cute&tags=~cute&maturity_rating=SFW&date_range=&ordering=-date_added", + "#comment" : "search with postive, negative, and optional tags", + "#category": ("", "itaku", "search"), + "#class" : itaku.ItakuSearchExtractor, + "#count" : 0 +}, )