# -*- coding: utf-8 -*- # 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 # published by the Free Software Foundation. """Extractors for https://mangaread.org/""" from .common import ChapterExtractor, MangaExtractor from .. import text, exception import re class MangareadBase(): """Base class for Mangaread extractors""" category = "mangaread" root = "https://www.mangaread.org" @staticmethod def parse_chapter_string(chapter_string, data): match = re.match( r"(?:(.+)\s*-\s*)?[Cc]hapter\s*(\d+)(\.\d+)?(?:\s*-\s*(.+))?", text.unescape(chapter_string).strip()) manga, chapter, minor, title = match.groups() manga = manga.strip() if manga else "" data["manga"] = data.pop("manga", manga) data["chapter"] = text.parse_int(chapter) data["chapter_minor"] = minor or "" data["title"] = title or "" data["lang"] = "en" data["language"] = "English" class MangareadChapterExtractor(MangareadBase, ChapterExtractor): """Extractor for manga-chapters from mangaread.org""" pattern = (r"(?:https?://)?(?:www\.)?mangaread\.org" r"(/manga/[^/?#]+/[^/?#]+)") test = ( ("https://www.mangaread.org/manga/one-piece/chapter-1053-3/", { "pattern": (r"https://www\.mangaread\.org/wp-content/uploads" r"/WP-manga/data/manga_[^/]+/[^/]+/[^.]+\.\w+"), "count": 11, "keyword": { "manga" : "One Piece", "title" : "", "chapter" : 1053, "chapter_minor": ".3", "tags" : ["Oda Eiichiro"], "lang" : "en", "language": "English", } }), ("https://www.mangaread.org/manga/one-piece/chapter-1000000/", { "exception": exception.NotFoundError, }), (("https://www.mangaread.org" "/manga/kanan-sama-wa-akumade-choroi/chapter-10/"), { "pattern": (r"https://www\.mangaread\.org/wp-content/uploads" r"/WP-manga/data/manga_[^/]+/[^/]+/[^.]+\.\w+"), "count": 9, "keyword": { "manga" : "Kanan-sama wa Akumade Choroi", "title" : "", "chapter" : 10, "chapter_minor": "", "tags" : list, "lang" : "en", "language": "English", } }), # 'Chapter146.5' # ^^ no whitespace ("https://www.mangaread.org/manga/above-all-gods/chapter146-5/", { "pattern": (r"https://www\.mangaread\.org/wp-content/uploads" r"/WP-manga/data/manga_[^/]+/[^/]+/[^.]+\.\w+"), "count": 6, "keyword": { "manga" : "Above All Gods", "title" : "", "chapter" : 146, "chapter_minor": ".5", "tags" : list, "lang" : "en", "language": "English", } }), ) def metadata(self, page): data = {"tags": list(text.extract_iter(page, "class>", "<"))} info = text.extr(page, '