2015-11-14 03:19:44 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright 2015 Mike Fährmann
|
|
|
|
#
|
|
|
|
# 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.hentai-foundry.com/"""
|
|
|
|
|
|
|
|
from .common import Extractor, Message
|
2016-12-07 09:10:18 +01:00
|
|
|
from .. import text, exception
|
2015-11-14 03:19:44 +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}"
|
|
|
|
pattern = [
|
2015-11-29 00:01:49 +01:00
|
|
|
r"(?:https?://)?(?:www\.)?hentai-foundry\.com/pictures/user/([^/]+)/?$",
|
2015-11-21 04:26:30 +01:00
|
|
|
r"(?:https?://)?(?:www\.)?hentai-foundry\.com/user/([^/]+)/profile",
|
|
|
|
]
|
2016-12-07 09:10:18 +01:00
|
|
|
test = [("http://www.hentai-foundry.com/pictures/user/Tenpura", {
|
|
|
|
"url": "95d44a26498ae4a73963e6fd03ea5e0e624f14a0",
|
|
|
|
"keyword": "6937c20b3afe5a0af741cc1c419994dd041c8395",
|
2015-12-14 03:00:58 +01:00
|
|
|
})]
|
2015-11-14 03:19:44 +01:00
|
|
|
url_base = "http://www.hentai-foundry.com/pictures/user/"
|
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
Extractor.__init__(self)
|
|
|
|
self.artist = match.group(1)
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
data, token = self.get_job_metadata()
|
|
|
|
self.set_filters(token)
|
|
|
|
yield Message.Version, 1
|
|
|
|
yield Message.Directory, data
|
2015-11-14 14:13:02 +01:00
|
|
|
for url, image in self.get_images():
|
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
|
|
|
|
|
|
|
def get_images(self):
|
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/'
|
2015-11-14 03:19:44 +01:00
|
|
|
while True:
|
|
|
|
pos = 0
|
|
|
|
url = self.url_base + self.artist + "/page/" + str(num)
|
|
|
|
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
|
|
|
|
yield self.get_image_metadata(self.url_base + part)
|
|
|
|
num += 1
|
|
|
|
|
|
|
|
def get_job_metadata(self):
|
|
|
|
"""Collect metadata for extractor-job"""
|
2016-12-07 09:10:18 +01:00
|
|
|
response = self.session.get(self.url_base + self.artist + "?enterAgree=1")
|
|
|
|
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)
|
2016-12-07 09:10:18 +01:00
|
|
|
return {"artist": self.artist, "count": 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
|
|
|
|
index = text.extract(url, '/', '/', len(self.url_base) + len(self.artist))[0]
|
|
|
|
title, pos = text.extract(page, 'Pictures</a> » <span>', '<')
|
2015-11-16 17:32:26 +01:00
|
|
|
url , pos = text.extract(page, '//pictures.hentai-foundry.com', '"', pos)
|
2016-12-07 09:10:18 +01:00
|
|
|
data = {"index": index, "title": text.unescape(title)}
|
|
|
|
text.nameext_from_url(url, data)
|
|
|
|
return "http://pictures.hentai-foundry.com" + url, 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,
|
|
|
|
"filter_media": "A",
|
|
|
|
"filter_order": "date_new",
|
|
|
|
"filter_type": 0,
|
|
|
|
}
|
|
|
|
self.request("http://www.hentai-foundry.com/site/filters",
|
2015-11-14 14:13:02 +01:00
|
|
|
method="post", data=formdata)
|
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}"
|
2016-12-27 15:24:42 +01:00
|
|
|
pattern = [(r"(?:https?://)?(?:www\.|pictures\.)?hentai-foundry\.com/"
|
|
|
|
r"(?:pictures/user/([^/]+)/(\d+)"
|
|
|
|
r"|[^/]/([^/]+)/(\d+))")]
|
2016-12-07 09:10:18 +01:00
|
|
|
test = [("http://www.hentai-foundry.com/pictures/user/Tenpura/340854/notitle", {
|
|
|
|
"url": "f3c0739bf86543697deabbed4bf99eb95a04582b",
|
|
|
|
"keyword": "96217c5becc1369c36dafa201c3c208518de8f1f",
|
|
|
|
"content": "5c14cd10deaad79a5152f9de45c9203cf76165a0",
|
2015-12-14 03:00:58 +01:00
|
|
|
})]
|
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"""
|
2016-12-27 15:24:42 +01:00
|
|
|
url = "http://www.hentai-foundry.com/pictures/user/{}/{}".format(
|
|
|
|
self.artist, self.index)
|
|
|
|
response = self.session.get(url + "?enterAgree=1")
|
2016-12-07 09:10:18 +01:00
|
|
|
if response.status_code == 404:
|
|
|
|
raise exception.NotFoundError("image")
|
|
|
|
page = response.text
|
2016-12-29 17:38:22 +01:00
|
|
|
artist, pos = text.extract(page, '<a href="/pictures/user/', '"')
|
|
|
|
title , pos = text.extract(page, 'Pictures</a> » <span>', '<', pos)
|
|
|
|
url , pos = text.extract(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,
|
2015-11-29 00:01:49 +01:00
|
|
|
"index": self.index,
|
|
|
|
"title": text.unescape(title),
|
|
|
|
}
|
2016-12-07 09:10:18 +01:00
|
|
|
text.nameext_from_url(url, data)
|
|
|
|
return "http://pictures.hentai-foundry.com" + url, data
|