2015-11-26 03:06:08 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-01-30 16:18:22 +01:00
|
|
|
# Copyright 2015-2019 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.
|
|
|
|
|
2019-01-30 16:18:22 +01:00
|
|
|
"""Extract manga-chapters and entire manga from https://www.mangahere.cc/"""
|
2015-11-26 03:06:08 +01:00
|
|
|
|
2018-02-07 11:22:47 +01:00
|
|
|
from .common import ChapterExtractor, MangaExtractor
|
2018-04-20 14:53:21 +02:00
|
|
|
from .. import text
|
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"
|
2019-01-30 16:18:22 +01:00
|
|
|
root = "https://www.mangahere.cc"
|
2019-02-10 22:09:29 +01:00
|
|
|
mobile_root = "https://m.mangahere.cc"
|
|
|
|
url_fmt = mobile_root + "/manga/{}/{}.html"
|
2018-05-16 16:22:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
class MangahereChapterExtractor(MangahereBase, ChapterExtractor):
|
|
|
|
"""Extractor for manga-chapters from mangahere.cc"""
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = (r"(?:https?://)?(?:www\.|m\.)?mangahere\.c[co]/manga/"
|
|
|
|
r"([^/]+(?:/v0*(\d+))?/c([^/?&#]+))")
|
|
|
|
test = (
|
2018-05-16 16:22:05 +02:00
|
|
|
("https://www.mangahere.cc/manga/dongguo_xiaojie/c004.2/", {
|
2019-02-10 22:09:29 +01:00
|
|
|
"keyword": "6407556817bd1fd2bdc8dee3fd2a718f5724ddc0",
|
2018-05-16 16:22:05 +02:00
|
|
|
"content": "708d475f06893b88549cbd30df1e3f9428f2c884",
|
2017-12-20 21:34:25 +01:00
|
|
|
}),
|
2019-02-08 13:45:40 +01:00
|
|
|
("http://www.mangahere.co/manga/dongguo_xiaojie/c003.2/"),
|
|
|
|
("http://m.mangahere.co/manga/dongguo_xiaojie/c003.2/"),
|
|
|
|
)
|
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()
|
2019-02-11 13:31:10 +01:00
|
|
|
url = self.url_fmt.format(self.part, 1)
|
|
|
|
ChapterExtractor.__init__(self, match, url)
|
2017-12-20 21:34:25 +01:00
|
|
|
|
2019-02-11 18:38:47 +01:00
|
|
|
def metadata(self, page):
|
2019-02-10 22:09:29 +01:00
|
|
|
pos = page.index("</select>")
|
|
|
|
count , pos = text.extract(page, ">", "<", pos - 20)
|
|
|
|
manga_id , pos = text.extract(page, "series_id = ", ";", pos)
|
|
|
|
chapter_id, pos = text.extract(page, "chapter_id = ", ";", pos)
|
|
|
|
manga , pos = text.extract(page, '"name":"', '"', pos)
|
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),
|
2019-02-10 22:09:29 +01:00
|
|
|
"manga_id": text.parse_int(manga_id),
|
|
|
|
"title": self._get_title(),
|
2018-04-20 14:53:21 +02:00
|
|
|
"volume": text.parse_int(self.volume),
|
2018-05-22 17:24:57 +02:00
|
|
|
"chapter": text.parse_int(chapter),
|
2018-05-16 16:22:05 +02:00
|
|
|
"chapter_minor": dot + minor,
|
2019-02-10 22:09:29 +01:00
|
|
|
"chapter_id": text.parse_int(chapter_id),
|
2018-04-20 14:53:21 +02:00
|
|
|
"count": text.parse_int(count),
|
2015-11-26 03:06:08 +01:00
|
|
|
"lang": "en",
|
|
|
|
"language": "English",
|
|
|
|
}
|
|
|
|
|
2019-02-11 18:38:47 +01:00
|
|
|
def images(self, page):
|
2015-11-26 03:06:08 +01:00
|
|
|
pnum = 1
|
2019-02-10 22:09:29 +01:00
|
|
|
|
2015-11-26 03:06:08 +01:00
|
|
|
while True:
|
2019-02-10 22:09:29 +01:00
|
|
|
url, pos = text.extract(page, '<img src="', '"')
|
|
|
|
yield url, None
|
|
|
|
url, pos = text.extract(page, ' src="', '"', pos)
|
|
|
|
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
|
|
|
|
2019-02-10 22:09:29 +01:00
|
|
|
def _get_title(self):
|
|
|
|
url = "{}/manga/{}/".format(self.root, self.part)
|
2018-05-16 16:22:05 +02:00
|
|
|
page = self.request(url).text
|
|
|
|
|
2019-02-10 22:09:29 +01:00
|
|
|
try:
|
|
|
|
pos = page.index(self.part) + len(self.part)
|
|
|
|
pos = page.index(self.part, pos) + len(self.part)
|
|
|
|
return text.extract(page, ' title="', '"', pos)[0]
|
|
|
|
except ValueError:
|
|
|
|
return ""
|
2019-02-11 18:38:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
class MangahereMangaExtractor(MangahereBase, MangaExtractor):
|
|
|
|
"""Extractor for manga from mangahere.cc"""
|
2019-02-13 13:23:36 +01:00
|
|
|
chapterclass = MangahereChapterExtractor
|
2019-02-11 18:38:47 +01:00
|
|
|
pattern = (r"(?:https?://)?(?:www\.|m\.)?mangahere\.c[co]"
|
|
|
|
r"(/manga/[^/]+)/?(?:#.*)?$")
|
|
|
|
test = (
|
|
|
|
("https://www.mangahere.cc/manga/aria/", {
|
|
|
|
"url": "23ad9256f7392de5973b79a36f6875e9fdcb7563",
|
|
|
|
"keyword": "79e326641e7d5d2fed43a1eb9949471b8162a9e0",
|
|
|
|
}),
|
|
|
|
("https://www.mangahere.cc/manga/hiyokoi/#50", {
|
|
|
|
"url": "654850570aa03825cd57e2ae2904af489602c523",
|
|
|
|
"keyword": "c8084d89a9ea6cf40353093669f9601a39bf5ca2",
|
|
|
|
}),
|
|
|
|
("https://www.mangahere.co/manga/aria/"),
|
|
|
|
("https://m.mangahere.co/manga/aria/"),
|
|
|
|
)
|
|
|
|
|
|
|
|
def chapters(self, page):
|
|
|
|
results = []
|
|
|
|
manga, pos = text.extract(page, '<meta name="og:title" content="', '"')
|
|
|
|
manga = text.unescape(manga)
|
|
|
|
|
|
|
|
page = text.extract(
|
|
|
|
page, 'id="chapterlist"', 'class="detail-main-list-more"', pos)[0]
|
|
|
|
pos = 0
|
|
|
|
while True:
|
|
|
|
url, pos = text.extract(page, ' href="', '"', pos)
|
|
|
|
if not url:
|
|
|
|
return results
|
|
|
|
info, pos = text.extract(page, 'class="title3">', '<', pos)
|
|
|
|
date, pos = text.extract(page, 'class="title2">', '<', pos)
|
|
|
|
|
|
|
|
match = re.match(
|
|
|
|
r"(?:Vol\.0*(\d+) )?Ch\.0*(\d+)(\S*)(?: - (.*))?", info)
|
|
|
|
if match:
|
|
|
|
volume, chapter, minor, title = match.groups()
|
|
|
|
else:
|
|
|
|
chapter, _, minor = url[:-1].rpartition("/c")[2].partition(".")
|
|
|
|
minor = "." + minor
|
|
|
|
volume = 0
|
|
|
|
title = ""
|
|
|
|
|
|
|
|
results.append((text.urljoin(self.root, url), {
|
|
|
|
"manga": manga,
|
|
|
|
"title": text.unescape(title) if title else "",
|
|
|
|
"volume": text.parse_int(volume),
|
|
|
|
"chapter": text.parse_int(chapter),
|
|
|
|
"chapter_minor": minor,
|
|
|
|
"date": date,
|
|
|
|
"lang": "en",
|
|
|
|
"language": "English",
|
|
|
|
}))
|