2019-01-28 18:00:32 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2023-02-07 23:14:53 +01:00
|
|
|
# Copyright 2019-2023 Mike Fährmann
|
2019-01-28 18:00:32 +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.
|
|
|
|
|
|
|
|
"""Extractors for https://hentaifox.com/"""
|
|
|
|
|
2019-02-26 14:08:02 +01:00
|
|
|
from .common import GalleryExtractor, Extractor, Message
|
2023-02-07 23:14:53 +01:00
|
|
|
from .. import text, util
|
2019-01-28 18:00:32 +01:00
|
|
|
|
|
|
|
|
2019-03-01 23:13:40 +01:00
|
|
|
class HentaifoxBase():
|
|
|
|
"""Base class for hentaifox extractors"""
|
2019-01-28 18:00:32 +01:00
|
|
|
category = "hentaifox"
|
2019-03-01 23:13:40 +01:00
|
|
|
root = "https://hentaifox.com"
|
|
|
|
|
|
|
|
|
|
|
|
class HentaifoxGalleryExtractor(HentaifoxBase, GalleryExtractor):
|
|
|
|
"""Extractor for image galleries on hentaifox.com"""
|
2019-02-11 18:38:47 +01:00
|
|
|
pattern = r"(?:https?://)?(?:www\.)?hentaifox\.com(/gallery/(\d+))"
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://hentaifox.com/gallery/12345/"
|
2019-01-28 18:00:32 +01:00
|
|
|
|
|
|
|
def __init__(self, match):
|
2019-02-26 14:08:02 +01:00
|
|
|
GalleryExtractor.__init__(self, match)
|
2019-02-11 18:38:47 +01:00
|
|
|
self.gallery_id = match.group(2)
|
2019-01-28 18:00:32 +01:00
|
|
|
|
2021-03-13 17:52:53 +01:00
|
|
|
@staticmethod
|
|
|
|
def _split(txt):
|
|
|
|
return [
|
|
|
|
text.remove_html(tag.partition(">")[2], "", "")
|
|
|
|
for tag in text.extract_iter(
|
|
|
|
txt, "class='tag_btn", "<span class='t_badge")
|
|
|
|
]
|
|
|
|
|
|
|
|
def metadata(self, page):
|
2019-04-19 23:02:29 +02:00
|
|
|
extr = text.extract_from(page)
|
2021-03-13 17:52:53 +01:00
|
|
|
split = self._split
|
2019-01-28 18:00:32 +01:00
|
|
|
|
2019-04-19 23:02:29 +02:00
|
|
|
return {
|
|
|
|
"gallery_id": text.parse_int(self.gallery_id),
|
2021-03-13 17:52:53 +01:00
|
|
|
"parody" : split(extr(">Parodies:" , "</ul>")),
|
|
|
|
"characters": split(extr(">Characters:", "</ul>")),
|
|
|
|
"tags" : split(extr(">Tags:" , "</ul>")),
|
|
|
|
"artist" : split(extr(">Artists:" , "</ul>")),
|
|
|
|
"group" : split(extr(">Groups:" , "</ul>")),
|
2019-12-02 18:04:22 +01:00
|
|
|
"type" : text.remove_html(extr(">Category:", "<span")),
|
2023-06-18 20:01:33 +02:00
|
|
|
"title" : text.unescape(extr(
|
|
|
|
'id="gallery_title" value="', '"')),
|
2019-04-19 23:02:29 +02:00
|
|
|
"language" : "English",
|
|
|
|
"lang" : "en",
|
|
|
|
}
|
2019-01-28 18:00:32 +01:00
|
|
|
|
2019-02-11 18:38:47 +01:00
|
|
|
def images(self, page):
|
2021-03-10 00:55:33 +01:00
|
|
|
cover, pos = text.extract(page, '<img src="', '"')
|
|
|
|
data , pos = text.extract(page, "$.parseJSON('", "');", pos)
|
|
|
|
path = "/".join(cover.split("/")[3:-1])
|
|
|
|
|
|
|
|
result = []
|
|
|
|
append = result.append
|
|
|
|
extmap = {"j": "jpg", "p": "png", "g": "gif"}
|
|
|
|
urlfmt = ("/" + path + "/{}.{}").format
|
|
|
|
|
|
|
|
server1 = "https://i.hentaifox.com"
|
|
|
|
server2 = "https://i2.hentaifox.com"
|
|
|
|
|
2023-02-07 23:14:53 +01:00
|
|
|
for num, image in util.json_loads(data).items():
|
2021-03-10 00:55:33 +01:00
|
|
|
ext, width, height = image.split(",")
|
|
|
|
path = urlfmt(num, extmap[ext])
|
|
|
|
append((server1 + path, {
|
|
|
|
"width" : width,
|
|
|
|
"height" : height,
|
|
|
|
"_fallback": (server2 + path,),
|
|
|
|
}))
|
|
|
|
|
|
|
|
return result
|
2019-01-28 22:38:32 +01:00
|
|
|
|
|
|
|
|
2019-03-01 23:13:40 +01:00
|
|
|
class HentaifoxSearchExtractor(HentaifoxBase, Extractor):
|
2019-01-28 22:38:32 +01:00
|
|
|
"""Extractor for search results and listings on hentaifox.com"""
|
|
|
|
subcategory = "search"
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = (r"(?:https?://)?(?:www\.)?hentaifox\.com"
|
2021-02-06 17:52:00 +01:00
|
|
|
r"(/(?:parody|tag|artist|character|search|group)/[^/?%#]+)")
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://hentaifox.com/tag/TAG/"
|
2019-01-28 22:38:32 +01:00
|
|
|
|
|
|
|
def __init__(self, match):
|
2019-02-11 13:31:10 +01:00
|
|
|
Extractor.__init__(self, match)
|
2019-01-28 22:38:32 +01:00
|
|
|
self.path = match.group(1)
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
for gallery in self.galleries():
|
|
|
|
yield Message.Queue, gallery["url"], gallery
|
|
|
|
|
|
|
|
def galleries(self):
|
2019-12-02 18:04:22 +01:00
|
|
|
num = 1
|
2019-01-28 22:38:32 +01:00
|
|
|
|
|
|
|
while True:
|
2019-12-02 18:04:22 +01:00
|
|
|
url = "{}{}/pag/{}/".format(self.root, self.path, num)
|
2019-01-28 22:38:32 +01:00
|
|
|
page = self.request(url).text
|
|
|
|
|
2019-12-02 18:04:22 +01:00
|
|
|
for info in text.extract_iter(
|
|
|
|
page, 'class="g_title"><a href="', '</a>'):
|
|
|
|
url, _, title = info.partition('">')
|
2019-01-28 22:38:32 +01:00
|
|
|
|
|
|
|
yield {
|
2019-12-02 18:04:22 +01:00
|
|
|
"url" : text.urljoin(self.root, url),
|
2019-01-28 22:38:32 +01:00
|
|
|
"gallery_id": text.parse_int(
|
|
|
|
url.strip("/").rpartition("/")[2]),
|
2019-12-02 18:04:22 +01:00
|
|
|
"title" : text.unescape(title),
|
2019-02-12 21:26:41 +01:00
|
|
|
"_extractor": HentaifoxGalleryExtractor,
|
2019-01-28 22:38:32 +01:00
|
|
|
}
|
|
|
|
|
2019-12-02 18:04:22 +01:00
|
|
|
pos = page.find(">Next<")
|
|
|
|
url = text.rextract(page, "href=", ">", pos)[0]
|
2019-01-28 22:38:32 +01:00
|
|
|
if pos == -1 or "/pag" not in url:
|
|
|
|
return
|
2019-12-02 18:04:22 +01:00
|
|
|
num += 1
|