[mangataro] fix 'manga' extractor (#8930)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2025 Mike Fährmann
|
||||
# Copyright 2025-2026 Mike Fährmann
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License version 2 as
|
||||
@@ -11,6 +11,8 @@
|
||||
from .common import ChapterExtractor, MangaExtractor
|
||||
from .. import text
|
||||
from ..cache import memcache
|
||||
import hashlib
|
||||
import time
|
||||
|
||||
BASE_PATTERN = r"(?:https?://)?mangataro\.org"
|
||||
|
||||
@@ -59,27 +61,56 @@ class MangataroChapterExtractor(MangataroBase, ChapterExtractor):
|
||||
class MangataroMangaExtractor(MangataroBase, MangaExtractor):
|
||||
"""Extractor for mangataro manga"""
|
||||
chapterclass = MangataroChapterExtractor
|
||||
pattern = BASE_PATTERN + r"(/manga/([^/?#]+))"
|
||||
pattern = BASE_PATTERN + r"/manga/([^/?#]+)"
|
||||
example = "https://mangataro.org/manga/MANGA"
|
||||
|
||||
def chapters(self, page):
|
||||
slug = self.groups[1]
|
||||
manga = _manga_info(self, slug)
|
||||
def chapters(self, _):
|
||||
manga = _manga_info(self, self.groups[0])
|
||||
|
||||
url = self.root + "/auth/manga-chapters"
|
||||
params = {
|
||||
"manga_id": manga["manga_id"],
|
||||
"offset" : 0,
|
||||
"limit" : 500, # values higher than 500 have no effect
|
||||
"order" : "DESC",
|
||||
}
|
||||
headers = {
|
||||
"Referer" : manga["manga_url"],
|
||||
"Sec-Fetch-Dest": "empty",
|
||||
"Sec-Fetch-Mode": "cors",
|
||||
"Sec-Fetch-Site": "same-origin",
|
||||
}
|
||||
|
||||
results = []
|
||||
for url in text.extract_iter(text.extr(
|
||||
page, '<div class="chapter-list', '<div id="tab-gallery"'),
|
||||
'<a href="', '"'):
|
||||
chapter, _, chapter_id = url[url.rfind("/")+3:].rpartition("-")
|
||||
chapter, sep, minor = chapter.partition("-")
|
||||
results.append((url, {
|
||||
**manga,
|
||||
"chapter" : text.parse_int(chapter),
|
||||
"chapter_minor": "." + minor if sep else "",
|
||||
"chapter_id" : text.parse_int(chapter_id),
|
||||
}))
|
||||
while True:
|
||||
self._update_params(params)
|
||||
data = self.request_json(url, params=params, headers=headers)
|
||||
|
||||
for ch in data["chapters"]:
|
||||
chapter, sep, minor = ch["chapter"].partition(".")
|
||||
results.append((ch["url"], {
|
||||
**manga,
|
||||
"chapter_id" : text.parse_int(ch.pop("id", None)),
|
||||
**ch,
|
||||
"chapter" : text.parse_int(chapter),
|
||||
"chapter_minor": "." + minor if sep else "",
|
||||
}))
|
||||
|
||||
if not data.get("has_more"):
|
||||
break
|
||||
params["offset"] += (data.get("limit") or params["limit"])
|
||||
return results
|
||||
|
||||
def _update_params(self, params):
|
||||
# adapted from dazedcat19/FMD2
|
||||
# https://github.com/dazedcat19/FMD2/blob/master/lua/modules/MangaTaro.lua
|
||||
if (ts := int(time.time())) == params.get("_ts"):
|
||||
return
|
||||
Y, m, d, H, _, _, _, _, _ = time.gmtime(ts)
|
||||
secret = f"{ts}mng_ch_{Y:>04}{m:>02}{d:>02}{H:>02}"
|
||||
params["_t"] = hashlib.md5(secret.encode()).hexdigest()[:16]
|
||||
params["_ts"] = ts
|
||||
|
||||
|
||||
@memcache(keyarg=1)
|
||||
def _manga_info(self, slug):
|
||||
@@ -89,6 +120,7 @@ def _manga_info(self, slug):
|
||||
|
||||
return {
|
||||
"manga" : manga["name"].rpartition(" | ")[0].rpartition(" ")[0],
|
||||
"manga_id" : text.extr(page, 'data-manga-id="', '"'),
|
||||
"manga_url" : manga["url"],
|
||||
"cover" : manga["image"],
|
||||
"author" : manga["author"]["name"].split(", "),
|
||||
|
||||
Reference in New Issue
Block a user