2015-11-15 01:30:26 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-01-14 15:44:23 +01:00
|
|
|
# Copyright 2015-2019 Mike Fährmann
|
2015-11-15 01:30:26 +01: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.
|
|
|
|
|
2019-01-15 12:21:49 +01:00
|
|
|
"""Extract images from https://www.hbrowse.com/"""
|
2015-11-15 01:30:26 +01:00
|
|
|
|
2018-02-03 23:14:32 +01:00
|
|
|
from .common import ChapterExtractor, MangaExtractor
|
2019-01-14 15:44:23 +01:00
|
|
|
from .. import text, exception
|
2016-09-14 09:48:47 +02:00
|
|
|
import json
|
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2018-02-03 23:14:32 +01:00
|
|
|
class HbrowseExtractor():
|
2017-09-20 16:25:25 +02:00
|
|
|
"""Base class for hbrowse extractors"""
|
2016-09-14 09:48:47 +02:00
|
|
|
category = "hbrowse"
|
2019-01-15 12:21:49 +01:00
|
|
|
root = "https://www.hbrowse.com"
|
2017-09-20 16:25:25 +02:00
|
|
|
|
2019-01-14 15:44:23 +01:00
|
|
|
def parse_page(self, page, data):
|
2017-09-24 15:59:25 +02:00
|
|
|
"""Parse metadata on 'page' and add it to 'data'"""
|
2017-09-20 16:25:25 +02:00
|
|
|
text.extract_all(page, (
|
|
|
|
('manga' , '<td class="listLong">', '</td>'),
|
|
|
|
('artist', '<td class="listLong">', '</td>'),
|
|
|
|
('total' , '<td class="listLong">', ' '),
|
|
|
|
('origin', '<td class="listLong">', '</td>'),
|
|
|
|
), values=data)
|
|
|
|
|
2019-01-14 15:44:23 +01:00
|
|
|
if not data["manga"] and "<b>Warning</b>" in page:
|
|
|
|
msg = page.rpartition(">")[2].strip()
|
|
|
|
self.log.error("Site is not accessible: '%s'", msg)
|
|
|
|
raise exception.StopExtraction()
|
|
|
|
|
2017-09-20 16:25:25 +02:00
|
|
|
data["manga"] = text.unescape(data["manga"])
|
2018-04-20 14:53:21 +02:00
|
|
|
data["total"] = text.parse_int(data["total"])
|
2017-09-20 16:25:25 +02:00
|
|
|
data["artist"] = text.remove_html(data["artist"])
|
|
|
|
data["origin"] = text.remove_html(data["origin"])
|
2017-09-24 15:59:25 +02:00
|
|
|
return data
|
2017-09-20 16:25:25 +02:00
|
|
|
|
|
|
|
|
2017-11-14 22:33:17 +01:00
|
|
|
class HbrowseMangaExtractor(HbrowseExtractor, MangaExtractor):
|
2017-09-20 16:25:25 +02:00
|
|
|
"""Extractor for manga from hbrowse.com"""
|
2017-05-20 11:27:43 +02:00
|
|
|
pattern = [r"(?:https?://)?((?:www\.)?hbrowse\.com/\d+)/?$"]
|
|
|
|
reverse = False
|
2019-01-15 12:21:49 +01:00
|
|
|
test = [("https://www.hbrowse.com/10363", {
|
|
|
|
"url": "b89682bfb86c11d2af0dc47463804ec3ac4aadd6",
|
2017-09-20 16:25:25 +02:00
|
|
|
"keyword": "aa0c6ba9ba180f18861aa5d608ff7f1966e666f8",
|
2016-09-14 09:48:47 +02:00
|
|
|
})]
|
|
|
|
|
2017-05-20 11:27:43 +02:00
|
|
|
def chapters(self, page):
|
2017-09-20 16:25:25 +02:00
|
|
|
results = []
|
2017-09-24 15:59:25 +02:00
|
|
|
data = self.parse_page(page, {
|
2018-04-20 14:53:21 +02:00
|
|
|
"manga_id": text.parse_int(
|
2017-09-24 15:59:25 +02:00
|
|
|
self.url.rstrip("/").rpartition("/")[2])
|
|
|
|
})
|
2017-09-20 16:25:25 +02:00
|
|
|
|
|
|
|
pos = 0
|
2016-09-14 09:48:47 +02:00
|
|
|
needle = '<td class="listMiddle">\n<a class="listLink" href="'
|
2017-09-20 16:25:25 +02:00
|
|
|
while True:
|
|
|
|
url, pos = text.extract(page, needle, '"', pos)
|
|
|
|
if not url:
|
|
|
|
return results
|
|
|
|
title, pos = text.extract(page, '>View ', '<', pos)
|
2018-04-20 14:53:21 +02:00
|
|
|
data["chapter"] = text.parse_int(url.rpartition("/")[2][1:])
|
2017-09-20 16:41:39 +02:00
|
|
|
data["title"] = title
|
2018-04-26 17:00:26 +02:00
|
|
|
results.append((text.urljoin(self.root, url), data.copy()))
|
2015-11-15 01:30:26 +01:00
|
|
|
|
|
|
|
|
2018-02-03 23:14:32 +01:00
|
|
|
class HbrowseChapterExtractor(HbrowseExtractor, ChapterExtractor):
|
2016-09-14 09:48:47 +02:00
|
|
|
"""Extractor for manga-chapters from hbrowse.com"""
|
2017-09-20 16:25:25 +02:00
|
|
|
directory_fmt = ["{category}", "{manga_id} {manga}", "c{chapter:>05}"]
|
|
|
|
filename_fmt = ("{category}_{manga_id}_{chapter:>05}_"
|
2018-02-03 23:14:32 +01:00
|
|
|
"{page:>03}.{extension}")
|
2018-02-12 18:07:58 +01:00
|
|
|
archive_fmt = "{manga_id}_{chapter}_{page}"
|
2017-09-20 16:25:25 +02:00
|
|
|
pattern = [r"(?:https?://)?(?:www\.)?hbrowse\.com/(\d+)/c(\d+)"]
|
2019-01-15 12:21:49 +01:00
|
|
|
test = [("https://www.hbrowse.com/10363/c00000", {
|
|
|
|
"url": "6feefbc9f4b98e20d8425ddffa9dd111791dc3e6",
|
2018-02-03 23:14:32 +01:00
|
|
|
"keyword": "f37cafef404696312f5db6ccaaaf72737d309e2d",
|
2016-09-14 09:48:47 +02:00
|
|
|
"content": "44578ebbe176c2c27434966aef22945787e2781e",
|
|
|
|
})]
|
2015-11-15 01:30:26 +01:00
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
self.gid, self.chapter = match.groups()
|
2017-09-20 16:25:25 +02:00
|
|
|
self.path = "/{}/c{}/".format(self.gid, self.chapter)
|
2018-02-03 23:14:32 +01:00
|
|
|
ChapterExtractor.__init__(self, self.root + self.path)
|
2015-11-15 01:30:26 +01:00
|
|
|
|
2018-02-03 23:14:32 +01:00
|
|
|
def get_metadata(self, page):
|
2017-09-24 15:59:25 +02:00
|
|
|
return self.parse_page(page, {
|
2018-04-20 14:53:21 +02:00
|
|
|
"manga_id": text.parse_int(self.gid),
|
|
|
|
"chapter": text.parse_int(self.chapter)
|
2017-09-24 15:59:25 +02:00
|
|
|
})
|
2015-11-15 01:30:26 +01:00
|
|
|
|
2018-02-03 23:14:32 +01:00
|
|
|
def get_images(self, page):
|
2017-09-20 16:25:25 +02:00
|
|
|
base = self.root + "/data" + self.path
|
2016-09-14 09:48:47 +02:00
|
|
|
json_data = text.extract(page, ';list = ', ',"zzz"')[0] + "]"
|
2018-02-03 23:14:32 +01:00
|
|
|
return [(base + name, None) for name in json.loads(json_data)]
|