1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-23 11:12:40 +01:00
gallery-dl/gallery_dl/extractor/mangahere.py

154 lines
5.7 KiB
Python
Raw Normal View History

2015-11-26 03:06:08 +01:00
# -*- coding: utf-8 -*-
2022-02-06 21:39:24 +01:00
# Copyright 2015-2022 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.
2022-02-06 21:39:24 +01:00
"""Extractors for https://www.mangahere.cc/"""
2015-11-26 03:06:08 +01:00
from .common import ChapterExtractor, MangaExtractor
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"
root_mobile = "https://m.mangahere.cc"
url_fmt = root_mobile + "/manga/{}/{}.html"
2018-05-16 16:22:05 +02:00
class MangahereChapterExtractor(MangahereBase, ChapterExtractor):
"""Extractor for manga-chapters from mangahere.cc"""
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/", {
"keyword": "7c98d7b50a47e6757b089aa875a53aa970cac66f",
2018-05-16 16:22:05 +02:00
"content": "708d475f06893b88549cbd30df1e3f9428f2c884",
}),
# URLs without HTTP scheme (#1070)
("https://www.mangahere.cc/manga/beastars/c196/1.html", {
"pattern": "https://zjcdn.mangahere.org/.*",
}),
("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()
url = self.url_fmt.format(self.part, 1)
ChapterExtractor.__init__(self, match, url)
self.session.headers["Referer"] = self.root_mobile + "/"
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(),
"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),
"count": text.parse_int(count),
2015-11-26 03:06:08 +01:00
"lang": "en",
"language": "English",
}
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 text.ensure_http_scheme(url), None
2019-02-10 22:09:29 +01:00
url, pos = text.extract(page, ' src="', '"', pos)
yield text.ensure_http_scheme(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 ""
class MangahereMangaExtractor(MangahereBase, MangaExtractor):
"""Extractor for manga from mangahere.cc"""
chapterclass = MangahereChapterExtractor
pattern = (r"(?:https?://)?(?:www\.|m\.)?mangahere\.c[co]"
2022-02-06 21:39:24 +01:00
r"(/manga/[^/?#]+/?)(?:#.*)?$")
test = (
("https://www.mangahere.cc/manga/aria/", {
2022-07-12 15:46:51 +02:00
"url": "9c2e54ec42e9a87ad53096c328b33c90750af3e4",
"keyword": "71503c682c5d0c277a50409a8c5fd78e871e3d69",
"count": 71,
}),
("https://www.mangahere.cc/manga/hiyokoi/#50", {
"url": "654850570aa03825cd57e2ae2904af489602c523",
"keyword": "c8084d89a9ea6cf40353093669f9601a39bf5ca2",
}),
# adult filter (#556)
("http://www.mangahere.cc/manga/gunnm_mars_chronicle/", {
"pattern": MangahereChapterExtractor.pattern,
"count": ">= 50",
}),
("https://www.mangahere.co/manga/aria/"),
("https://m.mangahere.co/manga/aria/"),
)
def __init__(self, match):
MangaExtractor.__init__(self, match)
self.session.cookies.set("isAdult", "1", domain="www.mangahere.cc")
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",
}))