2015-11-15 01:30:26 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2017-05-20 11:27:43 +02:00
|
|
|
# Copyright 2015-2017 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.
|
|
|
|
|
|
|
|
"""Extract images from http://www.hbrowse.com/"""
|
|
|
|
|
2017-05-20 11:27:43 +02:00
|
|
|
from .common import Extractor, MangaExtractor, Message
|
2017-09-24 15:59:25 +02:00
|
|
|
from .. import text, util
|
2016-09-14 09:48:47 +02:00
|
|
|
import json
|
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2017-09-20 16:25:25 +02:00
|
|
|
class HbrowseExtractor(Extractor):
|
|
|
|
"""Base class for hbrowse extractors"""
|
2016-09-14 09:48:47 +02:00
|
|
|
category = "hbrowse"
|
2017-09-20 16:25:25 +02:00
|
|
|
root = "http://www.hbrowse.com"
|
|
|
|
|
|
|
|
@staticmethod
|
2017-09-24 15:59:25 +02:00
|
|
|
def parse_page(page, data):
|
|
|
|
"""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)
|
|
|
|
|
|
|
|
data["manga"] = text.unescape(data["manga"])
|
2017-09-24 15:59:25 +02:00
|
|
|
data["total"] = util.safe_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
|
|
|
|
|
|
|
|
|
|
|
class HbrowseMangaExtractor(MangaExtractor, HbrowseExtractor):
|
|
|
|
"""Extractor for manga from hbrowse.com"""
|
2017-05-20 11:27:43 +02:00
|
|
|
pattern = [r"(?:https?://)?((?:www\.)?hbrowse\.com/\d+)/?$"]
|
|
|
|
reverse = False
|
2016-09-14 09:48:47 +02:00
|
|
|
test = [("http://www.hbrowse.com/10363", {
|
2017-05-03 15:17:08 +02:00
|
|
|
"url": "4d9def5df21c23f8c3d36de2076c189c02ea43bd",
|
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, {
|
|
|
|
"manga_id": util.safe_int(
|
|
|
|
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)
|
2017-09-24 15:59:25 +02:00
|
|
|
data["chapter"] = util.safe_int(url.rpartition("/")[2][1:])
|
2017-09-20 16:41:39 +02:00
|
|
|
data["title"] = title
|
|
|
|
results.append((url, data.copy()))
|
2015-11-15 01:30:26 +01:00
|
|
|
|
|
|
|
|
2017-09-20 16:25:25 +02:00
|
|
|
class HbrowseChapterExtractor(HbrowseExtractor):
|
2016-09-14 09:48:47 +02:00
|
|
|
"""Extractor for manga-chapters from hbrowse.com"""
|
|
|
|
subcategory = "chapter"
|
2017-09-20 16:25:25 +02:00
|
|
|
directory_fmt = ["{category}", "{manga_id} {manga}", "c{chapter:>05}"]
|
|
|
|
filename_fmt = ("{category}_{manga_id}_{chapter:>05}_"
|
2017-02-01 00:53:19 +01:00
|
|
|
"{num:>03}.{extension}")
|
2017-09-20 16:25:25 +02:00
|
|
|
pattern = [r"(?:https?://)?(?:www\.)?hbrowse\.com/(\d+)/c(\d+)"]
|
2016-09-14 09:48:47 +02:00
|
|
|
test = [("http://www.hbrowse.com/10363/c00000", {
|
|
|
|
"url": "634f4800858913f097bc3b62a8fedaf74b5254bd",
|
2017-09-20 16:25:25 +02:00
|
|
|
"keyword": "730bd33de2a0a0fb4e0b6dcdafedcaeee1060047",
|
2016-09-14 09:48:47 +02:00
|
|
|
"content": "44578ebbe176c2c27434966aef22945787e2781e",
|
|
|
|
})]
|
2015-11-15 01:30:26 +01:00
|
|
|
|
|
|
|
def __init__(self, match):
|
2017-09-20 16:25:25 +02:00
|
|
|
HbrowseExtractor.__init__(self)
|
2015-11-15 01:30:26 +01:00
|
|
|
self.gid, self.chapter = match.groups()
|
2017-09-20 16:25:25 +02:00
|
|
|
self.path = "/{}/c{}/".format(self.gid, self.chapter)
|
2015-11-15 01:30:26 +01:00
|
|
|
|
|
|
|
def items(self):
|
2017-09-20 16:25:25 +02:00
|
|
|
page = self.request(self.root + self.path).text
|
2015-11-15 01:30:26 +01:00
|
|
|
data = self.get_job_metadata(page)
|
|
|
|
yield Message.Version, 1
|
|
|
|
yield Message.Directory, data
|
2017-09-20 16:25:25 +02:00
|
|
|
for data["num"], url in enumerate(self.get_image_urls(page), 1):
|
2016-09-14 09:48:47 +02:00
|
|
|
yield Message.Url, url, text.nameext_from_url(url, data)
|
2015-11-15 01:30:26 +01:00
|
|
|
|
|
|
|
def get_job_metadata(self, page):
|
|
|
|
"""Collect metadata for extractor-job"""
|
2017-09-24 15:59:25 +02:00
|
|
|
return self.parse_page(page, {
|
|
|
|
"manga_id": util.safe_int(self.gid),
|
|
|
|
"chapter": util.safe_int(self.chapter)
|
|
|
|
})
|
2015-11-15 01:30:26 +01:00
|
|
|
|
2016-09-14 09:48:47 +02:00
|
|
|
def get_image_urls(self, page):
|
2015-11-15 01:30:26 +01:00
|
|
|
"""Yield all image-urls for a 'chapter'"""
|
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] + "]"
|
|
|
|
return [base + name for name in json.loads(json_data)]
|