2015-11-14 03:19:44 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2018-01-30 22:49:16 +01:00
|
|
|
# Copyright 2015-2018 Mike Fährmann
|
2015-11-14 03:19:44 +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.
|
|
|
|
|
2017-04-20 13:20:41 +02:00
|
|
|
"""Extract images from https://www.hentai-foundry.com/"""
|
2015-11-14 03:19:44 +01:00
|
|
|
|
|
|
|
from .common import Extractor, Message
|
2017-09-24 15:59:25 +02:00
|
|
|
from .. import text, util, exception
|
2015-11-14 03:19:44 +01:00
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2016-09-12 10:20:57 +02:00
|
|
|
class HentaifoundryUserExtractor(Extractor):
|
|
|
|
"""Extractor for all images of a hentai-foundry-user"""
|
2015-11-21 04:26:30 +01:00
|
|
|
category = "hentaifoundry"
|
2015-11-30 01:11:13 +01:00
|
|
|
subcategory = "user"
|
2015-11-21 04:26:30 +01:00
|
|
|
directory_fmt = ["{category}", "{artist}"]
|
|
|
|
filename_fmt = "{category}_{index}_{title}.{extension}"
|
2018-01-30 22:49:16 +01:00
|
|
|
archive_fmt = "{index}"
|
2017-07-03 14:16:08 +02:00
|
|
|
pattern = [r"(?:https?://)?(?:www\.)?hentai-foundry\.com/"
|
|
|
|
r"(?:pictures/user/([^/]+)/?$|user/([^/]+)/profile)"]
|
2016-12-31 00:51:06 +01:00
|
|
|
test = [
|
2017-04-20 13:20:41 +02:00
|
|
|
("https://www.hentai-foundry.com/pictures/user/Tenpura", {
|
|
|
|
"url": "ebbc981a85073745e3ca64a0f2ab31fab967fc28",
|
2017-09-24 15:59:25 +02:00
|
|
|
"keyword": "f8fecc8aa89978ecf402ec221243978fe791bd54",
|
2016-12-31 00:51:06 +01:00
|
|
|
}),
|
|
|
|
("http://www.hentai-foundry.com/user/asdq/profile", {
|
|
|
|
"exception": exception.NotFoundError,
|
|
|
|
}),
|
|
|
|
]
|
2017-11-06 20:56:49 +01:00
|
|
|
base_url = "https://www.hentai-foundry.com/pictures/user/"
|
2015-11-14 03:19:44 +01:00
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
Extractor.__init__(self)
|
2017-07-03 14:16:08 +02:00
|
|
|
self.artist = match.group(1) or match.group(2)
|
2015-11-14 03:19:44 +01:00
|
|
|
|
|
|
|
def items(self):
|
|
|
|
data, token = self.get_job_metadata()
|
|
|
|
self.set_filters(token)
|
|
|
|
yield Message.Version, 1
|
|
|
|
yield Message.Directory, data
|
2017-09-24 15:59:25 +02:00
|
|
|
for url, image in self.get_images(data["count"]):
|
2015-11-14 03:19:44 +01:00
|
|
|
image.update(data)
|
2015-11-14 14:13:02 +01:00
|
|
|
yield Message.Url, url, image
|
2015-11-14 03:19:44 +01:00
|
|
|
|
2017-07-03 14:16:08 +02:00
|
|
|
def get_images(self, count):
|
2015-11-14 14:13:02 +01:00
|
|
|
"""Yield url and keywords for all images of one artist"""
|
2015-11-14 03:19:44 +01:00
|
|
|
num = 1
|
2016-12-07 09:10:18 +01:00
|
|
|
needle = 'thumbTitle"><a href="/pictures/user/'
|
2017-07-03 14:16:08 +02:00
|
|
|
for _ in range((count-1) // 25 + 1):
|
2015-11-14 03:19:44 +01:00
|
|
|
pos = 0
|
2017-11-06 20:56:49 +01:00
|
|
|
url = self.base_url + self.artist + "/page/" + str(num)
|
2015-11-14 03:19:44 +01:00
|
|
|
page = self.request(url).text
|
2015-11-14 14:13:02 +01:00
|
|
|
for _ in range(25):
|
2016-12-07 09:10:18 +01:00
|
|
|
part, pos = text.extract(page, needle, '"', pos)
|
2015-11-14 03:19:44 +01:00
|
|
|
if not part:
|
|
|
|
return
|
2017-11-06 20:56:49 +01:00
|
|
|
yield self.get_image_metadata(self.base_url + part)
|
2015-11-14 03:19:44 +01:00
|
|
|
num += 1
|
|
|
|
|
|
|
|
def get_job_metadata(self):
|
|
|
|
"""Collect metadata for extractor-job"""
|
2017-11-06 20:56:49 +01:00
|
|
|
url = self.base_url + self.artist + "?enterAgree=1"
|
2017-08-05 16:11:46 +02:00
|
|
|
response = self.request(url, fatal=False)
|
2016-12-07 09:10:18 +01:00
|
|
|
if response.status_code == 404:
|
|
|
|
raise exception.NotFoundError("user")
|
|
|
|
page = response.text
|
2015-11-14 03:19:44 +01:00
|
|
|
token, pos = text.extract(page, 'hidden" value="', '"')
|
|
|
|
count, pos = text.extract(page, 'class="active" >Pictures (', ')', pos)
|
2017-09-24 15:59:25 +02:00
|
|
|
return {"artist": self.artist, "count": util.safe_int(count)}, token
|
2015-11-14 03:19:44 +01:00
|
|
|
|
|
|
|
def get_image_metadata(self, url):
|
|
|
|
"""Collect metadata for an image"""
|
|
|
|
page = self.request(url).text
|
2017-11-06 20:56:49 +01:00
|
|
|
index = url.rsplit("/", 2)[1]
|
2017-02-01 00:53:19 +01:00
|
|
|
title, pos = text.extract(
|
|
|
|
page, 'Pictures</a> » <span>', '<')
|
2017-11-06 20:56:49 +01:00
|
|
|
part, pos = text.extract(
|
2017-02-01 00:53:19 +01:00
|
|
|
page, '//pictures.hentai-foundry.com', '"', pos)
|
2017-09-24 15:59:25 +02:00
|
|
|
data = {"index": util.safe_int(index), "title": text.unescape(title)}
|
2017-11-06 20:56:49 +01:00
|
|
|
text.nameext_from_url(part, data)
|
|
|
|
return "https://pictures.hentai-foundry.com" + part, data
|
2015-11-14 03:19:44 +01:00
|
|
|
|
|
|
|
def set_filters(self, token):
|
2015-11-14 14:13:02 +01:00
|
|
|
"""Set site-internal filters to show all images"""
|
2015-11-14 03:19:44 +01:00
|
|
|
formdata = {
|
|
|
|
"YII_CSRF_TOKEN": token,
|
|
|
|
"rating_nudity": 3,
|
|
|
|
"rating_violence": 3,
|
|
|
|
"rating_profanity": 3,
|
|
|
|
"rating_racism": 3,
|
|
|
|
"rating_sex": 3,
|
|
|
|
"rating_spoilers": 3,
|
|
|
|
"rating_yaoi": 1,
|
|
|
|
"rating_yuri": 1,
|
|
|
|
"rating_teen": 1,
|
|
|
|
"rating_guro": 1,
|
|
|
|
"rating_furry": 1,
|
|
|
|
"rating_beast": 1,
|
|
|
|
"rating_male": 1,
|
|
|
|
"rating_female": 1,
|
|
|
|
"rating_futa": 1,
|
|
|
|
"rating_other": 1,
|
2017-04-20 13:20:41 +02:00
|
|
|
"rating_scat": 1,
|
|
|
|
"rating_incest": 1,
|
|
|
|
"rating_rape": 1,
|
2015-11-14 03:19:44 +01:00
|
|
|
"filter_media": "A",
|
|
|
|
"filter_order": "date_new",
|
|
|
|
"filter_type": 0,
|
|
|
|
}
|
2017-04-20 13:20:41 +02:00
|
|
|
self.request("https://www.hentai-foundry.com/site/filters",
|
2017-09-25 13:01:10 +02:00
|
|
|
method="post", data=formdata, allow_empty=True)
|
2015-11-29 00:01:49 +01:00
|
|
|
|
|
|
|
|
2016-09-12 10:20:57 +02:00
|
|
|
class HentaifoundryImageExtractor(Extractor):
|
|
|
|
"""Extractor for a single image from hentaifoundry.com"""
|
2015-11-29 00:01:49 +01:00
|
|
|
category = "hentaifoundry"
|
2015-11-30 01:11:13 +01:00
|
|
|
subcategory = "image"
|
2015-11-29 00:01:49 +01:00
|
|
|
directory_fmt = ["{category}", "{artist}"]
|
|
|
|
filename_fmt = "{category}_{index}_{title}.{extension}"
|
2018-02-12 23:09:34 +01:00
|
|
|
archive_fmt = "{index}"
|
2016-12-27 15:24:42 +01:00
|
|
|
pattern = [(r"(?:https?://)?(?:www\.|pictures\.)?hentai-foundry\.com/"
|
|
|
|
r"(?:pictures/user/([^/]+)/(\d+)"
|
|
|
|
r"|[^/]/([^/]+)/(\d+))")]
|
2016-12-31 00:51:06 +01:00
|
|
|
test = [
|
2017-02-01 00:53:19 +01:00
|
|
|
(("http://www.hentai-foundry.com/"
|
2017-04-10 10:50:34 +02:00
|
|
|
"pictures/user/Tenpura/407501/shimakaze"), {
|
2017-04-20 13:20:41 +02:00
|
|
|
"url": "fbf2fd74906738094e2575d2728e8dc3de18a8a3",
|
2017-09-24 15:59:25 +02:00
|
|
|
"keyword": "85b8e26fa93d00ae1333cb7b418078f1792dc4a8",
|
2017-04-10 10:50:34 +02:00
|
|
|
"content": "91bf01497c39254b6dfb234a18e8f01629c77fd1",
|
2016-12-31 00:51:06 +01:00
|
|
|
}),
|
|
|
|
("http://www.hentai-foundry.com/pictures/user/Tenpura/340853/", {
|
|
|
|
"exception": exception.NotFoundError,
|
|
|
|
}),
|
|
|
|
]
|
2015-11-29 00:01:49 +01:00
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
Extractor.__init__(self)
|
2016-12-27 15:24:42 +01:00
|
|
|
self.artist = match.group(1) or match.group(3)
|
|
|
|
self.index = match.group(2) or match.group(4)
|
2015-11-29 00:01:49 +01:00
|
|
|
|
|
|
|
def items(self):
|
|
|
|
url, data = self.get_image_metadata()
|
|
|
|
yield Message.Version, 1
|
|
|
|
yield Message.Directory, data
|
|
|
|
yield Message.Url, url, data
|
|
|
|
|
|
|
|
def get_image_metadata(self):
|
|
|
|
"""Collect metadata for an image"""
|
2017-04-20 13:20:41 +02:00
|
|
|
url = "https://www.hentai-foundry.com/pictures/user/{}/{}".format(
|
2016-12-27 15:24:42 +01:00
|
|
|
self.artist, self.index)
|
2017-08-05 16:11:46 +02:00
|
|
|
response = self.request(url + "?enterAgree=1", fatal=False)
|
2016-12-07 09:10:18 +01:00
|
|
|
if response.status_code == 404:
|
|
|
|
raise exception.NotFoundError("image")
|
2017-02-01 00:53:19 +01:00
|
|
|
extr = text.extract
|
2016-12-07 09:10:18 +01:00
|
|
|
page = response.text
|
2017-02-01 00:53:19 +01:00
|
|
|
artist, pos = extr(page, '<a href="/pictures/user/', '"')
|
|
|
|
title , pos = extr(page, 'Pictures</a> » <span>', '<', pos)
|
|
|
|
url , pos = extr(page, '//pictures.hentai-foundry.com', '"', pos)
|
2015-11-29 00:01:49 +01:00
|
|
|
data = {
|
2016-12-29 17:38:22 +01:00
|
|
|
"artist": artist,
|
2017-09-24 15:59:25 +02:00
|
|
|
"index": util.safe_int(self.index),
|
2015-11-29 00:01:49 +01:00
|
|
|
"title": text.unescape(title),
|
|
|
|
}
|
2016-12-07 09:10:18 +01:00
|
|
|
text.nameext_from_url(url, data)
|
2017-04-20 13:20:41 +02:00
|
|
|
return "https://pictures.hentai-foundry.com" + url, data
|