Debian Codegraph @

gallery_dl/extractor/hentaihere.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://hentaihere.com/"""
10
11 from .common import ChapterExtractor, MangaExtractor
12 from .. import text, util
13
14
15 class HentaihereBase():
16 """Base class for hentaihere extractors"""
17 category = "hentaihere"
18 root = "https://hentaihere.com"
19
20
21 class HentaihereChapterExtractor(HentaihereBase, ChapterExtractor):
22 """Extractor for a single manga chapter from hentaihere.com"""
23 archive_fmt = "{chapter_id}_{page}"
24 pattern = r"(?:https?://)?(?:www\.)?hentaihere\.com/m/S(\d+)/([^/?#]+)"
25 example = "https://hentaihere.com/m/S12345/1/1/"
26
27 def __init__(self, match):
28 self.manga_id, self.chapter = match.groups()
29 url = f"{self.root}/m/S{self.manga_id}/{self.chapter}/1"
30 ChapterExtractor.__init__(self, match, url)
31
32 def metadata(self, page):
33 title = text.extr(page, "<title>", "</title>")
34 chapter_id = text.extr(page, 'report/C', '"')
35 chapter, sep, minor = self.chapter.partition(".")
36 match = text.re(
37 r"Page 1 \| (.+) \(([^)]+)\) - Chapter \d+: (.+) by "
38 r"(.+) at ").match(title)
39 return {
40 "manga": match[1],
41 "manga_id": text.parse_int(self.manga_id),
42 "chapter": text.parse_int(chapter),
43 "chapter_minor": sep + minor,
44 "chapter_id": text.parse_int(chapter_id),
45 "type": match[2],
46 "title": match[3],
47 "author": match[4],
48 "lang": "en",
49 "language": "English",
50 }
51
52 def images(self, page):
53 images = text.extr(page, "var rff_imageList = ", ";")
54 return [
55 ("https://hentaicdn.com/hentai" + part, None)
56 for part in util.json_loads(images)
57 ]
58
59
60 class HentaihereMangaExtractor(HentaihereBase, MangaExtractor):
61 """Extractor for hmanga from hentaihere.com"""
62 chapterclass = HentaihereChapterExtractor
63 pattern = r"(?:https?://)?(?:www\.)?hentaihere\.com(/m/S\d+)/?$"
64 example = "https://hentaihere.com/m/S12345"
65
66 def chapters(self, page):
67 results = []
68
69 pos = page.find('itemscope itemtype="http://schema.org/Book') + 1
70 manga, pos = text.extract(
71 page, '<span itemprop="name">', '</span>', pos)
72 mtype, pos = text.extract(
73 page, '<span class="mngType text-danger">[', ']</span>', pos)
74 manga_id = text.parse_int(
75 self.page_url.rstrip("/").rpartition("/")[2][1:])
76
77 while True:
78 marker, pos = text.extract(
79 page, '<li class="sub-chp clearfix">', '', pos)
80 if marker is None:
81 return results
82 url, pos = text.extract(page, '<a href="', '"', pos)
83
84 chapter, pos = text.extract(page, 'title="Tagged: -">\n', '<', pos)
85 chapter_id, pos = text.extract(page, '/C', '"', pos)
86 chapter, _, title = text.unescape(chapter).strip().partition(" - ")
87 chapter, sep, minor = chapter.partition(".")
88
89 results.append((url, {
90 "manga_id": manga_id,
91 "manga": manga,
92 "chapter": text.parse_int(chapter),
93 "chapter_minor": sep + minor,
94 "chapter_id": text.parse_int(chapter_id),
95 "type": mtype,
96 "title": title,
97 "lang": "en",
98 "language": "English",
99 }))