[mangatown] fix & update

- use BASE_PATTERN
- fix manga, manga_id, chapter_id extraction
- fix & extend 'manga' metadata results
- extend test results
This commit is contained in:
Mike Fährmann
2026-01-25 18:32:17 +01:00
parent befa9b8a3e
commit bf3ee5e9f7
2 changed files with 52 additions and 38 deletions

View File

@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2015-2025 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation. # published by the Free Software Foundation.
@@ -11,6 +9,8 @@
from .common import ChapterExtractor, MangaExtractor from .common import ChapterExtractor, MangaExtractor
from .. import text from .. import text
BASE_PATTERN = r"(?:https?://)?(?:www\.)?mangatown\.com"
class MangatownBase(): class MangatownBase():
"""Base class for mangatown extractors""" """Base class for mangatown extractors"""
@@ -20,34 +20,32 @@ class MangatownBase():
class MangatownChapterExtractor(MangatownBase, ChapterExtractor): class MangatownChapterExtractor(MangatownBase, ChapterExtractor):
"""Extractor for manga-chapters from mangatown.com""" """Extractor for manga-chapters from mangatown.com"""
pattern = (r"(?:https?://)?(?:www\.)?mangatown\.com" pattern = BASE_PATTERN + r"(/manga/[^/?#]+(?:/v0*(\d+))?/c(\d+[^/?#]*))"
r"(/manga/[^/]+(?:/v0*(\d+))?/c(\d+[^/?#]*))")
example = "https://www.mangatown.com/manga/TITLE/c001/1.html" example = "https://www.mangatown.com/manga/TITLE/c001/1.html"
def __init__(self, match): def __init__(self, match):
self.part, self.volume, self.chapter = match.groups() self.part, self.volume, self.chapter = match.groups()
self.base = self.root + self.part + "/" self.base = f"{self.root}{self.part}/"
ChapterExtractor.__init__(self, match, self.base + "1.html") ChapterExtractor.__init__(self, match, self.base + "1.html")
def metadata(self, page): def metadata(self, page):
manga, pos = text.extract(page, '<title>', '</title>') manga, pos = text.extract(
manga = manga.partition(" Manga")[0].replace("Read ", "", 1) page, 'property="og:title" content="', '"')
count , pos = text.extract(page, "total_pages = ", ";", pos) count , pos = text.extract(page, "total_pages = ", ";", pos)
manga_id , pos = text.extract(page, "series_id = ", ";", pos) manga_id , pos = text.extract(page, "series_id=", ";", pos)
chapter_id, pos = text.extract(page, "chapter_id = ", ";", pos) chapter_id, pos = text.extract(page, "chapter_id=", ";", pos)
chapter, dot, minor = self.chapter.partition(".") chapter, dot, minor = self.chapter.partition(".")
return { return {
"manga": text.unescape(manga), "manga" : text.unescape(manga),
"manga_id": text.parse_int(manga_id), "manga_id": text.parse_int(manga_id),
"volume": text.parse_int(self.volume), "volume" : text.parse_int(self.volume),
"chapter": text.parse_int(chapter), "chapter" : text.parse_int(chapter),
"chapter_minor": dot + minor, "chapter_minor": dot + minor,
"chapter_id": text.parse_int(chapter_id), "chapter_id": text.parse_int(chapter_id),
"count": text.parse_int(count), "count" : text.parse_int(count),
"lang": "en", "lang" : "en",
"language": "English", "language": "English",
} }
@@ -67,8 +65,7 @@ class MangatownChapterExtractor(MangatownBase, ChapterExtractor):
class MangatownMangaExtractor(MangatownBase, MangaExtractor): class MangatownMangaExtractor(MangatownBase, MangaExtractor):
"""Extractor for manga from mangatown.com""" """Extractor for manga from mangatown.com"""
chapterclass = MangatownChapterExtractor chapterclass = MangatownChapterExtractor
pattern = (r"(?:https?://)?(?:www\.)?mangatown\.com" pattern = BASE_PATTERN + r"(/manga/[^/?#]+)"
r"(/manga/[^/?#]+)/?$")
example = "https://www.mangatown.com/manga/TITLE" example = "https://www.mangatown.com/manga/TITLE"
def chapters(self, page): def chapters(self, page):
@@ -78,23 +75,22 @@ class MangatownMangaExtractor(MangatownBase, MangaExtractor):
manga = manga.partition(" Manga")[0].replace("Read ", "", 1) manga = manga.partition(" Manga")[0].replace("Read ", "", 1)
manga = text.unescape(manga) manga = text.unescape(manga)
page = text.extract( page = text.extract(page, 'class="chapter_list"', '</ul>', pos)[0]
page, 'class="chapter_list"', '</ul>', pos)[0] for ch in text.extract_iter(page, "<li>", "</li>"):
path , pos = text.extract(ch, '<a href="', '"')
title, pos = text.extract(ch, "<span>", "<", pos)
date , pos = text.extract(ch, 'class="time">', "<", pos)
pos = 0 chapter = text.extr(path, "/c", "/")
while True: chapter, sep, minor = chapter.partition(".")
url, pos = text.extract(page, '<a href="', '"', pos)
if not url:
return results
url = text.urljoin(self.root, url)
title, pos = text.extract(page, '>', '<', pos)
date , pos = text.extract(page, 'class="time"', '</span>', pos)
date = text.remove_html(date).strip()
results.append((url, { results.append((self.root + path, {
"manga": manga, "manga" : manga,
"title": text.unescape(title), "chapter" : text.parse_int(chapter),
"date": date, "chapter_minor": sep + minor,
"lang": "en", "title" : "" if title is None else text.unescape(title),
"date" : date,
"lang" : "en",
"language": "English", "language": "English",
})) }))
return results

