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
|
2017-09-24 15:59:25 +02:00
|
|
|
from .. import text, util
|
2015-11-26 03:06:08 +01:00
|
|
|
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-09-22 14:55:37 +02:00
|
|
|
pattern = [r"(?:https?://)?((?:www\.)?mangahere\.co/manga/"
|
|
|
|
r"[^/]+)/?(?:#.*)?$"]
|
|
|
|
test = [
|
|
|
|
("http://www.mangahere.co/manga/aria/", {
|
|
|
|
"url": "77d96842292a6a341e8937816ed45cc09b538cf0",
|
|
|
|
"keyword": "951eef36a3775525a31ca78c9d9cea546f4cf2f5",
|
|
|
|
}),
|
|
|
|
("http://www.mangahere.co/manga/hiyokoi#50", {
|
|
|
|
"url": "f33cff8616dbc382a76034d9604e7671506ac02a",
|
|
|
|
"keyword": "9542283639bd082fabf3a14b6695697d3ef15111",
|
|
|
|
})
|
|
|
|
]
|
2015-11-28 00:11:28 +01:00
|
|
|
|
2017-05-20 11:27:43 +02:00
|
|
|
def chapters(self, page):
|
2017-09-22 14:55:37 +02:00
|
|
|
results = []
|
|
|
|
pos = page.index('<div class="detail_list">')
|
|
|
|
manga, pos = text.extract(page, '<h3>Read ', ' Online</h3>', pos)
|
|
|
|
manga = text.unescape(manga)
|
|
|
|
|
|
|
|
while True:
|
|
|
|
url, pos = text.extract(
|
|
|
|
page, '<a class="color_0077" href="', '"', pos)
|
|
|
|
if not url:
|
|
|
|
return results
|
|
|
|
chapter, dot, minor = url[:-1].rpartition("/c")[2].partition(".")
|
|
|
|
volume, pos = text.extract(page, 'span class="mr6">', '<', pos)
|
|
|
|
title, pos = text.extract(page, '/span>', '<', pos)
|
|
|
|
date, pos = text.extract(page, 'class="right">', '</span>', pos)
|
|
|
|
results.append((url, {
|
|
|
|
"manga": manga, "title": title, "date": date,
|
2017-09-24 15:59:25 +02:00
|
|
|
"volume": util.safe_int(volume.rpartition(" ")[2]),
|
|
|
|
"chapter": util.safe_int(chapter),
|
|
|
|
"chapter_minor": dot + minor,
|
2017-09-22 14:55:37 +02:00
|
|
|
"lang": "en", "language": "English",
|
|
|
|
}))
|
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-24 15:59:25 +02:00
|
|
|
"keyword": "0c263b83f803524baa8717d2b4d841617aa8d775",
|
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(
|
2017-09-24 15:59:25 +02:00
|
|
|
range(1, data["count"]+1),
|
2017-02-01 00:53:19 +01:00
|
|
|
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,
|
2017-09-24 15:59:25 +02:00
|
|
|
"volume": util.safe_int(self.volume),
|
|
|
|
"chapter": util.safe_int(self.chapter),
|
2017-09-10 22:20:47 +02:00
|
|
|
"chapter_minor": self.chminor or "",
|
2017-09-24 15:59:25 +02:00
|
|
|
"chapter_id": util.safe_int(chid),
|
|
|
|
"count": util.safe_int(count),
|
2015-11-26 03:06:08 +01:00
|
|
|
"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
|