1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-21 18:22:30 +01:00

[koharu] implement 'tags' option

This commit is contained in:
Mike Fährmann 2024-11-15 23:06:01 +01:00
parent ddd325b435
commit cb09273670
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
3 changed files with 74 additions and 6 deletions

View File

@ -1058,7 +1058,8 @@ Description
extractor.*.postprocessors extractor.*.postprocessors
-------------------------- --------------------------
Type Type
``list`` of |Postprocessor Configuration|_ objects * |Postprocessor Configuration|_ object
* ``list`` of |Postprocessor Configuration|_ objects
Example Example
.. code:: json .. code:: json
@ -2363,6 +2364,18 @@ Description
* ``"hitomi"``: Download the corresponding gallery from ``hitomi.la`` * ``"hitomi"``: Download the corresponding gallery from ``hitomi.la``
extractor.exhentai.tags
-----------------------
Type
``bool``
Default
``false``
Description
Group ``tags`` by type and
provide them as ``tags_<type>`` metadata fields,
for example ``tags_artist`` or ``tags_character``.
extractor.fanbox.comments extractor.fanbox.comments
------------------------- -------------------------
Type Type
@ -3032,6 +3045,18 @@ Description
| ``"780"``, ``"980"``, ``"1280"``, ``"1600"``, ``"0"`` (original) | ``"780"``, ``"980"``, ``"1280"``, ``"1600"``, ``"0"`` (original)
extractor.koharu.tags
---------------------
Type
``bool``
Default
``false``
Description
Group ``tags`` by type and
provide them as ``tags_<type>`` metadata fields,
for example ``tags_artist`` or ``tags_character``.
extractor.lolisafe.domain extractor.lolisafe.domain
------------------------- -------------------------
Type Type
@ -5156,8 +5181,9 @@ Type
Default Default
``false`` ``false``
Description Description
Categorize tags by their respective types Group ``tags`` by type and
and provide them as ``tags_<type>`` metadata fields. provide them as ``tags_<type>`` metadata fields,
for example ``tags_artist`` or ``tags_character``.
Note: This requires 1 additional HTTP request per post. Note: This requires 1 additional HTTP request per post.

View File

@ -11,6 +11,7 @@
from .common import GalleryExtractor, Extractor, Message from .common import GalleryExtractor, Extractor, Message
from .. import text, exception from .. import text, exception
from ..cache import cache from ..cache import cache
import collections
BASE_PATTERN = ( BASE_PATTERN = (
r"(?i)(?:https?://)?(" r"(?i)(?:https?://)?("
@ -108,14 +109,24 @@ class KoharuGalleryExtractor(KoharuExtractor, GalleryExtractor):
url = "{}/books/detail/{}/{}".format( url = "{}/books/detail/{}/{}".format(
self.root_api, self.groups[1], self.groups[2]) self.root_api, self.groups[1], self.groups[2])
self.data = data = self.request(url, headers=self.headers).json() self.data = data = self.request(url, headers=self.headers).json()
data["date"] = text.parse_timestamp(data["created_at"] // 1000)
tags = [] tags = []
for tag in data["tags"]: types = self.TAG_TYPES
tags_data = data["tags"]
for tag in tags_data:
name = tag["name"] name = tag["name"]
namespace = tag.get("namespace", 0) namespace = tag.get("namespace", 0)
tags.append(self.TAG_TYPES[namespace] + ":" + name) tags.append(types[namespace] + ":" + name)
data["tags"] = tags data["tags"] = tags
data["date"] = text.parse_timestamp(data["created_at"] // 1000)
if self.config("tags", False):
tags = collections.defaultdict(list)
for tag in tags_data :
tags[tag.get("namespace", 0)].append(tag["name"])
for type, values in tags.items():
data["tags_" + types[type]] = values
try: try:
if self.cbz: if self.cbz:

View File

@ -12,6 +12,7 @@ __tests__ = (
"#url" : "https://niyaniya.moe/g/14216/6c67076fdd45", "#url" : "https://niyaniya.moe/g/14216/6c67076fdd45",
"#category": ("", "koharu", "gallery"), "#category": ("", "koharu", "gallery"),
"#class" : koharu.KoharuGalleryExtractor, "#class" : koharu.KoharuGalleryExtractor,
"#options" : {"tags": True},
"#pattern" : r"https://kisakisexo.xyz/download/59896/a4fbd1828229/f47639c6abaf1903dd69c36a3d961da84741a1831aa07a2906ce9c74156a5d75\?v=1721626410802&w=0", "#pattern" : r"https://kisakisexo.xyz/download/59896/a4fbd1828229/f47639c6abaf1903dd69c36a3d961da84741a1831aa07a2906ce9c74156a5d75\?v=1721626410802&w=0",
"#count" : 1, "#count" : 1,
@ -43,6 +44,36 @@ __tests__ = (
"other:uncensored", "other:uncensored",
"other:vanilla", "other:vanilla",
], ],
"tags_artist": [
"ouchi kaeru",
],
"tags_female": [
"busty",
],
"tags_general": [
"beach",
"booty",
"dark skin",
"fingering",
"handjob",
"light hair",
"nakadashi",
"outdoors",
"ponytail",
"swimsuit",
"x-ray",
],
"tags_language": [
"english",
"translated",
],
"tags_magazine": [
"comic kairakuten 2024-08",
],
"tags_other": [
"uncensored",
"vanilla",
],
"title" : "[Ouchi Kaeru] Summer Business (Comic Kairakuten 2024-08)", "title" : "[Ouchi Kaeru] Summer Business (Comic Kairakuten 2024-08)",
"updated_at": 1721626410802, "updated_at": 1721626410802,
}, },