2015-11-07 02:32:59 +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.
|
|
|
|
|
|
|
|
"""Extract manga pages from http://kissmanga.com/"""
|
|
|
|
|
|
|
|
from .common import Extractor, Message
|
|
|
|
from .. import text, cloudflare
|
|
|
|
import re
|
|
|
|
|
|
|
|
class KissmangaExtractor(Extractor):
|
|
|
|
|
2015-11-21 04:26:30 +01:00
|
|
|
category = "kissmanga"
|
|
|
|
directory_fmt = ["{category}", "{manga}", "c{chapter:>03}{chapter-minor} - {title}"]
|
|
|
|
filename_fmt = "{manga}_c{chapter:>03}{chapter-minor}_{page:>03}.{extension}"
|
|
|
|
pattern = [r"(?:https?://)?(?:www\.)?kissmanga\.com/Manga/.+/.+\?id=\d+"]
|
|
|
|
|
2015-11-07 02:32:59 +01:00
|
|
|
def __init__(self, match):
|
|
|
|
Extractor.__init__(self)
|
|
|
|
self.url = match.group(0)
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
cloudflare.bypass_ddos_protection(self.session, "http://kissmanga.com")
|
|
|
|
page = self.request(self.url).text
|
|
|
|
data = self.get_job_metadata(page)
|
|
|
|
imgs = self.get_image_urls(page)
|
|
|
|
data["count"] = len(imgs)
|
|
|
|
yield Message.Version, 1
|
|
|
|
yield Message.Directory, data
|
|
|
|
for num, url in enumerate(imgs, 1):
|
|
|
|
data["page"] = num
|
2015-11-16 17:32:26 +01:00
|
|
|
yield Message.Url, url, text.nameext_from_url(url, data)
|
2015-11-07 02:32:59 +01:00
|
|
|
|
2015-11-21 04:26:30 +01:00
|
|
|
def get_job_metadata(self, page):
|
2015-11-07 02:32:59 +01:00
|
|
|
"""Collect metadata for extractor-job"""
|
|
|
|
manga, pos = text.extract(page, "Read manga\n", "\n")
|
|
|
|
cinfo, pos = text.extract(page, "", "\n", pos)
|
2015-11-07 13:28:07 +01:00
|
|
|
match = re.match(
|
|
|
|
r"(?:Vol.0*(\d+) )?(?:Ch.)?0*(\d+)(?:\.0*(\d+))?(?:: (.+))?", cinfo)
|
|
|
|
chminor = match.group(3)
|
2015-11-07 02:32:59 +01:00
|
|
|
return {
|
2015-11-21 04:26:30 +01:00
|
|
|
"category": self.category,
|
2015-11-07 02:32:59 +01:00
|
|
|
"manga": manga,
|
|
|
|
"volume": match.group(1) or "",
|
|
|
|
"chapter": match.group(2),
|
2015-11-07 13:28:07 +01:00
|
|
|
"chapter-minor": "."+chminor if chminor else "",
|
|
|
|
"title": match.group(4) or "",
|
2015-11-07 02:32:59 +01:00
|
|
|
"lang": "en",
|
|
|
|
"language": "English",
|
|
|
|
}
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_image_urls(page):
|
|
|
|
"""Extract list of all image-urls for a manga chapter"""
|
|
|
|
pos = 0
|
|
|
|
images = []
|
|
|
|
while True:
|
|
|
|
url, pos = text.extract(page, 'lstImages.push("', '"', pos)
|
|
|
|
if not url:
|
|
|
|
return images
|
|
|
|
images.append(url)
|