| 1 |
|
| 2 |
|
| 3 |
n |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
"""Extractors for https://www.mangahere.cc/""" |
| 10 |
|
| 11 |
from .common import ChapterExtractor, MangaExtractor |
| 12 |
from .. import text |
| 13 |
|
| 14 |
|
| 15 |
class MangahereBase(): |
| 16 |
"""Base class for mangahere extractors""" |
| 17 |
category = "mangahere" |
| 18 |
root = "https://www.mangahere.cc" |
| 19 |
root_mobile = "https://m.mangahere.cc" |
| 20 |
|
| 21 |
|
| 22 |
class MangahereChapterExtractor(MangahereBase, ChapterExtractor): |
| 23 |
"""Extractor for manga-chapters from mangahere.cc""" |
| 24 |
pattern = (r"(?:https?://)?(?:www\.|m\.)?mangahere\.c[co]/manga/" |
| 25 |
r"([^/]+(?:/v0*(\d+))?/c([^/?#]+))") |
| 26 |
example = "https://www.mangahere.cc/manga/TITLE/c001/1.html" |
| 27 |
|
| 28 |
def __init__(self, match): |
| 29 |
self.part, self.volume, self.chapter = match.groups() |
| 30 |
self.base = f"{self.root_mobile}/manga/{self.part}/" |
| 31 |
ChapterExtractor.__init__(self, match, self.base + "1.html") |
| 32 |
|
| 33 |
def _init(self): |
| 34 |
self.session.headers["Referer"] = self.root_mobile + "/" |
| 35 |
|
| 36 |
def metadata(self, page): |
| 37 |
pos = page.index("</select>") |
| 38 |
count , pos = text.extract(page, ">", "<", pos - 40) |
| 39 |
manga_id , pos = text.extract(page, "series_id = ", ";", pos) |
| 40 |
chapter_id, pos = text.extract(page, "chapter_id = ", ";", pos) |
| 41 |
manga , pos = text.extract(page, '"name":"', '"', pos) |
| 42 |
chapter, dot, minor = self.chapter.partition(".") |
| 43 |
|
| 44 |
return { |
| 45 |
"manga": text.unescape(manga), |
| 46 |
"manga_id": text.parse_int(manga_id), |
| 47 |
"title": self._get_title(), |
| 48 |
"volume": text.parse_int(self.volume), |
| 49 |
"chapter": text.parse_int(chapter), |
| 50 |
"chapter_minor": dot + minor, |
| 51 |
"chapter_id": text.parse_int(chapter_id), |
| 52 |
"count": text.parse_int(count), |
| 53 |
"lang": "en", |
| 54 |
"language": "English", |
| 55 |
} |
| 56 |
|
| 57 |
def images(self, page): |
| 58 |
pnum = 1 |
| 59 |
|
| 60 |
while True: |
| 61 |
url, pos = text.extract(page, '<img src="', '"') |
| 62 |
yield text.ensure_http_scheme(text.unescape(url)), None |
| 63 |
url, pos = text.extract(page, ' src="', '"', pos) |
| 64 |
yield text.ensure_http_scheme(text.unescape(url)), None |
| 65 |
pnum += 2 |
| 66 |
page = self.request(f"{self.base}{pnum}.html").text |
| 67 |
|
| 68 |
def _get_title(self): |
| 69 |
url = f"{self.root}/manga/{self.part}/" |
| 70 |
page = self.request(url).text |
| 71 |
|
| 72 |
try: |
| 73 |
pos = page.index(self.part) + len(self.part) |
| 74 |
pos = page.index(self.part, pos) + len(self.part) |
| 75 |
return text.extract(page, ' title="', '"', pos)[0] |
| 76 |
except ValueError: |
| 77 |
return "" |
| 78 |
|
| 79 |
|
| 80 |
class MangahereMangaExtractor(MangahereBase, MangaExtractor): |
| 81 |
"""Extractor for manga from mangahere.cc""" |
| 82 |
chapterclass = MangahereChapterExtractor |
| 83 |
pattern = (r"(?:https?://)?(?:www\.|m\.)?mangahere\.c[co]" |
| 84 |
r"(/manga/[^/?#]+/?)(?:#.*)?$") |
| 85 |
example = "https://www.mangahere.cc/manga/TITLE" |
| 86 |
|
| 87 |
def _init(self): |
| 88 |
self.cookies.set("isAdult", "1", domain="www.mangahere.cc") |
| 89 |
|
| 90 |
def chapters(self, page): |
| 91 |
results = [] |
| 92 |
manga, pos = text.extract(page, '<meta name="og:title" content="', '"') |
| 93 |
manga = text.unescape(manga) |
| 94 |
|
| 95 |
page = text.extract( |
| 96 |
page, 'id="chapterlist"', 'class="detail-main-list-more"', pos)[0] |
| 97 |
pos = 0 |
| 98 |
while True: |
| 99 |
url, pos = text.extract(page, ' href="', '"', pos) |
| 100 |
if not url: |
| 101 |
return results |
| 102 |
info, pos = text.extract(page, 'class="title3">', '<', pos) |
| 103 |
date, pos = text.extract(page, 'class="title2">', '<', pos) |
| 104 |
|
| 105 |
match = text.re( |
| 106 |
r"(?:Vol\.0*(\d+) )?Ch\.0*(\d+)(\S*)(?: - (.*))?").match(info) |
| 107 |
if match: |
| 108 |
volume, chapter, minor, title = match.groups() |
| 109 |
else: |
| 110 |
chapter, _, minor = url[:-1].rpartition("/c")[2].partition(".") |
| 111 |
minor = "." + minor |
| 112 |
volume = 0 |
| 113 |
title = "" |
| 114 |
|
| 115 |
results.append((text.urljoin(self.root, url), { |
| 116 |
"manga": manga, |
| 117 |
"title": text.unescape(title) if title else "", |
| 118 |
"volume": text.parse_int(volume), |
| 119 |
"chapter": text.parse_int(chapter), |
| 120 |
"chapter_minor": minor, |
| 121 |
"date": date, |
| 122 |
"lang": "en", |
| 123 |
"language": "English", |
| 124 |
})) |