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

102 lines
3.9 KiB
Python
Raw Normal View History

2015-11-26 03:06:08 +01:00
# -*- coding: utf-8 -*-
# Copyright 2015 Mike Fährmann
#
# 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.
2015-11-28 22:21:35 +01:00
"""Extract manga-chapters and entire manga from from http://www.mangahere.co/"""
2015-11-26 03:06:08 +01:00
from .common import Extractor, AsynchronousExtractor, Message
2015-11-26 03:06:08 +01:00
from .. import text
import re
2015-11-28 00:11:28 +01:00
class MangaHereMangaExtractor(Extractor):
2015-11-28 22:21:35 +01:00
"""Extract all manga-chapters from mangahere"""
2015-11-28 00:11:28 +01:00
category = "mangahere"
2015-11-30 01:11:13 +01:00
subcategory = "manga"
2015-11-28 00:11:28 +01: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
def __init__(self, match):
Extractor.__init__(self)
self.url = match.group(0) + "/"
def items(self):
yield Message.Version, 1
for chapter in self.get_chapters():
yield Message.Queue, chapter
def get_chapters(self):
2015-11-28 22:21:35 +01:00
"""Return a list of all chapter urls"""
2015-11-28 00:11:28 +01:00
page = self.request(self.url).text
2015-11-28 02:06:29 +01:00
return reversed(list(
text.extract_iter(page, '<a class="color_0077" href="', '"',
page.index('<div class="detail_list">'))
))
2015-11-28 00:11:28 +01:00
class MangaHereChapterExtractor(AsynchronousExtractor):
2015-11-28 22:21:35 +01:00
"""Extract a single manga-chapter from mangahere"""
2015-11-26 03:06:08 +01:00
category = "mangahere"
2015-11-30 01:11:13 +01:00
subcategory = "chapter"
directory_fmt = ["{category}", "{manga}", "c{chapter:>03}{chapter-minor}"]
filename_fmt = "{manga}_c{chapter:>03}{chapter-minor}_{page:>03}.{extension}"
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/", {
"url": "c807532e919af7600fe0ef21fb89c5062637dd87",
"keyword": "f342e3df9fa39eb10cf7ba5ef3300df6ad77f332",
})]
2015-11-26 03:06:08 +01:00
url_fmt = "http://www.mangahere.co/manga/{}/{}.html"
def __init__(self, match):
AsynchronousExtractor.__init__(self)
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)
yield Message.Version, 1
yield Message.Directory, data.copy()
for i, url in zip(range(int(data["count"])), self.get_image_urls(page)):
2015-11-26 03:06:08 +01:00
data["page"] = i+1
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>')
chid , pos = text.extract(page, 'a.mhcdn.net/store/manga/', '/', pos)
_ , pos = text.extract(page, '<select class="wid60"', '', pos)
_ , pos = text.extract(page, '</select>', '', pos)
count, pos = text.extract(page, '>', '<', pos-30)
manga = re.match(r"(.+) \d+(\.\d+)? - Read .+ Chapter \d+(\.\d+)? Online", manga).group(1)
2015-11-26 03:06:08 +01:00
return {
"category": self.category,
"manga": text.unescape(manga),
# "title": TODO,
"volume": self.volume or "",
"chapter": self.chapter,
"chapter-minor": self.chminor or "",
2015-11-26 03:06:08 +01:00
"chapter-id": chid,
"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)
url, pos = text.extract(page, '<img src="', '"', pos)
yield url
pnum += 2
page = self.request(self.url_fmt.format(self.part, pnum)).text