Debian Codegraph @

gallery_dl/extractor/tmohentai.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License version 2 as
5 # published by the Free Software Foundation.
6
7 """Extractors for https://tmohentai.com/"""
8
9 from .common import GalleryExtractor
10 from .. import text
11
12 BASE_PATTERN = r"(?:https?://)?tmohentai\.com"
13
14
15 class TmohentaiGalleryExtractor(GalleryExtractor):
16 category = "tmohentai"
17 root = "http://tmohentai.com"
18 directory_fmt = ("{category}", "{title} ({gallery_id})")
19 pattern = BASE_PATTERN + r"/(?:contents|reader)/(\w+)"
20 example = "https://tmohentai.com/contents/12345a67b89c0"
21
22 def __init__(self, match):
23 self.gallery_id = match[1]
24 url = f"{self.root}/contents/{self.gallery_id}"
25 GalleryExtractor.__init__(self, match, url)
26
27 def images(self, page):
28 base = f"https://imgrojo.tmohentai.com/contents/{self.gallery_id}/"
29 cnt = page.count('class="lanzador')
30 return [(f"{base}{i:>03}.webp", None) for i in range(0, cnt)]
31
32 def metadata(self, page):
33 extr = text.extract_from(page)
34
35 return {
36 "gallery_id": self.gallery_id,
37 "title" : text.unescape(extr("<h3>", "<").strip()),
38 "artists" : text.split_html(extr(
39 "<label>Artists and Artists Groups</label>", "</ul>")),
40 "genres" : text.split_html(extr(
41 "<label>Genders</label>", "</ul>")),
42 "tags" : text.split_html(extr(
43 "<label>Tags</label>", "</ul>")),
44 "uploader" : text.remove_html(extr(
45 "<label>Uploaded By</label>", "</ul>")),
46 "language" : extr("&nbsp;", "\n"),
47 }