From 3ea244eebb11e9d509630e63bf43d8388ff14465 Mon Sep 17 00:00:00 2001 From: pocketinternet Date: Tue, 17 Jun 2025 18:34:58 +0100 Subject: [PATCH] [webtoons] add 'thumbnails' option (#6468 #7441) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update webtoons.py Added thumbnail download capability which defaults to false * Update configuration.rst Added documentation for webtoon thumbnail option * extract thumbnails in GalleryExtractor.assets() * simplify & fix flake8 * include 'type' in default filenames * add test * update docs --------- Co-authored-by: Mike Fährmann --- docs/configuration.rst | 11 +++++++++++ docs/gallery-dl.conf | 3 ++- gallery_dl/extractor/webtoons.py | 10 +++++++++- test/results/webtoons.py | 18 ++++++++++++++++-- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index a27bc5c0..e31f6e27 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -5541,6 +5541,17 @@ Description | - Set a value to ``false`` to completely remove these extension's ``type`` parameter | - Omit an extension to leave its URLs unchanged +extractor.webtoons.thumbnails +----------------------------- +Type + ``bool`` +Default + ``false`` +Description + Download the active chapter's ``thumbnail``. + + Useful for creating CBZ archives with actual source thumbnails. + extractor.weibo.gifs -------------------- diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index e472378d..1723ec33 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -785,7 +785,8 @@ { "sleep-request": "0.5-1.5", - "quality": "original" + "quality" : "original", + "thumbnails": false }, "weebcentral": { diff --git a/gallery_dl/extractor/webtoons.py b/gallery_dl/extractor/webtoons.py index c72a843f..7fbfcc64 100644 --- a/gallery_dl/extractor/webtoons.py +++ b/gallery_dl/extractor/webtoons.py @@ -44,7 +44,7 @@ class WebtoonsEpisodeExtractor(WebtoonsBase, GalleryExtractor): """Extractor for an episode on webtoons.com""" subcategory = "episode" directory_fmt = ("{category}", "{comic}") - filename_fmt = "{episode_no}-{num:>02}.{extension}" + filename_fmt = "{episode_no}-{num:>02}{type:?-//}.{extension}" archive_fmt = "{title_no}_{episode_no}_{num}" pattern = (LANG_PATTERN + r"/([^/?#]+)/([^/?#]+)/[^/?#]+)" r"/viewer\?([^#'\"]+)") @@ -59,6 +59,7 @@ class WebtoonsEpisodeExtractor(WebtoonsBase, GalleryExtractor): self.title_no = params.get("title_no") self.episode_no = params.get("episode_no") self.gallery_url = "{}/{}/viewer?{}".format(self.root, path, query) + self.thumbnails = self.config("thumbnails", False) def metadata(self, page): extr = text.extract_from(page) @@ -128,6 +129,13 @@ class WebtoonsEpisodeExtractor(WebtoonsBase, GalleryExtractor): results.append((url, None)) return results + def assets(self, page): + if self.thumbnails: + active = text.extr(page, 'class="on ', '') + url = text.extr(active, 'data-url="', '"') + url = url.replace("://webtoon-phinf.", "://swebtoon-phinf.") + return ({"url": url, "type": "thumbnail"},) + class WebtoonsComicExtractor(WebtoonsBase, Extractor): """Extractor for an entire comic on webtoons.com""" diff --git a/test/results/webtoons.py b/test/results/webtoons.py index e3a57248..623c6b16 100644 --- a/test/results/webtoons.py +++ b/test/results/webtoons.py @@ -13,8 +13,8 @@ __tests__ = ( "#url" : "https://www.webtoons.com/en/comedy/safely-endangered/ep-572-earth/viewer?title_no=352&episode_no=572", "#category": ("", "webtoons", "episode"), "#class" : webtoons.WebtoonsEpisodeExtractor, - "#count" : 5, - "#results" : ( + "#count" : 5, + "#results" : ( "https://swebtoon-phinf.pstatic.net/20200513_191/1589322488148XfdRr_PNG/15893224850013525720.png?type=opti", "https://swebtoon-phinf.pstatic.net/20200513_143/1589322489499KJLvU_PNG/15893224866183525723.png?type=opti", "https://swebtoon-phinf.pstatic.net/20200513_281/15893224881499wbH7_PNG/15893224865073525729.png?type=opti", @@ -45,6 +45,20 @@ __tests__ = ( "username" : "safelyendangered", }, +{ + "#url" : "https://www.webtoons.com/en/comedy/safely-endangered/ep-572-earth/viewer?title_no=352&episode_no=572", + "#comment" : "thumbnails (#6468 #7441)", + "#class" : webtoons.WebtoonsEpisodeExtractor, + "#options" : {"thumbnails": True}, + "#range" : "1", + "#results" : "https://swebtoon-phinf.pstatic.net/20200513_37/1589322553469E5p76_PNG/thumb_15893224866533525729.png", + "#sha1_content": "e01e70610821df6ece601393eb6fd7d80fc42f9a", + + "count": 5, + "num" : 0, + "type" : "thumbnail", +}, + { "#url" : "https://www.webtoons.com/en/challenge/punderworld/happy-earth-day-/viewer?title_no=312584&episode_no=40", "#category": ("", "webtoons", "episode"),