Debian Codegraph @

gallery_dl/extractor/hentaihand.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # Copyright 2020-2025 Mike Fährmann
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 2 as
7 # published by the Free Software Foundation.
8
9 """Extractors for https://hentaihand.com/"""
10
11 from .common import GalleryExtractor, Extractor, Message
12 from .. import text, util
13
14
15 class HentaihandGalleryExtractor(GalleryExtractor):
16 """Extractor for image galleries on hentaihand.com"""
17 category = "hentaihand"
18 root = "https://hentaihand.com"
19 pattern = r"(?:https?://)?(?:www\.)?hentaihand\.com/\w+/comic/([\w-]+)"
20 example = "https://hentaihand.com/en/comic/TITLE"
21
22 def __init__(self, match):
23 self.slug = match[1]
24 url = f"{self.root}/api/comics/{self.slug}"
25 GalleryExtractor.__init__(self, match, url)
26
27 def metadata(self, page):
28 info = util.json_loads(page)
29 data = {
30 "gallery_id" : text.parse_int(info["id"]),
31 "title" : info["title"],
32 "title_alt" : info["alternative_title"],
33 "slug" : self.slug,
34 "type" : info["category"]["name"],
35 "language" : info["language"]["name"],
36 "lang" : util.language_to_code(info["language"]["name"]),
37 "tags" : [t["slug"] for t in info["tags"]],
38 "date" : self.parse_datetime_iso(info["uploaded_at"]),
39 }
40 for key in ("artists", "authors", "groups", "characters",
41 "relationships", "parodies"):
42 data[key] = [v["name"] for v in info[key]]
43 return data
44
45 def images(self, _):
46 info = self.request_json(self.page_url + "/images")
47 return [(img["source_url"], img) for img in info["images"]]
48
49
50 class HentaihandTagExtractor(Extractor):
51 """Extractor for tag searches on hentaihand.com"""
52 category = "hentaihand"
53 subcategory = "tag"
54 root = "https://hentaihand.com"
55 pattern = (r"(?i)(?:https?://)?(?:www\.)?hentaihand\.com"
56 r"/\w+/(parody|character|tag|artist|group|language"
57 r"|category|relationship)/([^/?#]+)")
58 example = "https://hentaihand.com/en/tag/TAG"
59
60 def __init__(self, match):
61 Extractor.__init__(self, match)
62 self.type, self.key = match.groups()
63
64 def items(self):
65 if self.type[-1] == "y":
66 tpl = self.type[:-1] + "ies"
67 else:
68 tpl = self.type + "s"
69
70 url = f"{self.root}/api/{tpl}/{self.key}"
71 tid = self.request_json(url, notfound=self.type)["id"]
72
73 url = self.root + "/api/comics"
74 params = {
75 "per_page": "18",
76 tpl : tid,
77 "page" : 1,
78 "q" : "",
79 "sort" : "uploaded_at",
80 "order" : "desc",
81 "duration": "day",
82 }
83 while True:
84 info = self.request_json(url, params=params)
85
86 for gallery in info["data"]:
87 gurl = f"{self.root}/en/comic/{gallery['slug']}"
88 gallery["_extractor"] = HentaihandGalleryExtractor
89 yield Message.Queue, gurl, gallery
90
91 if params["page"] >= info["last_page"]:
92 return
93 params["page"] += 1