2015-11-26 03:06:08 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2017-05-20 11:27:43 +02:00
|
|
|
# Copyright 2015-2017 Mike Fährmann
|
2015-11-26 03:06:08 +01: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.
|
|
|
|
|
2016-09-12 10:20:57 +02:00
|
|
|
"""Extract manga-chapters and entire manga from http://www.mangahere.co/"""
|
2015-11-26 03:06:08 +01:00
|
|
|
|
2017-05-20 11:27:43 +02:00
|
|
|
from .common import MangaExtractor, AsynchronousExtractor, Message
|
2015-11-26 03:06:08 +01:00
|
|
|
from .. import text
|
|
|
|
import re
|
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2017-05-20 11:27:43 +02:00
|
|
|
class MangahereMangaExtractor(MangaExtractor):
|
|
|
|
"""Extractor for manga from mangahere.co"""
|
2015-11-28 00:11:28 +01:00
|
|
|
category = "mangahere"
|
2017-05-20 11:27:43 +02:00
|
|
|
pattern = [r"(?:https?://)?((?:www\.)?mangahere\.co/manga/[^/]+/?)$"]
|
2015-12-14 03:00:58 +01:00
|
|
|
test = [("http://www.mangahere.co/manga/aria/", {
|
|
|
|
"url": "77d96842292a6a341e8937816ed45cc09b538cf0",
|
|
|
|
})]
|
2015-11-28 00:11:28 +01:00
|
|
|
|
2017-05-20 11:27:43 +02:00
|
|
|
def chapters(self, page):
|
|
|
|
return list(text.extract_iter(
|
2017-02-01 00:53:19 +01:00
|
|
|
page, '<a class="color_0077" href="', '"',
|
|
|
|
page.index('<div class="detail_list">')
|
2017-05-20 11:27:43 +02:00
|
|
|
))
|
2015-11-28 00:11:28 +01:00
|
|
|
|
|
|
|
|
2016-09-12 10:20:57 +02:00
|
|
|
class MangahereChapterExtractor(AsynchronousExtractor):
|
|
|
|
"""Extractor for manga-chapters from mangahere.co"""
|
2015-11-26 03:06:08 +01:00
|
|
|
category = "mangahere"
|
2015-11-30 01:11:13 +01:00
|
|
|
subcategory = "chapter"
|
2017-09-10 22:20:47 +02:00
|
|
|
directory_fmt = ["{category}", "{manga}", "c{chapter:>03}{chapter_minor}"]
|
|
|
|
filename_fmt = ("{manga}_c{chapter:>03}{chapter_minor}_"
|
2017-02-01 00:53:19 +01:00
|
|
|
"{page:>03}.{extension}")
|
2015-11-28 00:31:04 +01:00
|
|
|
pattern = [(r"(?:https?://)?(?:www\.)?mangahere\.co/manga/"
|
|
|
|
r"([^/]+(?:/v0*(\d+))?/c0*(\d+)(\.\d+)?)")]
|
2015-12-14 03:00:58 +01:00
|
|
|
test = [("http://www.mangahere.co/manga/dongguo_xiaojie/c003.2/", {
|
2017-09-10 22:20:47 +02:00
|
|
|
"keyword": "8cb9f9512b68d2cdcbea2419592b9247304c149b",
|
2016-12-12 14:17:15 +01:00
|
|
|
"content": "dd8454469429c6c717cbc3cad228e76ef8c6e420",
|
2015-12-14 03:00:58 +01:00
|
|
|
})]
|
2015-11-26 03:06:08 +01:00
|
|
|
url_fmt = "http://www.mangahere.co/manga/{}/{}.html"
|
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
AsynchronousExtractor.__init__(self)
|
2015-11-28 00:31:04 +01:00
|
|
|
self.part, self.volume, self.chapter, self.chminor = match.groups()
|
2015-11-26 03:06:08 +01:00
|
|
|
|
|
|
|
def items(self):
|
|
|
|
page = self.request(self.url_fmt.format(self.part, 1)).text
|
|
|
|
data = self.get_job_metadata(page)
|
2017-02-01 00:53:19 +01:00
|
|
|
urls = zip(
|
|
|
|
range(1, int(data["count"])+1),
|
|
|
|
self.get_image_urls(page),
|
|
|
|
)
|
2015-11-26 03:06:08 +01:00
|
|
|
yield Message.Version, 1
|
|
|
|
yield Message.Directory, data.copy()
|
2017-02-01 00:53:19 +01:00
|
|
|
for data["page"], url in urls:
|
2015-11-26 03:06:08 +01:00
|
|
|
text.nameext_from_url(url, data)
|
|
|
|
yield Message.Url, url, data.copy()
|
|
|
|
|
|
|
|
def get_job_metadata(self, page):
|
|
|
|
"""Collect metadata for extractor-job"""
|
|
|
|
manga, pos = text.extract(page, '<title>', '</title>')
|
2017-07-25 14:59:41 +02:00
|
|
|
chid , pos = text.extract(page, '.mhcdn.net/store/manga/', '/', pos)
|
2015-11-26 03:06:08 +01:00
|
|
|
_ , pos = text.extract(page, '<select class="wid60"', '', pos)
|
|
|
|
_ , pos = text.extract(page, '</select>', '', pos)
|
|
|
|
count, pos = text.extract(page, '>', '<', pos-30)
|
2017-02-01 00:53:19 +01:00
|
|
|
manga = re.match((r"(.+) \d+(\.\d+)? - Read .+ Chapter "
|
|
|
|
r"\d+(\.\d+)? Online"), manga).group(1)
|
2015-11-26 03:06:08 +01:00
|
|
|
return {
|
|
|
|
"manga": text.unescape(manga),
|
|
|
|
# "title": TODO,
|
|
|
|
"volume": self.volume or "",
|
|
|
|
"chapter": self.chapter,
|
2017-09-10 22:20:47 +02:00
|
|
|
"chapter_minor": self.chminor or "",
|
|
|
|
"chapter_id": chid,
|
2015-11-26 03:06:08 +01:00
|
|
|
"count": count,
|
|
|
|
"lang": "en",
|
|
|
|
"language": "English",
|
|
|
|
}
|
|
|
|
|
|
|
|
def get_image_urls(self, page):
|
|
|
|
"""Yield all image-urls for this chapter"""
|
|
|
|
pnum = 1
|
|
|
|
while True:
|
|
|
|
url, pos = text.extract(page, '<img src="', '"')
|
|
|
|
yield url
|
|
|
|
_ , pos = text.extract(page, '<img src="', '"', pos)
|
2016-04-20 08:33:06 +02:00
|
|
|
_ , pos = text.extract(page, '<img src="', '"', pos)
|
2015-11-26 03:06:08 +01:00
|
|
|
url, pos = text.extract(page, '<img src="', '"', pos)
|
|
|
|
yield url
|
|
|
|
pnum += 2
|
|
|
|
page = self.request(self.url_fmt.format(self.part, pnum)).text
|