From 0d1469f229eb860a0add6710c82a171732fa8f1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 15 Nov 2024 21:47:13 +0100 Subject: [PATCH] [exhentai] implement 'tags' option (#2117) allow splitting tags into categories, e.g. 'tags_parody', 'tags_group', etc. --- gallery_dl/extractor/exhentai.py | 8 ++++++++ test/results/exhentai.py | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/gallery_dl/extractor/exhentai.py b/gallery_dl/extractor/exhentai.py index 3e6d5378..e7ba78e7 100644 --- a/gallery_dl/extractor/exhentai.py +++ b/gallery_dl/extractor/exhentai.py @@ -11,6 +11,7 @@ from .common import Extractor, Message from .. import text, util, exception from ..cache import cache +import collections import itertools import math @@ -227,6 +228,13 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor): if self.config("metadata", False): data.update(self.metadata_from_api()) data["date"] = text.parse_timestamp(data["posted"]) + if self.config("tags", False): + tags = collections.defaultdict(list) + for tag in data["tags"]: + type, _, value = tag.partition(":") + tags[type].append(value) + for type, values in tags.items(): + data["tags_" + type] = values return data def metadata_from_page(self, page): diff --git a/test/results/exhentai.py b/test/results/exhentai.py index 731066aa..df593573 100644 --- a/test/results/exhentai.py +++ b/test/results/exhentai.py @@ -13,7 +13,7 @@ __tests__ = ( "#url" : "https://exhentai.org/g/1200119/d55c44d3d0/", "#category": ("", "exhentai", "gallery"), "#class" : exhentai.ExhentaiGalleryExtractor, - "#options" : {"original": False}, + "#options" : {"original": False, "tags": True}, "#sha1_content": [ "2c68cff8a7ca540a78c36fdbf5fbae0260484f87", "e9891a4c017ed0bb734cd1efba5cd03f594d31ff", @@ -40,6 +40,10 @@ __tests__ = ( "group:seventh lowlife", "other:sample", ], + "tags_parody" : ["komi-san wa komyushou desu."], + "tags_character": ["shouko komi"], + "tags_group" : ["seventh lowlife"], + "tags_other" : ["sample"], "thumb" : "https://s.exhentai.org/t/ce/0a/ce0a5bcb583229a9b07c0f83bcb1630ab1350640-624622-736-1036-jpg_250.jpg", "title" : "C93 [Seventh_Lowlife] Komi-san ha Tokidoki Daitan desu (Komi-san wa Komyushou desu) [Sample]", "title_jpn" : "(C93) [Comiketjack (わ!)] 古見さんは、時々大胆です。 (古見さんは、コミュ症です。) [見本]",