2016-09-22 17:20:57 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2017-04-20 13:20:41 +02:00
|
|
|
# Copyright 2015-2017 Mike Fährmann
|
2016-09-22 17:20:57 +02: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.
|
|
|
|
|
2017-04-20 13:20:41 +02:00
|
|
|
"""Extract manga-chapters from https://dynasty-scans.com/"""
|
2016-09-22 17:20:57 +02:00
|
|
|
|
|
|
|
from .common import Extractor, Message
|
2017-10-10 17:14:39 +02:00
|
|
|
from .. import text, util
|
2016-09-22 17:20:57 +02:00
|
|
|
import re
|
|
|
|
import json
|
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2016-09-22 17:20:57 +02:00
|
|
|
class DynastyscansChapterExtractor(Extractor):
|
|
|
|
"""Extractor for manga-chapters from dynasty-scans.com"""
|
|
|
|
category = "dynastyscans"
|
|
|
|
subcategory = "chapter"
|
2017-10-10 17:14:39 +02:00
|
|
|
directory_fmt = [
|
|
|
|
"{category}", "{manga}", "c{chapter:>03}{chapter_minor}{title:?: //}"]
|
|
|
|
filename_fmt = (
|
|
|
|
"{manga}_c{chapter:>03}{chapter_minor}_{page:>03}.{extension}")
|
2016-09-22 17:20:57 +02:00
|
|
|
pattern = [r"(?:https?://)?(?:www\.)?dynasty-scans\.com/chapters/([^/]+)"]
|
|
|
|
test = [
|
2017-02-01 00:53:19 +01:00
|
|
|
(("http://dynasty-scans.com/chapters/"
|
|
|
|
"hitoribocchi_no_oo_seikatsu_ch33"), {
|
2017-06-02 09:10:58 +02:00
|
|
|
"url": "ff79ea9956522a8dafd261c1fbe3c74aa8470dc5",
|
2017-10-10 17:14:39 +02:00
|
|
|
"keyword": "fb2f470b995df5b301ccede31ed9829a010236db",
|
2016-09-22 17:20:57 +02:00
|
|
|
}),
|
2017-02-01 00:53:19 +01:00
|
|
|
(("http://dynasty-scans.com/chapters/"
|
|
|
|
"new_game_the_spinoff_special_13"), {
|
2017-04-20 13:20:41 +02:00
|
|
|
"url": "2cd5e04bd16f842dc884c145a44cf0c64ec27a21",
|
2017-10-10 17:14:39 +02:00
|
|
|
"keyword": "281bbe0fb74b812ced595619ca5876983490dc0e",
|
2016-09-22 17:20:57 +02:00
|
|
|
}),
|
|
|
|
]
|
2017-04-20 13:20:41 +02:00
|
|
|
url_base = "https://dynasty-scans.com/"
|
2016-09-22 17:20:57 +02:00
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
Extractor.__init__(self)
|
|
|
|
self.chaptername = match.group(1)
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
page = self.request(self.url_base + "chapters/" + self.chaptername,
|
|
|
|
encoding="utf-8").text
|
|
|
|
data = self.get_job_metadata(page)
|
|
|
|
imgs = self.get_image_data(page)
|
|
|
|
data["count"] = len(imgs)
|
|
|
|
yield Message.Version, 1
|
|
|
|
yield Message.Directory, data
|
2017-10-10 17:14:39 +02:00
|
|
|
for data["page"], img in enumerate(imgs, 1):
|
2016-09-22 17:20:57 +02:00
|
|
|
url = self.url_base + img["image"]
|
|
|
|
text.nameext_from_url(url, data)
|
|
|
|
data["name"] = img["name"]
|
|
|
|
yield Message.Url, url, data
|
|
|
|
|
|
|
|
def get_job_metadata(self, page):
|
|
|
|
"""Collect metadata for extractor-job"""
|
|
|
|
info , pos = text.extract(page, "<h3 id='chapter-title'><b>", "</b>")
|
|
|
|
author, pos = text.extract(page, " by ", "</a>", pos)
|
2017-10-10 17:14:39 +02:00
|
|
|
group , pos = text.extract(page, '"icon-print"></i> ', '</span>', pos)
|
2017-02-01 00:53:19 +01:00
|
|
|
date , pos = text.extract(page, '"icon-calendar"></i> ', '<', pos)
|
2017-10-10 17:14:39 +02:00
|
|
|
|
2016-09-22 17:20:57 +02:00
|
|
|
match = re.match(
|
2017-10-10 17:14:39 +02:00
|
|
|
(r"(?:<a[^>]*>)?([^<]+)(?:</a>)?" # manga name
|
|
|
|
r"(?: ch(\d+)([^:<]*))?" # chapter info
|
|
|
|
r"(?:: (.+))?"), # title
|
2016-09-22 17:20:57 +02:00
|
|
|
info
|
|
|
|
)
|
2017-10-10 17:14:39 +02:00
|
|
|
|
2016-09-22 17:20:57 +02:00
|
|
|
return {
|
|
|
|
"manga": text.unescape(match.group(1)),
|
2017-10-10 17:14:39 +02:00
|
|
|
"chapter": util.safe_int(match.group(2)),
|
|
|
|
"chapter_minor": match.group(3) or "",
|
|
|
|
"title": text.unescape(match.group(4) or ""),
|
2016-09-22 17:20:57 +02:00
|
|
|
"author": text.remove_html(author),
|
2017-10-10 17:14:39 +02:00
|
|
|
"group": (text.remove_html(group) or
|
|
|
|
text.extract(group, ' alt="', '"')[0] or ""),
|
2016-09-22 17:20:57 +02:00
|
|
|
"date": date,
|
|
|
|
"lang": "en",
|
|
|
|
"language": "English",
|
|
|
|
}
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_image_data(page):
|
|
|
|
"""Extract list of all image-urls for a manga chapter"""
|
|
|
|
data = text.extract(page, "var pages = ", ";\n")[0]
|
|
|
|
return json.loads(data)
|