From 34e157e166373fbae893396162aec7c60fa9f654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 5 Dec 2024 21:25:44 +0100 Subject: [PATCH] [zerochan] download webp and gif files, add 'extensions' option (#6576) --- docs/configuration.rst | 16 ++++++++++++++++ gallery_dl/extractor/zerochan.py | 21 ++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index f191d03c..25d29c8b 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -5190,6 +5190,22 @@ Description `youtube-dl's docstrings `__ +extractor.zerochan.extensions +----------------------------- +Type + * ``string`` + * ``list`` of ``strings`` +Default + ``["jpg", "png", "webp", "gif"]`` +Example + * ``"gif"`` + * ``["webp", "gif", "jpg"}`` +Description + List of filename extensions to try when dynamically building download URLs + (`"pagination": "api" `__ + + `"metadata": false `__) + + extractor.zerochan.metadata --------------------------- Type diff --git a/gallery_dl/extractor/zerochan.py b/gallery_dl/extractor/zerochan.py index f9b1a7f4..4c4fb3af 100644 --- a/gallery_dl/extractor/zerochan.py +++ b/gallery_dl/extractor/zerochan.py @@ -145,6 +145,14 @@ class ZerochanTagExtractor(ZerochanExtractor): self.posts = self.posts_api self.session.headers["User-Agent"] = util.USERAGENT + exts = self.config("extensions") + if exts: + if isinstance(exts, str): + exts = exts.split(",") + self.exts = exts + else: + self.exts = ("jpg", "png", "webp", "gif") + def metadata(self): return {"search_tags": text.unquote( self.search_tag.replace("+", " "))} @@ -194,8 +202,6 @@ class ZerochanTagExtractor(ZerochanExtractor): "p" : self.page_start, } - static = "https://static.zerochan.net/.full." - while True: response = self.request(url, params=params, allow_redirects=False) @@ -221,15 +227,20 @@ class ZerochanTagExtractor(ZerochanExtractor): yield post else: for post in posts: - base = static + str(post["id"]) - post["file_url"] = base + ".jpg" - post["_fallback"] = (base + ".png",) + urls = self._urls(post) + post["file_url"] = next(urls) + post["_fallback"] = urls yield post if not data.get("next"): return params["p"] += 1 + def _urls(self, post, static="https://static.zerochan.net/.full."): + base = static + str(post["id"]) + "." + for ext in self.exts: + yield base + ext + class ZerochanImageExtractor(ZerochanExtractor): subcategory = "image"