| 1 |
|
| 2 |
|
| 3 |
n |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
"""Extractors for https://hiperdex.com/""" |
| 10 |
|
| 11 |
from .common import ChapterExtractor, MangaExtractor |
| 12 |
from .. import text, util |
| 13 |
|
| 14 |
BASE_PATTERN = (r"((?:https?://)?(?:www\.)?" |
| 15 |
r"(?:1st)?hiper(?:dex|toon)\d?\.(?:com|net|info|top))") |
| 16 |
|
| 17 |
|
| 18 |
class HiperdexBase(): |
| 19 |
"""Base class for hiperdex extractors""" |
| 20 |
category = "hiperdex" |
| 21 |
root = "https://hiperdex.com" |
| 22 |
|
| 23 |
def manga_data(self, slug): |
| 24 |
manga = self.request_api("series.bySlugWithGenres", {"slug": slug}) |
| 25 |
manga["manga"] = manga.pop("title", None) |
| 26 |
manga["manga_id"] = manga.pop("id", None) |
| 27 |
manga["manga_slug"] = manga.pop("slug", None) |
| 28 |
manga["manga_cover"] = manga.pop("coverUrl", None) |
| 29 |
manga["description"] = manga.pop("synopsis", None) |
| 30 |
manga["author"] = manga.pop("authors", None) |
| 31 |
manga["artist"] = manga.pop("artists", None) |
| 32 |
manga["tags"] = manga.pop("genres", None) |
| 33 |
manga["manga_date"] = self.parse_datetime_iso( |
| 34 |
manga.pop("createdAt", None)) |
| 35 |
manga["manga_date_updated"] = self.parse_datetime_iso( |
| 36 |
manga.pop("updatedAt", None)) |
| 37 |
|
| 38 |
return manga |
| 39 |
|
| 40 |
def chapter_data(self, chapter): |
| 41 |
if chapter.startswith("chapter-"): |
| 42 |
chapter = chapter[8:] |
| 43 |
chapter, _, minor = chapter.partition("-") |
| 44 |
return { |
| 45 |
**self.cache(self.manga_data, self.manga.lower()), |
| 46 |
"chapter" : text.parse_int(chapter), |
| 47 |
"chapter_minor": "." + minor if minor and minor != "end" else "", |
| 48 |
} |
| 49 |
|
| 50 |
def request_api(self, endpoint, params): |
| 51 |
url = "https://hiperdex.com/api/trpc/" + endpoint |
| 52 |
params = {"input": util.json_dumps({"json": params})} |
| 53 |
headers = {"x-cfg-auth": "yceqt7qgu004"} |
| 54 |
|
| 55 |
result = self.request_json(url, params=params, headers=headers) |
| 56 |
return result["result"]["data"]["json"] |
| 57 |
|
| 58 |
|
| 59 |
class HiperdexChapterExtractor(HiperdexBase, ChapterExtractor): |
| 60 |
"""Extractor for hiperdex manga chapters""" |
| 61 |
pattern = BASE_PATTERN + r"(/mangas?/([^/?#]+)/([^/?#]+))" |
| 62 |
example = "https://hiperdex.com/manga/MANGA/CHAPTER/" |
| 63 |
|
| 64 |
def __init__(self, match): |
| 65 |
root, path, self.manga, self.chapter = match.groups() |
| 66 |
self.root = text.ensure_http_scheme(root) |
| 67 |
ChapterExtractor.__init__(self, match, self.root + path) |
| 68 |
|
| 69 |
def metadata(self, _): |
| 70 |
return self.chapter_data(self.chapter) |
| 71 |
|
| 72 |
def images(self, _): |
| 73 |
pages = self.request_api("reader.chapterPages", { |
| 74 |
"seriesSlug": self.manga, |
| 75 |
"chapterNumber": float(self.chapter), |
| 76 |
}) |
| 77 |
pages.sort(key=lambda x: x.get("pageOrder")) |
| 78 |
return [(page["webpUrl"], page) for page in pages] |
| 79 |
|
| 80 |
|
| 81 |
class HiperdexMangaExtractor(HiperdexBase, MangaExtractor): |
| 82 |
"""Extractor for hiperdex manga""" |
| 83 |
chapterclass = HiperdexChapterExtractor |
| 84 |
pattern = BASE_PATTERN + r"(/mangas?/([^/?#]+))/?$" |
| 85 |
example = "https://hiperdex.com/manga/MANGA/" |
| 86 |
|
| 87 |
def __init__(self, match): |
| 88 |
root, path, self.manga = match.groups() |
| 89 |
self.root = text.ensure_http_scheme(root) |
| 90 |
MangaExtractor.__init__(self, match, self.root + path) |
| 91 |
|
| 92 |
def chapters(self, page): |
| 93 |
manga = self.cache(self.manga_data, self.manga) |
| 94 |
base = f"{self.root}/manga/{manga['manga_slug']}/" |
| 95 |
chapters = self.request_api("series.chapters", { |
| 96 |
"seriesId": manga["manga_id"], |
| 97 |
}) |
| 98 |
|
| 99 |
results = [] |
| 100 |
for ch in chapters: |
| 101 |
number = str(ch["number"]) |
| 102 |
results.append((base + number, { |
| 103 |
"date": self.parse_datetime_iso( |
| 104 |
ch.pop("createdAt", None)), |
| 105 |
"date_updated": self.parse_datetime_iso( |
| 106 |
ch.pop("updatedAt", None)), |
| 107 |
**self.chapter_data(number), |
| 108 |
**ch, |
| 109 |
})) |
| 110 |
return results |
| 111 |
|
| 112 |
|
| 113 |
class HiperdexArtistExtractor(HiperdexBase, MangaExtractor): |
| 114 |
"""Extractor for an artists's manga on hiperdex""" |
| 115 |
subcategory = "artist" |
| 116 |
categorytransfer = False |
| 117 |
chapterclass = HiperdexMangaExtractor |
| 118 |
reverse = False |
| 119 |
pattern = BASE_PATTERN + r"(/manga-a(?:rtist|uthor)/(?:[^/?#]+))" |
| 120 |
example = "https://hiperdex.com/manga-artist/NAME/" |
| 121 |
|
| 122 |
def __init__(self, match): |
| 123 |
self.root = text.ensure_http_scheme(match[1]) |
| 124 |
MangaExtractor.__init__(self, match, self.root + match[2] + "/") |
| 125 |
|
| 126 |
def chapters(self, page): |
| 127 |
results = [] |
| 128 |
for info in text.extract_iter(page, 'id="manga-item-', '<img'): |
| 129 |
url = text.extr(info, 'href="', '"') |
| 130 |
results.append((url, {})) |
| 131 |
return results |