1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-23 11:12:40 +01:00
gallery-dl/gallery_dl/extractor/hbrowse.py

95 lines
3.4 KiB
Python
Raw Normal View History

2015-11-15 01:30:26 +01:00
# -*- coding: utf-8 -*-
# Copyright 2015-2018 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/"""
from .common import ChapterExtractor, MangaExtractor
from .. import text
2017-11-14 22:33:17 +01:00
from urllib.parse import urljoin
2016-09-14 09:48:47 +02:00
import json
2017-02-01 00:53:19 +01:00
class HbrowseExtractor():
"""Base class for hbrowse extractors"""
2016-09-14 09:48:47 +02:00
category = "hbrowse"
root = "http://www.hbrowse.com"
@staticmethod
def parse_page(page, data):
"""Parse metadata on 'page' and add it to 'data'"""
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"])
data["total"] = text.parse_int(data["total"])
data["artist"] = text.remove_html(data["artist"])
data["origin"] = text.remove_html(data["origin"])
return data
2017-11-14 22:33:17 +01:00
class HbrowseMangaExtractor(HbrowseExtractor, MangaExtractor):
"""Extractor for manga from hbrowse.com"""
pattern = [r"(?:https?://)?((?:www\.)?hbrowse\.com/\d+)/?$"]
reverse = False
2016-09-14 09:48:47 +02:00
test = [("http://www.hbrowse.com/10363", {
"url": "4d9def5df21c23f8c3d36de2076c189c02ea43bd",
"keyword": "aa0c6ba9ba180f18861aa5d608ff7f1966e666f8",
2016-09-14 09:48:47 +02:00
})]
def chapters(self, page):
results = []
data = self.parse_page(page, {
"manga_id": text.parse_int(
self.url.rstrip("/").rpartition("/")[2])
})
pos = 0
2016-09-14 09:48:47 +02:00
needle = '<td class="listMiddle">\n<a class="listLink" href="'
while True:
url, pos = text.extract(page, needle, '"', pos)
if not url:
return results
title, pos = text.extract(page, '>View ', '<', pos)
data["chapter"] = text.parse_int(url.rpartition("/")[2][1:])
data["title"] = title
2017-11-14 22:33:17 +01:00
results.append((urljoin(self.root, url), data.copy()))
2015-11-15 01:30:26 +01:00
class HbrowseChapterExtractor(HbrowseExtractor, ChapterExtractor):
2016-09-14 09:48:47 +02:00
"""Extractor for manga-chapters from hbrowse.com"""
directory_fmt = ["{category}", "{manga_id} {manga}", "c{chapter:>05}"]
filename_fmt = ("{category}_{manga_id}_{chapter:>05}_"
"{page:>03}.{extension}")
2018-02-12 18:07:58 +01:00
archive_fmt = "{manga_id}_{chapter}_{page}"
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",
"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()
self.path = "/{}/c{}/".format(self.gid, self.chapter)
ChapterExtractor.__init__(self, self.root + self.path)
2015-11-15 01:30:26 +01:00
def get_metadata(self, page):
return self.parse_page(page, {
"manga_id": text.parse_int(self.gid),
"chapter": text.parse_int(self.chapter)
})
2015-11-15 01:30:26 +01:00
def get_images(self, page):
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, None) for name in json.loads(json_data)]