2015-11-26 03:06:08 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2018-02-07 11:22:47 +01:00
|
|
|
# Copyright 2015-2018 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
|
|
|
|
2018-02-07 11:22:47 +01:00
|
|
|
from .common import ChapterExtractor, MangaExtractor
|
2017-09-24 15:59:25 +02:00
|
|
|
from .. import text, util
|
2018-05-16 16:22:05 +02:00
|
|
|
from ..cache import memcache
|
2017-09-26 17:08:59 +02:00
|
|
|
from urllib.parse import urljoin
|
2015-11-26 03:06:08 +01:00
|
|
|
import re
|
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2018-05-16 16:22:05 +02:00
|
|
|
class MangahereBase():
|
|
|
|
"""Base class for mangahere extractors"""
|
2015-11-28 00:11:28 +01:00
|
|
|
category = "mangahere"
|
2018-05-16 16:22:05 +02:00
|
|
|
root = "https://www.mangahere.cc"
|
|
|
|
url_fmt = root + "/manga/{}/{}.html"
|
|
|
|
|
|
|
|
|
|
|
|
class MangahereMangaExtractor(MangahereBase, MangaExtractor):
|
|
|
|
"""Extractor for manga from mangahere.cc"""
|
2017-12-20 21:34:25 +01:00
|
|
|
pattern = [r"(?:https?://)?(?:www\.|m\.)?mangahere\.c[co]/manga/"
|
|
|
|
r"([^/]+)/?(?:#.*)?$"]
|
2017-09-22 14:55:37 +02:00
|
|
|
test = [
|
2018-05-16 16:22:05 +02:00
|
|
|
("https://www.mangahere.cc/manga/aria/", {
|
2017-12-20 21:34:25 +01:00
|
|
|
"url": "e8971b1605d9888d978ebb2895adb1c7c37d663c",
|
2017-09-22 14:55:37 +02:00
|
|
|
"keyword": "951eef36a3775525a31ca78c9d9cea546f4cf2f5",
|
|
|
|
}),
|
2017-12-20 21:34:25 +01:00
|
|
|
("http://www.mangahere.cc/manga/hiyokoi#50", {
|
|
|
|
"url": "6df27c0e105d9ee0b78a7aa77340d0891e6c7fc6",
|
2017-09-22 14:55:37 +02:00
|
|
|
"keyword": "9542283639bd082fabf3a14b6695697d3ef15111",
|
2017-12-20 21:34:25 +01:00
|
|
|
}),
|
|
|
|
("http://www.mangahere.co/manga/aria/", None),
|
|
|
|
("http://m.mangahere.co/manga/aria/", None),
|
2017-09-22 14:55:37 +02:00
|
|
|
]
|
2015-11-28 00:11:28 +01:00
|
|
|
|
2017-12-20 21:34:25 +01:00
|
|
|
def __init__(self, match):
|
2018-05-16 16:22:05 +02:00
|
|
|
url = "{}/manga/{}/".format(self.root, match.group(1))
|
2017-12-20 21:34:25 +01:00
|
|
|
MangaExtractor.__init__(self, match, url)
|
|
|
|
|
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)
|
2017-09-26 17:08:59 +02:00
|
|
|
results.append((urljoin("http:", url), {
|
2017-09-22 14:55:37 +02:00
|
|
|
"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
|
|
|
|
|
|
|
|
2018-05-16 16:22:05 +02:00
|
|
|
class MangahereChapterExtractor(MangahereBase, ChapterExtractor):
|
|
|
|
"""Extractor for manga-chapters from mangahere.cc"""
|
2017-12-20 21:34:25 +01:00
|
|
|
pattern = [(r"(?:https?://)?(?:www\.|m\.)?mangahere\.c[co]/manga/"
|
2018-05-16 16:22:05 +02:00
|
|
|
r"([^/]+(?:/v0*(\d+))?/c([^/?&#]+))")]
|
2017-12-20 21:34:25 +01:00
|
|
|
test = [
|
2018-05-16 16:22:05 +02:00
|
|
|
("https://www.mangahere.cc/manga/dongguo_xiaojie/c004.2/", {
|
|
|
|
"keyword": "0e1cee6dd377da02ad51aa810ba65db3e811aef9",
|
|
|
|
"content": "708d475f06893b88549cbd30df1e3f9428f2c884",
|
2017-12-20 21:34:25 +01:00
|
|
|
}),
|
|
|
|
("http://www.mangahere.co/manga/dongguo_xiaojie/c003.2/", None),
|
|
|
|
("http://m.mangahere.co/manga/dongguo_xiaojie/c003.2/", None),
|
|
|
|
]
|
2015-11-26 03:06:08 +01:00
|
|
|
|
|
|
|
def __init__(self, match):
|
2018-05-16 16:22:05 +02:00
|
|
|
self.part, self.volume, self.chapter = match.groups()
|
2017-12-20 21:34:25 +01:00
|
|
|
# remove ".html" for the first chapter page to avoid redirects
|
|
|
|
url = self.url_fmt.format(self.part, "")[:-5]
|
2018-02-07 11:22:47 +01:00
|
|
|
ChapterExtractor.__init__(self, url)
|
2017-12-20 21:34:25 +01:00
|
|
|
|
2018-02-07 11:22:47 +01:00
|
|
|
def get_metadata(self, page):
|
2015-11-26 03:06:08 +01:00
|
|
|
"""Collect metadata for extractor-job"""
|
|
|
|
manga, pos = text.extract(page, '<title>', '</title>')
|
2018-05-16 16:22:05 +02:00
|
|
|
mid , pos = text.extract(page, '.net/store/manga/', '/', pos)
|
2017-11-03 14:54:46 +01:00
|
|
|
pages, pos = text.extract(page, ' class="wid60"', '</select>', pos)
|
|
|
|
count = re.findall(r">(\d+)<", pages)[-1]
|
2017-02-01 00:53:19 +01:00
|
|
|
manga = re.match((r"(.+) \d+(\.\d+)? - Read .+ Chapter "
|
|
|
|
r"\d+(\.\d+)? Online"), manga).group(1)
|
2018-05-16 16:22:05 +02:00
|
|
|
chapter, dot, minor = self.chapter.partition(".")
|
|
|
|
|
2015-11-26 03:06:08 +01:00
|
|
|
return {
|
|
|
|
"manga": text.unescape(manga),
|
2018-05-16 16:22:05 +02:00
|
|
|
"manga_id": util.safe_int(mid),
|
|
|
|
"title": self._get_title_map(mid).get(self.chapter),
|
2017-09-24 15:59:25 +02:00
|
|
|
"volume": util.safe_int(self.volume),
|
2018-05-16 16:22:05 +02:00
|
|
|
"chapter": util.safe_int(chapter),
|
|
|
|
"chapter_minor": dot + minor,
|
2017-09-24 15:59:25 +02:00
|
|
|
"count": util.safe_int(count),
|
2015-11-26 03:06:08 +01:00
|
|
|
"lang": "en",
|
|
|
|
"language": "English",
|
|
|
|
}
|
|
|
|
|
2018-02-07 11:22:47 +01:00
|
|
|
def get_images(self, page):
|
2015-11-26 03:06:08 +01:00
|
|
|
"""Yield all image-urls for this chapter"""
|
|
|
|
pnum = 1
|
|
|
|
while True:
|
|
|
|
url, pos = text.extract(page, '<img src="', '"')
|
2018-02-07 11:22:47 +01:00
|
|
|
yield url, None
|
2015-11-26 03:06:08 +01:00
|
|
|
_ , 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)
|
2018-02-07 11:22:47 +01:00
|
|
|
yield url, None
|
|
|
|
|
2015-11-26 03:06:08 +01:00
|
|
|
pnum += 2
|
|
|
|
page = self.request(self.url_fmt.format(self.part, pnum)).text
|
2018-05-16 16:22:05 +02:00
|
|
|
|
|
|
|
@memcache(keyarg=1)
|
|
|
|
def _get_title_map(self, manga_id):
|
|
|
|
url = "{}/get_chapters{}.js".format(self.root, manga_id)
|
|
|
|
page = self.request(url).text
|
|
|
|
|
|
|
|
chapters = {}
|
|
|
|
for info in text.extract_iter(page, '["', '"]'):
|
|
|
|
title, _, url = info.partition('","')
|
|
|
|
title = title.partition(": ")[2]
|
|
|
|
num = url.rpartition("c")[2].rstrip("/")
|
|
|
|
chapters[num] = text.unescape(title)
|
|
|
|
|
|
|
|
return chapters
|