aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/tmohentai.py
blob: 873cce8b84ef738b97b613f372b9d065da96f5fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.

"""Extractors for https://tmohentai.com/"""

from .common import GalleryExtractor
from .. import text

BASE_PATTERN = r"(?:https?://)?tmohentai\.com"


class TmohentaiGalleryExtractor(GalleryExtractor):
    category = "tmohentai"
    root = "http://tmohentai.com"
    directory_fmt = ("{category}", "{title} ({gallery_id})")
    pattern = rf"{BASE_PATTERN}/(?:contents|reader)/(\w+)"
    example = "https://tmohentai.com/contents/12345a67b89c0"

    def __init__(self, match):
        self.gallery_id = match[1]
        url = f"{self.root}/contents/{self.gallery_id}"
        GalleryExtractor.__init__(self, match, url)

    def images(self, page):
        base = f"https://imgrojo.tmohentai.com/contents/{self.gallery_id}/"
        cnt = page.count('class="lanzador')
        return [(f"{base}{i:>03}.webp", None) for i in range(0, cnt)]

    def metadata(self, page):
        extr = text.extract_from(page)

        return {
            "gallery_id": self.gallery_id,
            "title"     : text.unescape(extr("<h3>", "<").strip()),
            "artists"   : text.split_html(extr(
                "<label>Artists and Artists Groups</label>", "</ul>")),
            "genres"    : text.split_html(extr(
                "<label>Genders</label>", "</ul>")),
            "tags"      : text.split_html(extr(
                "<label>Tags</label>", "</ul>")),
            "uploader"  : text.remove_html(extr(
                "<label>Uploaded By</label>", "</ul>")),
            "language"  : extr("&nbsp;", "\n"),
        }