Debian Codegraph @

gallery_dl/extractor/hentai2read.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # Copyright 2016-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://hentai2read.com/"""
10
11 from .common import ChapterExtractor, MangaExtractor
12 from .. import text, util
13
14
15 class Hentai2readBase():
16 """Base class for hentai2read extractors"""
17 category = "hentai2read"
18 root = "https://hentai2read.com"
19
20
21 class Hentai2readChapterExtractor(Hentai2readBase, ChapterExtractor):
22 """Extractor for a single manga chapter from hentai2read.com"""
23 archive_fmt = "{chapter_id}_{page}"
24 pattern = r"(?:https?://)?(?:www\.)?hentai2read\.com(/[^/?#]+/([^/?#]+))"
25 example = "https://hentai2read.com/TITLE/1/"
26
27 def metadata(self, page):
28 title, pos = text.extract(page, "<title>", "</title>")
29 manga_id, pos = text.extract(page, 'data-mid="', '"', pos)
30 chapter_id, pos = text.extract(page, 'data-cid="', '"', pos)
31 chapter, sep, minor = self.groups[1].partition(".")
32
33 match = text.re(
34 r"Reading (.+) \(([^)]+)\) Hentai(?: by (.*))? - "
35 r"([^:]+): (.+) . Page 1 ").match(title)
36 if match:
37 manga, type, author, _, title = match.groups()
38 else:
39 self.log.warning("Failed to extract 'manga', 'type', 'author', "
40 "and 'title' metadata")
41 manga = type = author = title = ""
42
43 return {
44 "manga": manga,
45 "manga_id": text.parse_int(manga_id),
46 "chapter": text.parse_int(chapter),
47 "chapter_minor": sep + minor,
48 "chapter_id": text.parse_int(chapter_id),
49 "type": type,
50 "author": author,
51 "title": title,
52 "lang": "en",
53 "language": "English",
54 }
55
56 def images(self, page):
57 images = text.extract(page, "'images' : ", ",\n")[0]
58 return [
59 ("https://hentaicdn.com/hentai" + part, None)
60 for part in util.json_loads(images)
61 ]
62
63
64 class Hentai2readMangaExtractor(Hentai2readBase, MangaExtractor):
65 """Extractor for hmanga from hentai2read.com"""
66 chapterclass = Hentai2readChapterExtractor
67 pattern = r"(?:https?://)?(?:www\.)?hentai2read\.com(/[^/?#]+)/?$"
68 example = "https://hentai2read.com/TITLE/"
69
70 def chapters(self, page):
71 results = []
72
73 pos = page.find('itemscope itemtype="http://schema.org/Book') + 1
74 manga, pos = text.extract(
75 page, '<span itemprop="name">', '</span>', pos)
76 mtype, pos = text.extract(
77 page, '<small class="text-danger">[', ']</small>', pos)
78 manga_id = text.parse_int(text.extract(
79 page, 'data-mid="', '"', pos)[0])
80
81 while True:
82 chapter_id, pos = text.extract(page, ' data-cid="', '"', pos)
83 if not chapter_id:
84 return results
85 _ , pos = text.extract(page, ' href="', '"', pos)
86 url, pos = text.extract(page, ' href="', '"', pos)
87
88 chapter, pos = text.extract(page, '>', '<', pos)
89 chapter, _, title = text.unescape(chapter).strip().partition(" - ")
90 chapter, sep, minor = chapter.partition(".")
91
92 results.append((url, {
93 "manga": manga,
94 "manga_id": manga_id,
95 "chapter": text.parse_int(chapter),
96 "chapter_minor": sep + minor,
97 "chapter_id": text.parse_int(chapter_id),
98 "type": mtype,
99 "title": title,
100 "lang": "en",
101 "language": "English",
102 }))