View File

@@ -10,36 +10,54 @@ from gallery_dl.extractor import mangatown
__tests__ = ( __tests__ = (
{ {
"#url" : "https://www.mangatown.com/manga/kimetsu_no_yaiba/c001/", "#url" : "https://www.mangatown.com/manga/kimetsu_no_yaiba/c001/",
"#category": ("", "mangatown", "chapter"),
"#class" : mangatown.MangatownChapterExtractor, "#class" : mangatown.MangatownChapterExtractor,
"#pattern" : r"https://zjcdn\.mangahere\.org/.*", "#pattern" : r"https://zjcdn\.mangahere\.org/.*",
"#count" : ">= 20", "#count" : ">= 20",
"chapter" : 1,
"chapter_id" : 368511,
"chapter_minor": "",
"count" : 55,
"page" : range(1, 55),
"extension" : "jpg",
"filename" : str,
"lang" : "en",
"language" : "English",
"manga" : "Kimetsu no Yaiba",
"manga_id" : 21437,
"volume" : 0,
}, },
{ {
"#url" : "https://www.mangatown.com/manga/kimetsu_no_yaiba/c001/1.html", "#url" : "https://www.mangatown.com/manga/kimetsu_no_yaiba/c001/1.html",
"#category": ("", "mangatown", "chapter"),
"#class" : mangatown.MangatownChapterExtractor, "#class" : mangatown.MangatownChapterExtractor,
"#pattern" : r"https://zjcdn\.mangahere\.org/.*", "#pattern" : r"https://zjcdn\.mangahere\.org/.*",
}, },
{ {
"#url" : "http://www.mangatown.com/manga/kimetsu_no_yaiba/c001/", "#url" : "http://www.mangatown.com/manga/kimetsu_no_yaiba/c001/",
"#category": ("", "mangatown", "chapter"),
"#class" : mangatown.MangatownChapterExtractor, "#class" : mangatown.MangatownChapterExtractor,
}, },
{ {
"#url" : "https://www.mangatown.com/manga/kimetsu_no_yaiba/", "#url" : "https://www.mangatown.com/manga/kimetsu_no_yaiba/",
"#category": ("", "mangatown", "manga"),
"#class" : mangatown.MangatownMangaExtractor, "#class" : mangatown.MangatownMangaExtractor,
"#pattern" : mangatown.MangatownChapterExtractor.pattern, "#pattern" : mangatown.MangatownChapterExtractor.pattern,
"#count" : ">= 100", "#count" : ">= 100",
"chapter" : int,
"chapter_minor": {"", ".5", ".6"},
"date" : str,
"lang" : "en",
"language" : "English",
"manga" : "Kimetsu no Yaiba",
"title" : str,
}, },
{ {
"#url" : "http://www.mangatown.com/manga/kimetsu_no_yaiba/", "#url" : "http://www.mangatown.com/manga/kimetsu_no_yaiba/",
"#category": ("", "mangatown", "manga"),
"#class" : mangatown.MangatownMangaExtractor, "#class" : mangatown.MangatownMangaExtractor,
}, },