2015-11-14 03:19:44 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-02-08 13:45:40 +01:00
|
|
|
# Copyright 2015-2019 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
|
|
|
|
2018-04-20 18:22:57 +02:00
|
|
|
class HentaifoundryExtractor(Extractor):
|
2018-09-20 16:24:49 +02:00
|
|
|
"""Base class for hentaifoundry extractors"""
|
2015-11-21 04:26:30 +01:00
|
|
|
category = "hentaifoundry"
|
2019-02-08 13:45:40 +01:00
|
|
|
directory_fmt = ("{category}", "{user}")
|
2015-11-21 04:26:30 +01:00
|
|
|
filename_fmt = "{category}_{index}_{title}.{extension}"
|
2018-01-30 22:49:16 +01:00
|
|
|
archive_fmt = "{index}"
|
2018-04-20 18:22:57 +02:00
|
|
|
root = "https://www.hentai-foundry.com"
|
|
|
|
per_page = 25
|
2015-11-14 03:19:44 +01:00
|
|
|
|
2019-02-11 13:31:10 +01:00
|
|
|
def __init__(self, match, user="", page=1):
|
|
|
|
Extractor.__init__(self, match)
|
2019-02-12 10:20:21 +01:00
|
|
|
self.page_url = ""
|
2018-09-22 17:38:09 +02:00
|
|
|
self.user = user
|
2018-04-20 18:22:57 +02:00
|
|
|
self.start_post = 0
|
2018-09-22 17:38:09 +02:00
|
|
|
self.start_page = text.parse_int(page, 1)
|
2015-11-14 03:19:44 +01:00
|
|
|
|
|
|
|
def items(self):
|
2018-04-20 18:22:57 +02:00
|
|
|
data = self.get_job_metadata()
|
2015-11-14 03:19:44 +01:00
|
|
|
yield Message.Version, 1
|
|
|
|
yield Message.Directory, data
|
2018-04-20 18:22:57 +02:00
|
|
|
|
2018-09-20 16:24:49 +02:00
|
|
|
self.set_filters()
|
2018-04-20 18:22:57 +02:00
|
|
|
for page_url in util.advance(self.get_image_pages(), self.start_post):
|
|
|
|
url, image = self.get_image_metadata(page_url)
|
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
|
|
|
|
2018-04-20 18:22:57 +02:00
|
|
|
def skip(self, num):
|
|
|
|
pages, posts = divmod(num, self.per_page)
|
|
|
|
self.start_page += pages
|
|
|
|
self.start_post += posts
|
|
|
|
return num
|
|
|
|
|
|
|
|
def get_job_metadata(self):
|
2018-09-20 16:24:49 +02:00
|
|
|
"""Collect metadata for extractor-job"""
|
2018-09-22 17:38:09 +02:00
|
|
|
self.request(self.root + "/?enterAgree=1")
|
|
|
|
return {"user": self.user}
|
2018-04-20 18:22:57 +02:00
|
|
|
|
2018-09-20 16:24:49 +02:00
|
|
|
def get_image_pages(self):
|
2018-09-22 17:38:09 +02:00
|
|
|
"""Yield urls of all relevant image pages"""
|
|
|
|
num = self.start_page
|
|
|
|
|
|
|
|
while True:
|
2019-02-12 10:20:21 +01:00
|
|
|
page = self.request("{}/page/{}".format(self.page_url, num)).text
|
2018-09-22 17:38:09 +02:00
|
|
|
yield from text.extract_iter(page, 'thumbTitle"><a href="', '"')
|
2018-04-20 18:22:57 +02:00
|
|
|
|
2018-09-22 17:38:09 +02:00
|
|
|
if 'class="pager"' not in page or 'class="last hidden"' in page:
|
|
|
|
return
|
|
|
|
num += 1
|
|
|
|
|
|
|
|
def get_image_metadata(self, page_url):
|
|
|
|
"""Collect url and metadata from an image page"""
|
|
|
|
page = self.request(text.urljoin(self.root, page_url)).text
|
|
|
|
index = page_url.rsplit("/", 2)[1]
|
2018-09-20 16:24:49 +02:00
|
|
|
title , pos = text.extract(page, '<title>', '</title>')
|
2019-02-25 16:07:48 +01:00
|
|
|
_ , pos = text.extract(page, 'id="picBox"', '', pos)
|
2018-09-20 16:24:49 +02:00
|
|
|
width , pos = text.extract(page, 'width="', '"', pos)
|
|
|
|
height, pos = text.extract(page, 'height="', '"', pos)
|
|
|
|
url , pos = text.extract(page, 'src="', '"', pos)
|
|
|
|
|
|
|
|
title, _, artist = title.rpartition(" - ")[0].rpartition(" by ")
|
|
|
|
|
|
|
|
data = text.nameext_from_url(url, {
|
|
|
|
"title": text.unescape(title),
|
|
|
|
"artist": text.unescape(artist),
|
|
|
|
"index": text.parse_int(index),
|
|
|
|
"width": text.parse_int(width),
|
|
|
|
"height": text.parse_int(height),
|
|
|
|
})
|
|
|
|
if not data["extension"]:
|
|
|
|
data["extension"] = "jpg"
|
|
|
|
return text.urljoin(self.root, url), data
|
2018-04-20 18:22:57 +02:00
|
|
|
|
|
|
|
def set_filters(self):
|
2015-11-14 14:13:02 +01:00
|
|
|
"""Set site-internal filters to show all images"""
|
2018-11-19 21:43:00 +01:00
|
|
|
token = text.unquote(text.extract(
|
|
|
|
self.session.cookies["YII_CSRF_TOKEN"], "%22", "%22")[0])
|
2018-09-20 16:24:49 +02:00
|
|
|
data = {
|
2015-11-14 03:19:44 +01:00
|
|
|
"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,
|
|
|
|
}
|
2018-09-20 16:24:49 +02:00
|
|
|
url = self.root + "/site/filters"
|
|
|
|
self.request(url, method="POST", data=data)
|
2015-11-29 00:01:49 +01:00
|
|
|
|
2018-09-20 16:24:49 +02:00
|
|
|
|
|
|
|
class HentaifoundryUserExtractor(HentaifoundryExtractor):
|
|
|
|
"""Extractor for all images of a hentai-foundry-user"""
|
|
|
|
subcategory = "user"
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = (r"(?:https?://)?(?:www\.)?hentai-foundry\.com"
|
2018-09-22 17:38:09 +02:00
|
|
|
r"/(?:pictures/user/([^/]+)(?:/page/(\d+))?/?$"
|
2019-02-08 13:45:40 +01:00
|
|
|
r"|user/([^/]+)/profile)")
|
|
|
|
test = (
|
2018-09-20 16:24:49 +02:00
|
|
|
("https://www.hentai-foundry.com/pictures/user/Tenpura", {
|
|
|
|
"url": "ebbc981a85073745e3ca64a0f2ab31fab967fc28",
|
2019-02-14 16:07:17 +01:00
|
|
|
"keyword": "63ad576f87f82fa166ca4676761762f7f8496cf5",
|
2018-09-20 16:24:49 +02:00
|
|
|
}),
|
2019-02-08 13:45:40 +01:00
|
|
|
("https://www.hentai-foundry.com/pictures/user/Tenpura/page/3"),
|
|
|
|
("https://www.hentai-foundry.com/user/Tenpura/profile"),
|
|
|
|
)
|
2018-09-19 21:04:50 +02:00
|
|
|
|
|
|
|
def __init__(self, match):
|
2018-09-20 16:24:49 +02:00
|
|
|
HentaifoundryExtractor.__init__(
|
2019-02-11 13:31:10 +01:00
|
|
|
self, match, match.group(1) or match.group(3), match.group(2))
|
2019-02-12 10:20:21 +01:00
|
|
|
self.page_url = "{}/pictures/user/{}".format(self.root, self.user)
|
2018-09-19 21:04:50 +02:00
|
|
|
|
2018-09-22 17:38:09 +02:00
|
|
|
def get_job_metadata(self):
|
2019-02-12 10:20:21 +01:00
|
|
|
page = self.request(self.page_url + "?enterAgree=1").text
|
2018-09-22 17:38:09 +02:00
|
|
|
count = text.extract(page, ">Pictures (", ")")[0]
|
|
|
|
return {"user": self.user, "count": text.parse_int(count)}
|
2018-09-19 21:04:50 +02:00
|
|
|
|
|
|
|
|
2018-09-20 16:24:49 +02:00
|
|
|
class HentaifoundryScrapsExtractor(HentaifoundryExtractor):
|
|
|
|
"""Extractor for scrap images of a hentai-foundry-user"""
|
|
|
|
subcategory = "scraps"
|
2019-02-08 13:45:40 +01:00
|
|
|
directory_fmt = ("{category}", "{user}", "Scraps")
|
|
|
|
pattern = (r"(?:https?://)?(?:www\.)?hentai-foundry\.com"
|
|
|
|
r"/pictures/user/([^/]+)/scraps(?:/page/(\d+))?")
|
|
|
|
test = (
|
2018-09-20 16:24:49 +02:00
|
|
|
("https://www.hentai-foundry.com/pictures/user/Evulchibi/scraps", {
|
2019-09-08 11:33:35 +02:00
|
|
|
"url": "7cd9c6ec6258c4ab8c44991f7731be82337492a7",
|
|
|
|
"keyword": "40b07a9822b6b868fea2fa9b1c0b212ae8735da7",
|
2018-09-20 16:24:49 +02:00
|
|
|
}),
|
2019-02-08 13:45:40 +01:00
|
|
|
("https://www.hentai-foundry.com"
|
|
|
|
"/pictures/user/Evulchibi/scraps/page/3"),
|
|
|
|
)
|
2018-09-20 16:24:49 +02:00
|
|
|
|
|
|
|
def __init__(self, match):
|
2019-02-11 13:31:10 +01:00
|
|
|
HentaifoundryExtractor.__init__(
|
|
|
|
self, match, match.group(1), match.group(2))
|
2019-02-12 10:20:21 +01:00
|
|
|
self.page_url = "{}/pictures/user/{}/scraps".format(
|
|
|
|
self.root, self.user)
|
2018-09-20 16:24:49 +02:00
|
|
|
|
2018-09-22 17:38:09 +02:00
|
|
|
def get_job_metadata(self):
|
2019-02-12 10:20:21 +01:00
|
|
|
page = self.request(self.page_url + "?enterAgree=1").text
|
2018-09-22 17:38:09 +02:00
|
|
|
count = text.extract(page, ">Scraps (", ")")[0]
|
|
|
|
return {"user": self.user, "count": text.parse_int(count)}
|
2018-09-19 21:04:50 +02:00
|
|
|
|
|
|
|
|
2018-09-22 21:22:53 +02:00
|
|
|
class HentaifoundryFavoriteExtractor(HentaifoundryExtractor):
|
|
|
|
"""Extractor for favorite images of a hentai-foundry-user"""
|
|
|
|
subcategory = "favorite"
|
2019-02-08 13:45:40 +01:00
|
|
|
directory_fmt = ("{category}", "{user}", "Favorites")
|
2018-09-22 21:22:53 +02:00
|
|
|
archive_fmt = "f_{user}_{index}"
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = (r"(?:https?://)?(?:www\.)?hentai-foundry\.com"
|
|
|
|
r"/user/([^/]+)/faves/pictures(?:/page/(\d+))?")
|
|
|
|
test = (
|
2018-09-22 21:22:53 +02:00
|
|
|
("https://www.hentai-foundry.com/user/Tenpura/faves/pictures", {
|
|
|
|
"url": "56f9ae2e89fe855e9fe1da9b81e5ec6212b0320b",
|
2019-02-14 16:07:17 +01:00
|
|
|
"keyword": "2b9478725e66d46ea043fa87476bbd28546958e7",
|
2018-09-22 21:22:53 +02:00
|
|
|
}),
|
|
|
|
("https://www.hentai-foundry.com"
|
2019-02-08 13:45:40 +01:00
|
|
|
"/user/Tenpura/faves/pictures/page/3"),
|
|
|
|
)
|
2018-09-22 21:22:53 +02:00
|
|
|
|
|
|
|
def __init__(self, match):
|
2019-02-11 13:31:10 +01:00
|
|
|
HentaifoundryExtractor.__init__(
|
|
|
|
self, match, match.group(1), match.group(2))
|
2019-02-12 10:20:21 +01:00
|
|
|
self.page_url = "{}/user/{}/faves/pictures".format(
|
|
|
|
self.root, self.user)
|
2018-09-22 21:22:53 +02:00
|
|
|
|
|
|
|
|
2018-09-22 21:28:16 +02:00
|
|
|
class HentaifoundryRecentExtractor(HentaifoundryExtractor):
|
|
|
|
"""Extractor for 'Recent Pictures' on hentaifoundry.com"""
|
|
|
|
subcategory = "recent"
|
2019-02-08 13:45:40 +01:00
|
|
|
directory_fmt = ("{category}", "Recent Pictures", "{date}")
|
2018-09-22 21:28:16 +02:00
|
|
|
archive_fmt = "r_{index}"
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = (r"(?:https?://)?(?:www\.)?hentai-foundry\.com"
|
|
|
|
r"/pictures/recent/(\d+-\d+-\d+)(?:/page/(\d+))?")
|
|
|
|
test = ("http://www.hentai-foundry.com/pictures/recent/2018-09-20",)
|
2018-09-22 21:28:16 +02:00
|
|
|
|
|
|
|
def __init__(self, match):
|
2019-02-11 13:31:10 +01:00
|
|
|
HentaifoundryExtractor.__init__(self, match, "", match.group(2))
|
2018-09-22 21:28:16 +02:00
|
|
|
self.date = match.group(1)
|
2019-02-12 10:20:21 +01:00
|
|
|
self.page_url = "{}/pictures/recent/{}".format(self.root, self.date)
|
2018-09-22 21:28:16 +02:00
|
|
|
|
|
|
|
def get_job_metadata(self):
|
|
|
|
self.request(self.root + "/?enterAgree=1")
|
|
|
|
return {"date": self.date}
|
|
|
|
|
|
|
|
|
|
|
|
class HentaifoundryPopularExtractor(HentaifoundryExtractor):
|
|
|
|
"""Extractor for popular images on hentaifoundry.com"""
|
|
|
|
subcategory = "popular"
|
2019-02-08 13:45:40 +01:00
|
|
|
directory_fmt = ("{category}", "Popular Pictures")
|
2018-09-22 21:28:16 +02:00
|
|
|
archive_fmt = "p_{index}"
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = (r"(?:https?://)?(?:www\.)?hentai-foundry\.com"
|
|
|
|
r"/pictures/popular(?:/page/(\d+))?")
|
|
|
|
test = ("http://www.hentai-foundry.com/pictures/popular",)
|
2018-09-22 21:28:16 +02:00
|
|
|
|
|
|
|
def __init__(self, match):
|
2019-02-11 13:31:10 +01:00
|
|
|
HentaifoundryExtractor.__init__(self, match, "", match.group(1))
|
2019-02-12 10:20:21 +01:00
|
|
|
self.page_url = self.root + "/pictures/popular"
|
2018-09-22 21:28:16 +02:00
|
|
|
|
|
|
|
|
2018-04-20 18:22:57 +02:00
|
|
|
class HentaifoundryImageExtractor(HentaifoundryExtractor):
|
2016-09-12 10:20:57 +02:00
|
|
|
"""Extractor for a single image from hentaifoundry.com"""
|
2015-11-30 01:11:13 +01:00
|
|
|
subcategory = "image"
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = (r"(?:https?://)?(?:www\.|pictures\.)?hentai-foundry\.com"
|
|
|
|
r"/(?:pictures/user|[^/])/([^/]+)/(\d+)")
|
|
|
|
test = (
|
2018-09-20 16:24:49 +02:00
|
|
|
(("https://www.hentai-foundry.com"
|
2018-04-20 18:22:57 +02:00
|
|
|
"/pictures/user/Tenpura/407501/shimakaze"), {
|
2017-04-20 13:20:41 +02:00
|
|
|
"url": "fbf2fd74906738094e2575d2728e8dc3de18a8a3",
|
2019-02-14 16:07:17 +01:00
|
|
|
"keyword": "cbb9381e6c2acce58db4adf4efc0ad7d138bddc4",
|
2017-04-10 10:50:34 +02:00
|
|
|
"content": "91bf01497c39254b6dfb234a18e8f01629c77fd1",
|
2016-12-31 00:51:06 +01:00
|
|
|
}),
|
2018-09-20 16:24:49 +02:00
|
|
|
("https://www.hentai-foundry.com/pictures/user/Tenpura/340853/", {
|
2018-04-20 18:22:57 +02:00
|
|
|
"exception": exception.HttpError,
|
2016-12-31 00:51:06 +01:00
|
|
|
}),
|
2019-02-08 13:45:40 +01:00
|
|
|
("https://pictures.hentai-foundry.com"
|
|
|
|
"/t/Tenpura/407501/Tenpura-407501-shimakaze.png"),
|
|
|
|
)
|
2015-11-29 00:01:49 +01:00
|
|
|
|
|
|
|
def __init__(self, match):
|
2019-02-11 13:31:10 +01:00
|
|
|
HentaifoundryExtractor.__init__(self, match, match.group(1))
|
2018-09-20 16:24:49 +02:00
|
|
|
self.index = match.group(2)
|
2015-11-29 00:01:49 +01:00
|
|
|
|
2018-09-20 16:24:49 +02:00
|
|
|
def items(self):
|
2018-09-22 17:38:09 +02:00
|
|
|
post_url = "{}/pictures/user/{}/{}/?enterAgree=1".format(
|
|
|
|
self.root, self.user, self.index)
|
|
|
|
url, data = self.get_image_metadata(post_url)
|
|
|
|
data["user"] = self.user
|
|
|
|
|
2018-09-20 16:24:49 +02:00
|
|
|
yield Message.Version, 1
|
|
|
|
yield Message.Directory, data
|
|
|
|
yield Message.Url, url, data
|
2015-11-29 00:01:49 +01:00
|
|
|
|
2018-09-20 16:24:49 +02:00
|
|
|
def skip(self, _):
|
|
|
|
return 0
|