From 5207a0c2e0a6fe38d46ea7fe541b807321471993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 23 Jul 2024 09:50:06 +0200 Subject: [PATCH] [zerochan] implement 'tags' option (#5874) allow splitting tags into separate lists by category --- gallery_dl/extractor/zerochan.py | 9 +++++++++ test/results/zerochan.py | 25 ++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/gallery_dl/extractor/zerochan.py b/gallery_dl/extractor/zerochan.py index 6a053737..1d00c60f 100644 --- a/gallery_dl/extractor/zerochan.py +++ b/gallery_dl/extractor/zerochan.py @@ -11,6 +11,7 @@ from .booru import BooruExtractor from ..cache import cache from .. import text, util, exception +import collections BASE_PATTERN = r"(?:https?://)?(?:www\.)?zerochan\.net" @@ -109,6 +110,14 @@ class ZerochanExtractor(BooruExtractor): return data + def _tags(self, post, page): + tags = collections.defaultdict(list) + for tag in post["tags"]: + category, _, name = tag.partition(":") + tags[category].append(name) + for key, value in tags.items(): + post["tags_" + key.lower()] = value + class ZerochanTagExtractor(ZerochanExtractor): subcategory = "tag" diff --git a/test/results/zerochan.py b/test/results/zerochan.py index ce5efe45..f1788c2b 100644 --- a/test/results/zerochan.py +++ b/test/results/zerochan.py @@ -120,6 +120,7 @@ __tests__ = ( "#category": ("booru", "zerochan", "image"), "#class" : zerochan.ZerochanImageExtractor, "#urls" : "https://static.zerochan.net/DRAGON.BALL.full.4233756.jpg", + "#options" : {"tags": True}, "author" : "Raydash", "date" : "dt:2024-07-23 00:10:51", @@ -149,9 +150,31 @@ __tests__ = ( "Source:Fanart from X (Twitter)", "Source:X (Twitter)", ], + "tags_character": [ + "Piccolo", + "Son Gohan", + ], + "tags_mangaka" : [ + "Raydash", + ], + "tags_series" : [ + "DRAGON BALL", + "DRAGON BALL Z", + ], + "tags_source" : [ + "Fanart", + "Fanart from X (Twitter)", + "X (Twitter)", + ], + "tags_theme" : [ + "Duo", + "Green Skin", + "Male", + "Male Focus", + "Two Males", + ], "uploader" : "menotbug", "width" : 750, - }, )