2015-06-26 22:07:36 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2017-05-20 11:27:43 +02:00
|
|
|
# Copyright 2015-2017 Mike Fährmann
|
2015-06-26 22:07:36 +02:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2015-11-28 22:21:35 +01:00
|
|
|
"""Extract manga-chapters and entire manga from http://www.mangareader.net/"""
|
2015-06-26 22:07:36 +02:00
|
|
|
|
2017-05-20 11:27:43 +02:00
|
|
|
from .common import AsynchronousExtractor, MangaExtractor, Message
|
2017-09-24 15:59:25 +02:00
|
|
|
from .. import text, util
|
2015-06-26 22:07:36 +02:00
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2016-09-12 10:20:57 +02:00
|
|
|
class MangareaderBase():
|
2015-11-28 22:21:35 +01:00
|
|
|
"""Base class for mangareader extractors"""
|
2015-11-26 23:07:12 +01:00
|
|
|
category = "mangareader"
|
2017-05-20 11:27:43 +02:00
|
|
|
root = "http://www.mangareader.net"
|
2015-11-26 23:07:12 +01:00
|
|
|
|
2017-09-23 15:42:50 +02:00
|
|
|
@staticmethod
|
2017-09-24 15:59:25 +02:00
|
|
|
def parse_page(page, data):
|
|
|
|
"""Parse metadata on 'page' and add it to 'data'"""
|
2017-09-23 15:42:50 +02:00
|
|
|
text.extract_all(page, (
|
|
|
|
("manga" , '<h2 class="aname">', '</h2>'),
|
|
|
|
("release", '>Year of Release:</td>\n<td>', '</td>'),
|
|
|
|
('author' , '>Author:</td>\n<td>', '</td>'),
|
|
|
|
('artist' , '>Artist:</td>\n<td>', '</td>'),
|
|
|
|
), values=data)
|
|
|
|
data["manga"] = data["manga"].strip()
|
|
|
|
data["author"] = text.unescape(data["author"])
|
|
|
|
data["artist"] = text.unescape(data["artist"])
|
2017-09-24 15:59:25 +02:00
|
|
|
return data
|
2017-09-23 15:42:50 +02:00
|
|
|
|
2015-11-26 23:32:16 +01:00
|
|
|
|
2017-05-20 11:27:43 +02:00
|
|
|
class MangareaderMangaExtractor(MangareaderBase, MangaExtractor):
|
|
|
|
"""Extractor for manga from mangareader.net"""
|
2017-10-09 22:37:50 +02:00
|
|
|
pattern = [r"(?:https?://)?((?:www\.)?mangareader\.net/[^/?&#]+)/?$"]
|
2017-05-20 11:27:43 +02:00
|
|
|
reverse = False
|
2015-12-14 03:00:58 +01:00
|
|
|
test = [("http://www.mangareader.net/mushishi", {
|
|
|
|
"url": "249042420b67a07b32e7f6be4c7410b6d810b808",
|
2017-09-23 15:42:50 +02:00
|
|
|
"keyword": "031b3ea085921c552de017ecbb9b906e462229c9",
|
2015-12-14 03:00:58 +01:00
|
|
|
})]
|
2015-11-26 23:32:16 +01:00
|
|
|
|
2017-09-23 15:42:50 +02:00
|
|
|
def chapters(self, page):
|
|
|
|
results = []
|
2017-09-24 15:59:25 +02:00
|
|
|
data = self.parse_page(page, {"lang": "en", "language": "English"})
|
2017-09-23 15:42:50 +02:00
|
|
|
|
2017-05-20 11:27:43 +02:00
|
|
|
needle = '<div class="chico_manga"></div>\n<a href="'
|
2017-09-23 15:42:50 +02:00
|
|
|
pos = page.index('<div id="chapterlist">')
|
|
|
|
while True:
|
|
|
|
url, pos = text.extract(page, needle, '"', pos)
|
|
|
|
if not url:
|
|
|
|
return results
|
|
|
|
data["title"], pos = text.extract(page, '</a> : ', '</td>', pos)
|
|
|
|
data["date"] , pos = text.extract(page, '<td>', '</td>', pos)
|
2017-09-24 15:59:25 +02:00
|
|
|
data["chapter"] = util.safe_int(url.rpartition("/")[2])
|
2017-09-23 15:42:50 +02:00
|
|
|
results.append((self.root + url, data.copy()))
|
2015-11-26 23:07:12 +01:00
|
|
|
|
2015-11-26 23:32:16 +01:00
|
|
|
|
2016-09-12 10:20:57 +02:00
|
|
|
class MangareaderChapterExtractor(MangareaderBase, AsynchronousExtractor):
|
|
|
|
"""Extractor for manga-chapters from mangareader.net"""
|
2015-11-30 01:11:13 +01:00
|
|
|
subcategory = "chapter"
|
2017-10-02 19:06:24 +02:00
|
|
|
directory_fmt = ["{category}", "{manga}", "c{chapter:>03}{title:?: //}"]
|
|
|
|
filename_fmt = "{manga}_c{chapter:>03}_{page:>03}.{extension}"
|
2015-11-21 04:26:30 +01:00
|
|
|
pattern = [
|
2017-10-09 22:37:50 +02:00
|
|
|
(r"(?:https?://)?(?:www\.)?mangareader\.net((/[^/?&#]+)/(\d+))"),
|
|
|
|
(r"(?:https?://)?(?:www\.)?mangareader\.net"
|
|
|
|
r"(/\d+-\d+-\d+(/[^/]+)/chapter-(\d+)\.html)"),
|
2015-11-21 04:26:30 +01:00
|
|
|
]
|
2017-02-01 00:53:19 +01:00
|
|
|
test = [(("http://www.mangareader.net/"
|
|
|
|
"karate-shoukoushi-kohinata-minoru/11"), {
|
2015-12-14 03:00:58 +01:00
|
|
|
"url": "84ffaab4c027ef9022695c53163c3aeabd07ca58",
|
2017-09-23 15:42:50 +02:00
|
|
|
"keyword": "2038e6a780a0028eee0067985b55debb1d4a6aab",
|
2015-12-14 03:00:58 +01:00
|
|
|
})]
|
2015-06-26 22:07:36 +02:00
|
|
|
|
2015-10-05 15:35:48 +02:00
|
|
|
def __init__(self, match):
|
|
|
|
AsynchronousExtractor.__init__(self)
|
2015-11-03 00:08:25 +01:00
|
|
|
self.part, self.url_title, self.chapter = match.groups()
|
2015-06-26 22:07:36 +02:00
|
|
|
|
|
|
|
def items(self):
|
2017-05-20 11:27:43 +02:00
|
|
|
page = self.request(self.root + self.part).text
|
2015-11-03 00:08:25 +01:00
|
|
|
data = self.get_job_metadata(page)
|
2015-06-26 22:07:36 +02:00
|
|
|
yield Message.Version, 1
|
2015-11-03 00:08:25 +01:00
|
|
|
yield Message.Directory, data
|
2017-09-23 15:42:50 +02:00
|
|
|
for data["page"] in range(1, data["count"]+1):
|
2015-11-03 00:08:25 +01:00
|
|
|
next_url, image_url, image_data = self.get_page_metadata(page)
|
|
|
|
image_data.update(data)
|
|
|
|
yield Message.Url, image_url, image_data
|
|
|
|
if next_url:
|
|
|
|
page = self.request(next_url).text
|
2015-06-26 22:07:36 +02:00
|
|
|
|
2015-11-03 00:08:25 +01:00
|
|
|
def get_job_metadata(self, chapter_page):
|
|
|
|
"""Collect metadata for extractor-job"""
|
2017-05-20 11:27:43 +02:00
|
|
|
page = self.request(self.root + self.url_title).text
|
2017-09-24 15:59:25 +02:00
|
|
|
data = self.parse_page(page, {
|
|
|
|
"chapter": util.safe_int(self.chapter),
|
2015-11-03 00:08:25 +01:00
|
|
|
"lang": "en",
|
|
|
|
"language": "English",
|
2017-09-24 15:59:25 +02:00
|
|
|
})
|
2017-09-23 15:42:50 +02:00
|
|
|
text.extract_all(page, (
|
2015-11-03 00:08:25 +01:00
|
|
|
('title', ' ' + self.chapter + '</a> : ', '</td>'),
|
2017-09-10 22:20:47 +02:00
|
|
|
('date', '<td>', '</td>'),
|
2017-09-23 15:42:50 +02:00
|
|
|
), page.index('<div id="chapterlist">'), data)
|
2017-09-24 15:59:25 +02:00
|
|
|
data["count"] = util.safe_int(text.extract(
|
2017-09-23 15:42:50 +02:00
|
|
|
chapter_page, '</select> of ', '<')[0]
|
|
|
|
)
|
2015-11-03 00:08:25 +01:00
|
|
|
return data
|
|
|
|
|
|
|
|
def get_page_metadata(self, page):
|
2015-06-26 22:07:36 +02:00
|
|
|
"""Collect next url, image-url and metadata for one manga-page"""
|
2015-10-03 15:43:02 +02:00
|
|
|
extr = text.extract
|
2015-06-28 01:22:39 +02:00
|
|
|
width = None
|
2015-11-03 00:08:25 +01:00
|
|
|
test , pos = extr(page, "document['pu']", '')
|
2015-06-28 01:22:39 +02:00
|
|
|
if test is None:
|
2015-06-26 22:07:36 +02:00
|
|
|
return None, None, None
|
2015-06-28 01:22:39 +02:00
|
|
|
if page.find("document['imgwidth']", pos, pos+200) != -1:
|
|
|
|
width , pos = extr(page, "document['imgwidth'] = ", ";", pos)
|
|
|
|
height, pos = extr(page, "document['imgheight'] = ", ";", pos)
|
|
|
|
_ , pos = extr(page, '<div id="imgholder">', '')
|
|
|
|
url, pos = extr(page, ' href="', '"', pos)
|
|
|
|
if width is None:
|
|
|
|
width , pos = extr(page, '<img id="img" width="', '"', pos)
|
|
|
|
height, pos = extr(page, ' height="', '"', pos)
|
|
|
|
image, pos = extr(page, ' src="', '"', pos)
|
2017-05-20 11:27:43 +02:00
|
|
|
return self.root + url, image, text.nameext_from_url(image, {
|
2017-09-24 15:59:25 +02:00
|
|
|
"width": util.safe_int(width),
|
|
|
|
"height": util.safe_int(height),
|
2015-11-16 17:32:26 +01:00
|
|
|
})
|