2016-10-23 17:51:12 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2018-01-07 21:42:28 +01:00
|
|
|
# Copyright 2016-2018 Mike Fährmann
|
2016-10-23 17:51:12 +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-11 21:03:40 +02:00
|
|
|
"""Base classes for extractors for FoOlSlide based sites"""
|
2016-10-23 17:51:12 +02:00
|
|
|
|
2017-08-29 22:42:48 +02:00
|
|
|
from .common import SharedConfigExtractor, MangaExtractor, Message
|
2017-03-28 13:12:44 +02:00
|
|
|
from .. import text, util
|
2017-10-21 16:42:45 +02:00
|
|
|
import base64
|
2016-10-23 17:51:12 +02:00
|
|
|
import json
|
improved foolslide-based extractors
- this includes dokireader, fallenangels, jaiminisbox, powermanga,
sensescans, worldthree, yonkouprod, gomanga, yomanga
- added 'chapter_string', 'chapter_id', 'chapter_minor' and 'count'
keywords
- changed the 'chapter' keyword to always be just a number
- changed the default directory format
2017-02-16 23:42:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
CHAPTER_RE = (
|
|
|
|
r"/read/[^/]+"
|
2018-01-07 21:42:28 +01:00
|
|
|
r"/(?P<lang>[a-z-]+)"
|
improved foolslide-based extractors
- this includes dokireader, fallenangels, jaiminisbox, powermanga,
sensescans, worldthree, yonkouprod, gomanga, yomanga
- added 'chapter_string', 'chapter_id', 'chapter_minor' and 'count'
keywords
- changed the 'chapter' keyword to always be just a number
- changed the default directory format
2017-02-16 23:42:30 +01:00
|
|
|
r"/(?P<volume>\d+)"
|
|
|
|
r"/(?P<chapter>\d+)"
|
|
|
|
r"(?:/(?P<chapter_minor>\d+))?)"
|
|
|
|
)
|
|
|
|
|
2017-04-11 21:03:40 +02:00
|
|
|
MANGA_RE = (
|
|
|
|
r"/series/[^/]+/?$)"
|
|
|
|
)
|
|
|
|
|
improved foolslide-based extractors
- this includes dokireader, fallenangels, jaiminisbox, powermanga,
sensescans, worldthree, yonkouprod, gomanga, yomanga
- added 'chapter_string', 'chapter_id', 'chapter_minor' and 'count'
keywords
- changed the 'chapter' keyword to always be just a number
- changed the default directory format
2017-02-16 23:42:30 +01:00
|
|
|
|
|
|
|
def chapter_pattern(domain_re):
|
|
|
|
return [r"(?:https?://)?(" + domain_re + CHAPTER_RE]
|
2016-10-23 17:51:12 +02:00
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2017-04-11 21:03:40 +02:00
|
|
|
def manga_pattern(domain_re):
|
|
|
|
return [r"(?:https?://)?(" + domain_re + MANGA_RE]
|
|
|
|
|
|
|
|
|
2017-09-24 16:57:47 +02:00
|
|
|
class FoolslideExtractor(SharedConfigExtractor):
|
|
|
|
"""Base class for FoOlSlide extractors"""
|
2017-08-29 22:42:48 +02:00
|
|
|
basecategory = "foolslide"
|
2017-09-24 16:57:47 +02:00
|
|
|
scheme = "https"
|
|
|
|
|
|
|
|
def request(self, url):
|
|
|
|
return SharedConfigExtractor.request(
|
|
|
|
self, url, encoding="utf-8", method="post", data={"adult": "true"})
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def parse_chapter_url(url, data):
|
2017-09-25 12:59:24 +02:00
|
|
|
info = url.partition("/read/")[2].rstrip("/").split("/")
|
2018-01-07 21:42:28 +01:00
|
|
|
lang = info[1].partition("-")[0]
|
|
|
|
data["lang"] = lang
|
|
|
|
data["language"] = util.code_to_language(lang)
|
2017-09-24 16:57:47 +02:00
|
|
|
data["volume"] = util.safe_int(info[2])
|
|
|
|
data["chapter"] = util.safe_int(info[3])
|
2017-09-25 12:59:24 +02:00
|
|
|
data["chapter_minor"] = "." + info[4] if len(info) >= 5 else ""
|
2017-09-24 16:57:47 +02:00
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
class FoolslideChapterExtractor(FoolslideExtractor):
|
|
|
|
"""Base class for chapter extractors for FoOlSlide based sites"""
|
2016-10-23 17:51:12 +02:00
|
|
|
subcategory = "chapter"
|
improved foolslide-based extractors
- this includes dokireader, fallenangels, jaiminisbox, powermanga,
sensescans, worldthree, yonkouprod, gomanga, yomanga
- added 'chapter_string', 'chapter_id', 'chapter_minor' and 'count'
keywords
- changed the 'chapter' keyword to always be just a number
- changed the default directory format
2017-02-16 23:42:30 +01:00
|
|
|
directory_fmt = ["{category}", "{manga}", "{chapter_string}"]
|
2017-10-02 19:06:24 +02:00
|
|
|
filename_fmt = (
|
|
|
|
"{manga}_c{chapter:>03}{chapter_minor}_{page:>03}.{extension}")
|
2018-01-30 22:49:16 +01:00
|
|
|
archive_fmt = "{id}"
|
2017-10-21 16:42:45 +02:00
|
|
|
method = "default"
|
2016-10-23 17:51:12 +02:00
|
|
|
|
improved foolslide-based extractors
- this includes dokireader, fallenangels, jaiminisbox, powermanga,
sensescans, worldthree, yonkouprod, gomanga, yomanga
- added 'chapter_string', 'chapter_id', 'chapter_minor' and 'count'
keywords
- changed the 'chapter' keyword to always be just a number
- changed the default directory format
2017-02-16 23:42:30 +01:00
|
|
|
def __init__(self, match, url=None):
|
2017-09-24 16:57:47 +02:00
|
|
|
FoolslideExtractor.__init__(self)
|
improved foolslide-based extractors
- this includes dokireader, fallenangels, jaiminisbox, powermanga,
sensescans, worldthree, yonkouprod, gomanga, yomanga
- added 'chapter_string', 'chapter_id', 'chapter_minor' and 'count'
keywords
- changed the 'chapter' keyword to always be just a number
- changed the default directory format
2017-02-16 23:42:30 +01:00
|
|
|
self.url = url or self.scheme + "://" + match.group(1)
|
2016-10-23 17:51:12 +02:00
|
|
|
|
|
|
|
def items(self):
|
2017-09-24 16:57:47 +02:00
|
|
|
page = self.request(self.url).text
|
2017-04-11 21:03:40 +02:00
|
|
|
data = self.get_metadata(page)
|
improved foolslide-based extractors
- this includes dokireader, fallenangels, jaiminisbox, powermanga,
sensescans, worldthree, yonkouprod, gomanga, yomanga
- added 'chapter_string', 'chapter_id', 'chapter_minor' and 'count'
keywords
- changed the 'chapter' keyword to always be just a number
- changed the default directory format
2017-02-16 23:42:30 +01:00
|
|
|
imgs = self.get_images(page)
|
|
|
|
|
|
|
|
data["count"] = len(imgs)
|
2017-09-24 16:57:47 +02:00
|
|
|
data["chapter_id"] = util.safe_int(imgs[0]["chapter_id"])
|
improved foolslide-based extractors
- this includes dokireader, fallenangels, jaiminisbox, powermanga,
sensescans, worldthree, yonkouprod, gomanga, yomanga
- added 'chapter_string', 'chapter_id', 'chapter_minor' and 'count'
keywords
- changed the 'chapter' keyword to always be just a number
- changed the default directory format
2017-02-16 23:42:30 +01:00
|
|
|
|
2016-10-23 17:51:12 +02:00
|
|
|
yield Message.Version, 1
|
|
|
|
yield Message.Directory, data
|
improved foolslide-based extractors
- this includes dokireader, fallenangels, jaiminisbox, powermanga,
sensescans, worldthree, yonkouprod, gomanga, yomanga
- added 'chapter_string', 'chapter_id', 'chapter_minor' and 'count'
keywords
- changed the 'chapter' keyword to always be just a number
- changed the default directory format
2017-02-16 23:42:30 +01:00
|
|
|
for data["page"], image in enumerate(imgs, 1):
|
2016-10-23 17:51:12 +02:00
|
|
|
try:
|
|
|
|
url = image["url"]
|
|
|
|
del image["url"]
|
2017-09-24 16:57:47 +02:00
|
|
|
del image["chapter_id"]
|
2016-10-23 17:51:12 +02:00
|
|
|
del image["thumb_url"]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
2017-09-24 16:57:47 +02:00
|
|
|
for key in ("height", "id", "size", "width"):
|
|
|
|
image[key] = util.safe_int(image[key])
|
2016-10-23 17:51:12 +02:00
|
|
|
data.update(image)
|
|
|
|
text.nameext_from_url(data["filename"], data)
|
|
|
|
yield Message.Url, url, data
|
|
|
|
|
2017-04-11 21:03:40 +02:00
|
|
|
def get_metadata(self, page):
|
2016-10-23 17:51:12 +02:00
|
|
|
"""Collect metadata for extractor-job"""
|
improved foolslide-based extractors
- this includes dokireader, fallenangels, jaiminisbox, powermanga,
sensescans, worldthree, yonkouprod, gomanga, yomanga
- added 'chapter_string', 'chapter_id', 'chapter_minor' and 'count'
keywords
- changed the 'chapter' keyword to always be just a number
- changed the default directory format
2017-02-16 23:42:30 +01:00
|
|
|
_ , pos = text.extract(page, '<h1 class="tbtitle dnone">', '')
|
|
|
|
manga , pos = text.extract(page, 'title="', '"', pos)
|
|
|
|
chapter, pos = text.extract(page, 'title="', '"', pos)
|
|
|
|
chapter = text.unescape(chapter)
|
2017-09-24 16:57:47 +02:00
|
|
|
return self.parse_chapter_url(self.url, {
|
|
|
|
"manga": text.unescape(manga).strip(),
|
|
|
|
"title": chapter.partition(":")[2].strip(),
|
|
|
|
"chapter_string": chapter,
|
|
|
|
})
|
2016-10-23 17:51:12 +02:00
|
|
|
|
2017-01-10 00:05:08 +01:00
|
|
|
def get_images(self, page):
|
2016-10-23 17:51:12 +02:00
|
|
|
"""Return a list of all images in this chapter"""
|
2017-10-21 16:42:45 +02:00
|
|
|
if self.method == "base64":
|
|
|
|
base64_data = text.extract(page, 'atob("', '"')[0].encode()
|
|
|
|
data = base64.b64decode(base64_data).decode()
|
|
|
|
elif self.method == "double":
|
2017-01-10 00:05:08 +01:00
|
|
|
pos = page.find("[{")
|
2017-10-21 16:42:45 +02:00
|
|
|
data = text.extract(page, " = ", ";", pos)[0]
|
|
|
|
else:
|
|
|
|
data = text.extract(page, "var pages = ", ";")[0]
|
|
|
|
return json.loads(data)
|
2017-04-11 21:03:40 +02:00
|
|
|
|
|
|
|
|
2017-09-24 16:57:47 +02:00
|
|
|
class FoolslideMangaExtractor(FoolslideExtractor, MangaExtractor):
|
2017-04-11 21:03:40 +02:00
|
|
|
"""Base class for manga extractors for FoOlSlide based sites"""
|
|
|
|
|
2017-05-20 11:27:43 +02:00
|
|
|
def chapters(self, page):
|
2017-04-11 21:03:40 +02:00
|
|
|
"""Return a list of all chapter urls"""
|
2017-09-12 16:44:38 +02:00
|
|
|
manga , pos = text.extract(page, '<h1 class="title">', '</h1>')
|
|
|
|
author, pos = text.extract(page, '<b>Author</b>: ', '<br', pos)
|
|
|
|
artist, pos = text.extract(page, '<b>Artist</b>: ', '<br', pos)
|
2017-09-24 16:57:47 +02:00
|
|
|
manga = text.unescape(manga).strip()
|
2017-09-12 16:44:38 +02:00
|
|
|
|
|
|
|
results = []
|
|
|
|
while True:
|
|
|
|
url, pos = text.extract(
|
|
|
|
page, '<div class="title"><a href="', '"', pos)
|
|
|
|
if not url:
|
|
|
|
return results
|
|
|
|
|
|
|
|
chapter, pos = text.extract(page, 'title="', '"', pos)
|
|
|
|
group , pos = text.extract(page, 'title="', '"', pos)
|
2017-09-24 16:57:47 +02:00
|
|
|
|
|
|
|
results.append((url, self.parse_chapter_url(url, {
|
2017-09-12 16:44:38 +02:00
|
|
|
"manga": manga, "author": author, "artist": artist,
|
|
|
|
"group": group, "chapter_string": chapter,
|
|
|
|
"title": chapter.partition(": ")[2] or "",
|
2017-09-24 16:57:47 +02:00
|
|
|
})))
|