# -*- 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://kissmanga.com/""" from .common import ChapterExtractor, MangaExtractor from .. import text, cloudflare, aes, exception from ..cache import cache import hashlib import ast import re IV = [ 0xa5, 0xe8, 0xe2, 0xe9, 0xc2, 0x72, 0x1b, 0xe0, 0xa8, 0x4a, 0xd6, 0x60, 0xc4, 0x72, 0xc1, 0xf3 ] class KissmangaBase(): """Base class for kissmanga extractors""" category = "kissmanga" archive_fmt = "{chapter_id}_{page}" root = "https://kissmanga.com" def request(self, url): response = cloudflare.request_func(self, url) if response.history and "/Message/AreYouHuman?" in response.url: self.log.error("Requesting too many pages caused a redirect to %s." " Try visiting this URL in your browser and solving" " the CAPTCHA to continue.", response.url) raise exception.StopExtraction() return response @staticmethod def parse_chapter_string(data): """Parse 'chapter_string' value contained in 'data'""" data["chapter_string"] = text.unescape(data["chapter_string"]) match = re.match(( r"(?:[Vv]ol\.0*(\d+) )?" r"(?:[Cc]h\.)?0*(\d+)" r"(?:[.:]0*(\d+))?" r"(?: *[:-]? *(.+))?" ), data["chapter_string"]) if not match: match = re.match(( r".+?(?: -)? ()" r"0*(\d+)(?:[Vv.]0*(\d+))?" r"(?: *[:-]? *(.+))?" ), data["chapter_string"]) if match: volume, chapter, minor, title = match.groups() else: volume, chapter, minor, title = 0, 0, "", data["chapter_string"] data["volume"] = text.parse_int(volume) data["chapter"] = text.parse_int(chapter) data["chapter_minor"] = "." + minor if minor else "" data["title"] = title if title and title != "Read Online" else "" return data class KissmangaChapterExtractor(KissmangaBase, ChapterExtractor): """Extractor for manga-chapters from kissmanga.com""" pattern = (r"(?i)(?:https?://)?(?:www\.)?kissmanga\.com" r"(/Manga/[^/?]+/[^/?]+\?id=(\d+))") test = ( ("https://kissmanga.com/Manga/Dropout/Ch-000---Oneshot-?id=145847", { "url": "46e63fd63e9e16f19bc1e6c7a45dc060815642fd", "keyword": "4a3a9341d453541de0dbfa24cd6b2e3ed39c0182", }), ("https://kissmanga.com/Manga/Urban-Tales/a?id=256717", { "url": "c26be8bf9c2abacee2076979d021634092cf38f1", "keyword": "ffc11b630da44fe67709ed0473756cf51b90a05c", }), ("https://kissmanga.com/Manga/Monster/Monster-79?id=7608", { "count": 23, "keyword": "d47c94f4c57f4ab690a34b60fefac7b294468856", }), ("https://kissmanga.com/Manga/Houseki-no-Kuni/Oneshot?id=404189", { "count": 49, "keyword": "7835a19c9fc54ec4f2b345e8be3e865cfa57da5c", }), ("https://kissmanga.com/mAnGa/mOnStEr/Monster-79?id=7608"), ) def __init__(self, match): ChapterExtractor.__init__(self, match) self.chapter_id = match.group(2) self.session.headers["Referer"] = self.root def metadata(self, page): title = text.extract(page, "