# -*- coding: utf-8 -*- # Copyright 2015-2019 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 # published by the Free Software Foundation. """Extract manga-chapters and entire manga from https://mangapark.me/""" from .common import ChapterExtractor, MangaExtractor from .. import text, exception import json class MangaparkBase(): """Base class for mangapark extractors""" category = "mangapark" root_fmt = "https://mangapark.{}" @staticmethod def parse_chapter_path(path, data): """Get volume/chapter information from url-path of a chapter""" data["volume"], data["chapter_minor"] = 0, "" for part in path.split("/")[1:]: key, value = part[0], part[1:] if key == "c": chapter, dot, minor = value.partition(".") data["chapter"] = text.parse_int(chapter) data["chapter_minor"] = dot + minor elif key == "i": data["chapter_id"] = text.parse_int(value) elif key == "v": data["volume"] = text.parse_int(value) elif key == "s": data["stream"] = text.parse_int(value) elif key == "e": data["chapter_minor"] = "v" + value class MangaparkChapterExtractor(MangaparkBase, ChapterExtractor): """Extractor for manga-chapters from mangapark.me""" pattern = (r"(?:https?://)?(?:www\.)?mangapark\.(me|net|com)" r"/manga/([^?]+/i\d+)") test = ( ("https://mangapark.me/manga/gosu/i811615/c55/1", { "count": 50, "keyword": "373d678048d29492f9763743ccaa9b6d840f17cf", }), (("https://mangapark.me/manga" "/ad-astra-per-aspera-hata-kenjirou/i662054/c001.2/1"), { "count": 40, "keyword": "8e9cce4ed0e25d12a45e02f840d6f32ef838e257", }), ("https://mangapark.me/manga/gekkan-shoujo-nozaki-kun/i655476/c70/1", { "count": 15, "keyword": "19f730617074d65f91c0781f429de324890925bf", }), ("https://mangapark.net/manga/gosu/i811615/c55/1"), ("https://mangapark.com/manga/gosu/i811615/c55/1"), ) def __init__(self, match): tld, self.path = match.groups() self.root = self.root_fmt.format(tld) url = "{}/manga/{}?zoom=2".format(self.root, self.path) ChapterExtractor.__init__(self, match, url) def metadata(self, page): data = text.extract_all(page, ( ("manga_id" , "var _manga_id = '", "'"), ("chapter_id", "var _book_id = '", "'"), ("stream" , "var _stream = '", "'"), ("path" , "var _book_link = '", "'"), ("manga" , "