# -*- 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://www.mangashare.com/""" from .common import AsynchronousExtractor, Message from .. import text class MangaShareExtractor(AsynchronousExtractor): category = "mangashare" directory_fmt = ["{category}", "{manga}", "c{chapter:>03} - {title}"] filename_fmt = "{manga}_c{chapter:>03}_{page:>03}.{extension}" pattern = [r"(?:https?://)?read\.mangashare\.com/([^/]+/chapter-\d+)"] url_fmt = "http://read.mangashare.com/{}/page{:>03}.html" def __init__(self, match): AsynchronousExtractor.__init__(self) self.part = match.group(1) def items(self): page = self.request(self.url_fmt.format(self.part, 1)).text data = self.get_job_metadata(page) yield Message.Version, 1 yield Message.Directory, data.copy() for i, url in zip(range(int(data["count"])), (self.get_image_urls(page))): data["page"] = i+1 text.nameext_from_url(url, data) yield Message.Url, url, data.copy() def get_job_metadata(self, page): """Collect metadata for extractor-job""" data = { "category": self.category, "lang": "en", "language": "English", } data, pos = text.extract_all(page, ( ('manga' , 'title="', '"'), ('chapter', 'selected="selected">', ' - '), ('title' , '', '<'), (None , 'Page 1', ''), (None , '', ''), ), values=data) data["count"] = text.extract(page, '>Page ', '<', pos-35)[0] return data def get_image_urls(self, page): """Yield all image-urls for this chapter""" pnum = 1 while True: _ , pos = text.extract(page, '
', '') url, pos = text.extract(page, '