| 1 |
|
| 2 |
|
| 3 |
n |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
"""Extractors for https://mangareader.to/""" |
| 10 |
|
| 11 |
from .common import ChapterExtractor, MangaExtractor |
| 12 |
from .. import text, util |
| 13 |
|
| 14 |
BASE_PATTERN = r"(?:https?://)?(?:www\.)?mangareader\.to" |
| 15 |
|
| 16 |
|
| 17 |
class MangareaderBase(): |
| 18 |
"""Base class for mangareader extractors""" |
| 19 |
category = "mangareader" |
| 20 |
root = "https://mangareader.to" |
| 21 |
|
| 22 |
def _manga_info(self, manga_path): |
| 23 |
url = f"{self.root}/{manga_path}" |
| 24 |
html = self.request(url).text |
| 25 |
|
| 26 |
slug, _, mid = manga_path.rpartition("-") |
| 27 |
extr = text.extract_from(html) |
| 28 |
url = extr('property="og:url" content="', '"') |
| 29 |
manga = { |
| 30 |
"manga_url": url, |
| 31 |
"manga_slug": url.rpartition("/")[2].rpartition("-")[0], |
| 32 |
"manga_id": text.parse_int(mid), |
| 33 |
"manga": text.unescape(extr('class="manga-name">', "<")), |
| 34 |
"manga_alt": text.unescape(extr('class="manga-name-or">', "<")), |
| 35 |
"tags": text.split_html(extr('class="genres">', "</div>")), |
| 36 |
"type": text.remove_html(extr('>Type:', "</div>")), |
| 37 |
"status": text.remove_html(extr('>Status:', "</div>")), |
| 38 |
"author": text.split_html(extr('>Authors:', "</div>"))[0::2], |
| 39 |
"published": text.remove_html(extr('>Published:', "</div>")), |
| 40 |
"score": text.parse_float(text.remove_html(extr( |
| 41 |
'>Score:', "</div>"))), |
| 42 |
"views": text.parse_int(text.remove_html(extr( |
| 43 |
'>Views:', "</div>")).replace(",", "")), |
| 44 |
} |
| 45 |
|
| 46 |
base = self.root |
| 47 |
|
| 48 |
|
| 49 |
html = extr('class="chapters-list-ul">', " </div>") |
| 50 |
manga["_chapters"] = chapters = {} |
| 51 |
for group in text.extract_iter(html, "<ul", "</ul>"): |
| 52 |
lang = text.extr(group, ' id="', '-chapters"') |
| 53 |
|
| 54 |
chapters[lang] = current = {} |
| 55 |
lang = lang.partition("-")[0] |
| 56 |
for ch in text.extract_iter(group, "<li ", "</li>"): |
| 57 |
path = text.extr(ch, 'href="', '"') |
| 58 |
chap = text.extr(ch, 'data-number="', '"') |
| 59 |
name = text.unescape(text.extr(ch, 'class="name">', "<")) |
| 60 |
|
| 61 |
chapter, sep, minor = chap.partition(".") |
| 62 |
current[chap] = { |
| 63 |
"title" : name.partition(":")[2].strip(), |
| 64 |
"chapter" : text.parse_int(chapter), |
| 65 |
"chapter_minor" : sep + minor, |
| 66 |
"chapter_string": chap, |
| 67 |
"chapter_url" : base + path, |
| 68 |
"lang" : lang, |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
html = extr('class="volume-list-ul">', "</section>") |
| 73 |
manga["_volumes"] = volumes = {} |
| 74 |
for group in html.split('<div class="manga_list-wrap')[1:]: |
| 75 |
lang = text.extr(group, ' id="', '-volumes"') |
| 76 |
|
| 77 |
volumes[lang] = current = {} |
| 78 |
lang = lang.partition("-")[0] |
| 79 |
for vol in text.extract_iter(group, 'class="item">', "</div>"): |
| 80 |
path = text.extr(vol, 'href="', '"') |
| 81 |
voln = text.extr(vol, 'tick-vol">', '<').rpartition(" ")[2] |
| 82 |
|
| 83 |
current[voln] = { |
| 84 |
"volume" : text.parse_int(voln), |
| 85 |
"volume_cover" : text.extr(vol, ' src="', '"'), |
| 86 |
"chapter" : 0, |
| 87 |
"chapter_minor" : "", |
| 88 |
"chapter_string": voln, |
| 89 |
"chapter_url" : base + path, |
| 90 |
"lang" : lang, |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
manga["description"] = text.unescape(extr( |
| 95 |
'class="description-modal">', "</div>")).strip() |
| 96 |
|
| 97 |
return manga |
| 98 |
|
| 99 |
|
| 100 |
class MangareaderChapterExtractor(MangareaderBase, ChapterExtractor): |
| 101 |
"""Extractor for mangareader manga chapters""" |
| 102 |
directory_fmt = ( |
| 103 |
"{category}", "{manga}", |
| 104 |
"{volume:?v/ />02}{chapter:?c//>03}{chapter_minor:?//}{title:?: //}") |
| 105 |
filename_fmt = ( |
| 106 |
"{manga}{volume:?_v//>02}{chapter:?_c//>03}{chapter_minor:?//}_" |
| 107 |
"{page:>03}.{extension}") |
| 108 |
archive_fmt = ( |
| 109 |
"{manga_id}_{chapter_id}_{page}") |
| 110 |
pattern = (BASE_PATTERN + r"/read/([\w-]+-\d+)/([^/?#]+)" |
| 111 |
r"/(chapter|volume)-(\d+[^/?#]*)") |
| 112 |
example = "https://mangareader.to/read/MANGA-123/LANG/chapter-123" |
| 113 |
|
| 114 |
def metadata(self, _): |
| 115 |
path, lang, type, chstr = self.groups |
| 116 |
|
| 117 |
settings = util.json_dumps({ |
| 118 |
"readingMode" : "vertical", |
| 119 |
"readingDirection": "rtl", |
| 120 |
"quality" : "high", |
| 121 |
}) |
| 122 |
self.cookies.set("mr_settings", settings, domain="mangareader.to") |
| 123 |
|
| 124 |
url = f"{self.root}/read/{path}/{lang}/{type}-{chstr}" |
| 125 |
page = self.request(url).text |
| 126 |
self.cid = cid = text.extr(page, 'data-reading-id="', '"') |
| 127 |
|
| 128 |
manga = self.cache(self._manga_info, path) |
| 129 |
return { |
| 130 |
**manga, |
| 131 |
**manga[f"_{type}s"][lang][chstr], |
| 132 |
"chapter_id": text.parse_int(cid), |
| 133 |
} |
| 134 |
|
| 135 |
def images(self, page): |
| 136 |
key = "chap" if self.groups[2] == "chapter" else "vol" |
| 137 |
url = f"{self.root}/ajax/image/list/{key}/{self.cid}" |
| 138 |
params = { |
| 139 |
"mode" : "vertical,", |
| 140 |
"quality" : "high,", |
| 141 |
"hozPageSize": "1,", |
| 142 |
} |
| 143 |
headers = { |
| 144 |
"X-Requested-With": "XMLHttpRequest", |
| 145 |
} |
| 146 |
html = self.request_json(url, params=params, headers=headers)["html"] |
| 147 |
|
| 148 |
return [ |
| 149 |
(url, None) |
| 150 |
for url in text.extract_iter(html, 'data-url="', '"') |
| 151 |
] |
| 152 |
|
| 153 |
|
| 154 |
class MangareaderMangaExtractor(MangareaderBase, MangaExtractor): |
| 155 |
"""Extractor for mangareader manga""" |
| 156 |
chapterclass = MangareaderChapterExtractor |
| 157 |
pattern = BASE_PATTERN + r"/([\w-]+-\d+)" |
| 158 |
example = "https://mangareader.to/MANGA-123" |
| 159 |
|
| 160 |
def chapters(self, page): |
| 161 |
manga = self.cache(self._manga_info, self.groups[0]) |
| 162 |
lang = self.config("lang") or "en" |
| 163 |
|
| 164 |
return [ |
| 165 |
(info["chapter_url"], {**manga, **info}) |
| 166 |
for info in manga["_chapters"][lang].values() |
| 167 |
] |