feat: filtre par groupe MangaDex (ex. Keiyoushi) + keiyoushi.github.io bloqué (SCAL-13)
- list-groups / --group via API officielle MangaDex (groups[]), résolution nom -> UUID - keiyoushi.github.io et keiyoushi.com ajoutés à la liste de blocage legal-source-check - tests: stub fetcher MangaDex (params groups[]/translatedLanguage[]), blocage keiyoushi
This commit is contained in:
1 parent
041e55b669
commit
5177ddedc5
10 files changed
+160
-29
No files matched your search
+34
-5
@@ -1,4 +1,4 @@
|
||||
"""CLI Scalper : check-source, list-series, list-chapters, fetch, clean, translate, qa, export, run."""
|
||||
"""CLI Scalper : check-source, list-series, list-groups, list-chapters, fetch, clean, translate, qa, export, run."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -30,10 +30,17 @@ def main(argv: list[str] | None = None) -> int:
|
||||
|
||||
c = sub.add_parser("list-series", help="liste les séries d'une source")
|
||||
c.add_argument("source")
|
||||
c.add_argument("--query", default="")
|
||||
|
||||
c = sub.add_parser("list-chapters", help="liste les chapitres d'une série")
|
||||
c = sub.add_parser("list-groups", help="liste les groupes de scanlation (source mangadex uniquement)")
|
||||
c.add_argument("source")
|
||||
c.add_argument("--query", default="")
|
||||
|
||||
c = sub.add_parser("list-chapters", help="liste les chapitres d'une série (--group pour filtrer par groupe, ex. Keiyoushi)")
|
||||
c.add_argument("source")
|
||||
c.add_argument("series")
|
||||
c.add_argument("--group", default=None, help="nom ou UUID du groupe (mangadex)")
|
||||
c.add_argument("--lang", default="en", help="langue des chapitres (mangadex), '' pour toutes")
|
||||
|
||||
c = sub.add_parser("fetch", help="télécharge un chapitre brut")
|
||||
c.add_argument("source")
|
||||
@@ -68,6 +75,7 @@ def main(argv: list[str] | None = None) -> int:
|
||||
c.add_argument("--source", required=True)
|
||||
c.add_argument("--series", required=True)
|
||||
c.add_argument("--lang", required=True)
|
||||
c.add_argument("--group", default=None, help="filtrer par groupe (mangadex)")
|
||||
c.add_argument("--out", default="out")
|
||||
c.add_argument("--max-chapters", type=int, default=None)
|
||||
c.add_argument("--mock-llm", action="store_true", help="démo hors ligne (LLM factice)")
|
||||
@@ -79,11 +87,28 @@ def main(argv: list[str] | None = None) -> int:
|
||||
return 0
|
||||
if args.cmd == "list-series":
|
||||
adapter = get_adapter(args.source)
|
||||
series = adapter.list_series() if args.source == "demo" else adapter.list_series(query="")
|
||||
series = adapter.list_series(query=args.query) if args.source == "mangadex" else adapter.list_series()
|
||||
_print([s.to_dict() for s in series])
|
||||
return 0
|
||||
if args.cmd == "list-groups":
|
||||
if args.source != "mangadex":
|
||||
print("list-groups est disponible uniquement pour la source 'mangadex'", file=sys.stderr)
|
||||
return 1
|
||||
from .sources.mangadex import MangaDexAdapter
|
||||
|
||||
_print(MangaDexAdapter(fetcher=RespectfulFetcher()).list_groups(args.query))
|
||||
return 0
|
||||
if args.cmd == "list-chapters":
|
||||
_print([c.to_dict() for c in get_adapter(args.source).list_chapters(args.series)])
|
||||
adapter = get_adapter(args.source)
|
||||
kwargs: dict = {}
|
||||
if args.group:
|
||||
if args.source != "mangadex":
|
||||
print("--group est disponible uniquement pour la source 'mangadex'", file=sys.stderr)
|
||||
return 1
|
||||
kwargs["group"] = args.group
|
||||
if args.source == "mangadex":
|
||||
kwargs["lang"] = args.lang or None
|
||||
_print([c.to_dict() for c in adapter.list_chapters(args.series, **kwargs)])
|
||||
return 0
|
||||
if args.cmd == "fetch":
|
||||
adapter = get_adapter(args.source, fetcher=RespectfulFetcher())
|
||||
@@ -125,7 +150,11 @@ def main(argv: list[str] | None = None) -> int:
|
||||
_print({"exported": str(path)})
|
||||
return 0
|
||||
if args.cmd == "run":
|
||||
summary = pipeline.run_pipeline(args.source, args.series, args.lang, out_root=Path(args.out), mock_llm=args.mock_llm, max_chapters=args.max_chapters)
|
||||
summary = pipeline.run_pipeline(
|
||||
args.source, args.series, args.lang,
|
||||
out_root=Path(args.out), mock_llm=args.mock_llm,
|
||||
max_chapters=args.max_chapters, group=args.group,
|
||||
)
|
||||
_print(summary)
|
||||
return 0 if summary.get("status") == "done" else 3
|
||||
return 1
|
||||
|
||||
@@ -19,8 +19,10 @@ USER_AGENT = "Scalper/1.0 (+https://github.com/Orionis312050/Scalper)"
|
||||
|
||||
BLOCKED_DOMAINS: dict[str, str] = {
|
||||
"mangas-origines.fr": "site de scanlation non autorisé (contrefaçon de mangas commerciaux)",
|
||||
"keiyoushi.github.io": "index d'extensions Keiyoushi pointant vers des sites de scanlation non autorisés",
|
||||
"keiyoushi.com": "dépôt d'extensions Keiyoushi pointant vers des sites de scanlation non autorisés",
|
||||
}
|
||||
BLOCKED_SUBSTRINGS = ("mangas-origines",)
|
||||
BLOCKED_SUBSTRINGS = ("mangas-origines", "keiyoushi.github.io", "keiyoushi.com")
|
||||
|
||||
TRUSTED_SOURCES: dict[str, dict[str, str]] = {
|
||||
"api.mangadex.org": {
|
||||
|
||||
@@ -25,6 +25,7 @@ def run_pipeline(
|
||||
mock_llm: bool = False,
|
||||
fetcher: RespectfulFetcher | None = None,
|
||||
max_chapters: int | None = None,
|
||||
group: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
out_root = Path(out_root)
|
||||
verdict = legal.check_source(source_id)
|
||||
@@ -33,7 +34,7 @@ def run_pipeline(
|
||||
|
||||
fetcher = fetcher or RespectfulFetcher(min_delay=1.0)
|
||||
adapter = get_adapter(source_id, fetcher=fetcher)
|
||||
chapters = adapter.list_chapters(series_id)
|
||||
chapters = adapter.list_chapters(series_id, **({"group": group} if group else {}))
|
||||
if max_chapters is not None:
|
||||
chapters = chapters[:max_chapters]
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ class SourceAdapter(Protocol):
|
||||
|
||||
def list_series(self) -> list[Series]: ...
|
||||
|
||||
def list_chapters(self, series_id: str) -> list[ChapterRef]: ...
|
||||
def list_chapters(self, series_id: str, **kwargs) -> list[ChapterRef]: ...
|
||||
|
||||
def fetch_chapter(self, chapter: ChapterRef, dest_dir: Path) -> None:
|
||||
"""Télécharge le chapitre brut (HTML + images) dans dest_dir."""
|
||||
|
||||
@@ -27,7 +27,7 @@ class DemoAdapter:
|
||||
idx = self._index()
|
||||
return [Series(id=s["id"], title=s["title"], url=s["url"], license=self.license) for s in idx["series"]]
|
||||
|
||||
def list_chapters(self, series_id: str) -> list[ChapterRef]:
|
||||
def list_chapters(self, series_id: str, **kwargs) -> list[ChapterRef]:
|
||||
idx = self._index()
|
||||
chapters = idx["chapters"].get(series_id, [])
|
||||
return [
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
"""Adaptateur API officielle MangaDex (https://api.mangadex.org) — source légale.
|
||||
|
||||
L'API publique ne nécessite pas de clé pour la lecture. Rate limiting appliqué.
|
||||
Permet de filtrer les chapitres par groupe de scanlation (ex. Keiyoushi) via le
|
||||
paramètre groups[] — la voie légale pour suivre un groupe donné.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from ..models import ChapterRef, Series
|
||||
from ..scraper import RespectfulFetcher
|
||||
|
||||
API = "https://api.mangadex.org"
|
||||
|
||||
_UUID_RE = re.compile(r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")
|
||||
|
||||
|
||||
class MangaDexAdapter:
|
||||
id = "mangadex"
|
||||
@@ -21,16 +27,14 @@ class MangaDexAdapter:
|
||||
def __init__(self, fetcher: RespectfulFetcher | None = None) -> None:
|
||||
self.fetcher = fetcher or RespectfulFetcher(min_delay=1.0)
|
||||
|
||||
def _get_json(self, path: str, params: dict[str, str] | None = None) -> dict:
|
||||
def _get_json(self, path: str, params: dict[str, object] | None = None) -> dict:
|
||||
url = API + path
|
||||
if params:
|
||||
from urllib.parse import urlencode
|
||||
|
||||
url += "?" + urlencode(params)
|
||||
url += "?" + urlencode(params, doseq=True)
|
||||
return json.loads(self.fetcher.get(url).decode("utf-8"))
|
||||
|
||||
def list_series(self, query: str = "", limit: int = 20) -> list[Series]:
|
||||
params = {"limit": str(limit), "order[relevance]": "desc", "includes[]": "cover_art"}
|
||||
params: dict[str, object] = {"limit": limit, "order[relevance]": "desc", "includes[]": "cover_art"}
|
||||
if query:
|
||||
params["title"] = query
|
||||
data = self._get_json("/manga", params)
|
||||
@@ -44,17 +48,35 @@ class MangaDexAdapter:
|
||||
for m in data.get("data", [])
|
||||
]
|
||||
|
||||
def list_chapters(self, series_id: str, limit: int = 100) -> list[ChapterRef]:
|
||||
data = self._get_json(
|
||||
f"/manga/{series_id}/feed",
|
||||
{
|
||||
"limit": str(limit),
|
||||
"translatedLanguage[]": "en",
|
||||
"order[chapter]": "asc",
|
||||
"contentRating[]": "safe",
|
||||
"contentRating[]": "suggestive",
|
||||
},
|
||||
)
|
||||
def list_groups(self, query: str = "", limit: int = 20) -> list[dict]:
|
||||
"""Recherche des groupes de scanlation par nom (ex. 'Keiyoushi')."""
|
||||
params: dict[str, object] = {"limit": limit, "order[name]": "asc"}
|
||||
if query:
|
||||
params["name"] = query
|
||||
data = self._get_json("/group", params)
|
||||
return [{"id": g["id"], "name": g["attributes"]["name"]} for g in data.get("data", [])]
|
||||
|
||||
def resolve_group(self, name_or_id: str) -> str:
|
||||
if _UUID_RE.match(name_or_id):
|
||||
return name_or_id
|
||||
groups = self.list_groups(name_or_id)
|
||||
if not groups:
|
||||
raise KeyError(f"groupe introuvable sur MangaDex: {name_or_id}")
|
||||
exact = next((g for g in groups if g["name"].lower() == name_or_id.lower()), None)
|
||||
return (exact or groups[0])["id"]
|
||||
|
||||
def list_chapters(self, series_id: str, limit: int = 100, group: str | None = None, lang: str | None = "en") -> list[ChapterRef]:
|
||||
params: dict[str, object] = {
|
||||
"limit": limit,
|
||||
"order[chapter]": "asc",
|
||||
"contentRating[]": ["safe", "suggestive"],
|
||||
"includeFutureUpdates": "0",
|
||||
}
|
||||
if lang:
|
||||
params["translatedLanguage[]"] = [lang]
|
||||
if group:
|
||||
params["groups[]"] = [self.resolve_group(group)]
|
||||
data = self._get_json(f"/manga/{series_id}/feed", params)
|
||||
refs = []
|
||||
for c in data.get("data", []):
|
||||
attrs = c["attributes"]
|
||||
@@ -76,13 +98,12 @@ class MangaDexAdapter:
|
||||
attrs = data["data"]["attributes"]
|
||||
chapter_hash = attrs["hash"]
|
||||
pages = attrs.get("pages", 0)
|
||||
files = attrs.get("data", []) + attrs.get("dataSaver", [])
|
||||
files = attrs.get("data", [])
|
||||
lines = [f"# raw chapter {chapter.id} ({chapter.title})", ""]
|
||||
img_dir = dest_dir / "images"
|
||||
img_dir.mkdir(exist_ok=True)
|
||||
quality = "data-saver" if attrs.get("dataSaver") else "data"
|
||||
for i, fname in enumerate(files, start=1):
|
||||
url = f"{base}/{quality}/{chapter_hash}/{fname}"
|
||||
url = f"{base}/data/{chapter_hash}/{fname}"
|
||||
(img_dir / fname).write_bytes(self.fetcher.get(url))
|
||||
lines.append(f"")
|
||||
(dest_dir / "raw.html").write_text("\n".join(lines), encoding="utf-8")
|
||||
|
||||
Reference in new issue
Block a user