# -*- coding: utf-8 -*- # Copyright 2015 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 pages from http://powermanga.org/""" from .common import Extractor, Message from .. import text, iso639_1 import os.path import json import re class PowerMangaExtractor(Extractor): category = "powermanga" directory_fmt = ["{category}", "{manga}", "c{chapter:>03}{chapter-minor} - {title}"] filename_fmt = "{manga}_c{chapter:>03}{chapter-minor}_{page:>03}.{extension}" pattern = [ (r"(?:https?://)?read(?:er)?\.powermanga\.org/read/" r"(.+/([a-z]{2})/\d+/\d+)(?:/page)?"), (r"(?:https?://)?(?:www\.)?(p)owermanga\.org/((?:[^-]+-)+[^-]+/?)"), ] test = [("http://read.powermanga.org/read/one_piece/en/0/803/page/1", { "url": "e6179c1565068f99180620281f86bdd25be166b4", "keyword": "ef17bbc6a9ab0390a31f1508e825ddce35f2d2b1", })] def __init__(self, match): Extractor.__init__(self) if match.group(1) == "p": page = self.request("https://powermanga.org/" + match.group(2)).text pos = page.index("class='small-button smallblack'>Download") url = text.extract(page, "', '') manga , pos = text.extract(page, 'title="', '"', pos) chapter , pos = text.extract(page, '">', '', pos) json_data, pos = text.extract(page, 'var pages = ', ';', pos) match = re.match(r"(\w+ (\d+)([^:+]*)(?:: (.*))?|[^:]+)", chapter) return { "category": self.category, "manga": text.unescape(manga), "chapter": match.group(2) or match.group(1), "chapter-minor": match.group(3) or "", "lang": self.lang, "language": iso639_1.code_to_language(self.lang), "title": text.unescape(match.group(4) or ""), }, json.loads(json_data)