1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 18:53:21 +01:00
gallery-dl/gallery_dl/extractor/redhawkscans.py

66 lines
2.4 KiB
Python
Raw Normal View History

2015-06-25 16:55:28 +02: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.
"""Extract manga pages from http://manga.redhawkscans.com/"""
2015-10-05 17:15:31 +02:00
from .common import Extractor, Message
2015-10-03 15:43:02 +02:00
from .. import text
2015-06-25 16:55:28 +02:00
import os.path
import json
import re
info = {
"category": "redhawkscans",
"extractor": "RedHawkScansExtractor",
2015-06-25 19:24:30 +02:00
"directory": ["{category}", "{manga}", "c{chapter:>03}{chapter-minor} - {title}"],
"filename": "{manga}_c{chapter:>03}{chapter-minor}_{page:>03}.{extension}",
2015-06-25 16:55:28 +02:00
"pattern": [
r"(?:https?://)?manga\.redhawkscans\.com/reader/read/(.+)(?:/page)?",
2015-06-25 16:55:28 +02:00
],
}
2015-10-05 17:15:31 +02:00
class RedHawkScansExtractor(Extractor):
2015-06-25 16:55:28 +02:00
url_base = "https://manga.redhawkscans.com/reader/read/"
def __init__(self, match):
2015-10-05 17:15:31 +02:00
Extractor.__init__(self)
self.category = info["category"]
2015-06-25 16:55:28 +02:00
self.part = match.group(1)
def items(self):
yield Message.Version, 1
data, pages = self.get_job_metadata()
yield Message.Directory, data
for page_index, page_data in enumerate(pages, 1):
name, ext = os.path.splitext(page_data["filename"])
page_data.update(data)
page_data["page"] = page_index
page_data["name"] = name
page_data["extension"] = ext[1:]
yield Message.Url, "https" + page_data["url"][4:], page_data
def get_job_metadata(self):
"""Collect metadata for extractor-job"""
response = self.request(self.url_base + self.part)
response.encoding = "utf-8"
page = response.text
2015-10-03 15:43:02 +02:00
_ , pos = text.extract(page, '<h1 class="tbtitle dnone">', '')
manga , pos = text.extract(page, 'title="', '"', pos)
chapter , pos = text.extract(page, '">', '</a>', pos)
json_data, pos = text.extract(page, 'var pages = ', ';', pos)
match = re.match(r"(\w+ (\d+)([^:+]*)(?:: (.*))?|[^:]+)", chapter)
2015-06-25 16:55:28 +02:00
return {
"category": self.category,
2015-10-03 15:43:02 +02:00
"manga": text.unescape(manga),
2015-06-25 19:24:30 +02:00
"chapter": match.group(2) or match.group(1),
"chapter-minor": match.group(3) or "",
"language": "English", #TODO: lookup table for language codes (en, it, ch, ...)
2015-10-03 15:43:02 +02:00
"title": text.unescape(match.group(4) or ""),
2015-06-25 17:59:20 +02:00
}, json.loads(json_data)