2018-01-15 16:39:05 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2020-01-27 22:19:41 +01:00
|
|
|
# Copyright 2018-2020 Mike Fährmann
|
2018-01-15 16:39:05 +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.
|
|
|
|
|
2020-11-17 00:34:07 +01:00
|
|
|
"""Extractors for https://rule34.paheal.net/"""
|
2018-01-15 16:39:05 +01:00
|
|
|
|
2020-11-17 00:34:07 +01:00
|
|
|
from .common import Extractor, Message
|
2018-05-10 22:07:55 +02:00
|
|
|
from .. import text
|
2018-01-15 16:39:05 +01:00
|
|
|
|
|
|
|
|
2020-11-17 00:34:07 +01:00
|
|
|
class PahealExtractor(Extractor):
|
2018-01-15 16:39:05 +01:00
|
|
|
"""Base class for paheal extractors"""
|
|
|
|
basecategory = "booru"
|
|
|
|
category = "paheal"
|
|
|
|
filename_fmt = "{category}_{id}_{md5}.{extension}"
|
2018-01-30 22:49:16 +01:00
|
|
|
archive_fmt = "{id}"
|
2018-07-17 21:23:50 +02:00
|
|
|
root = "https://rule34.paheal.net"
|
2018-01-15 16:39:05 +01:00
|
|
|
|
|
|
|
def items(self):
|
2020-10-28 21:51:31 +01:00
|
|
|
self.session.cookies.set(
|
|
|
|
"ui-tnc-agreed", "true", domain="rule34.paheal.net")
|
2020-12-01 12:14:55 +01:00
|
|
|
data = self.get_metadata()
|
2020-10-28 21:51:31 +01:00
|
|
|
|
2020-12-01 12:14:55 +01:00
|
|
|
for post in self.get_posts():
|
|
|
|
url = post["file_url"]
|
2018-01-15 16:39:05 +01:00
|
|
|
for key in ("id", "width", "height"):
|
2020-12-01 12:14:55 +01:00
|
|
|
post[key] = text.parse_int(post[key])
|
|
|
|
post["tags"] = text.unquote(post["tags"])
|
|
|
|
post.update(data)
|
|
|
|
yield Message.Directory, post
|
|
|
|
yield Message.Url, url, text.nameext_from_url(url, post)
|
2018-01-15 16:39:05 +01:00
|
|
|
|
|
|
|
def get_metadata(self):
|
|
|
|
"""Return general metadata"""
|
|
|
|
return {}
|
|
|
|
|
|
|
|
def get_posts(self):
|
|
|
|
"""Return an iterable containing data of all relevant posts"""
|
|
|
|
|
|
|
|
|
|
|
|
class PahealTagExtractor(PahealExtractor):
|
|
|
|
"""Extractor for images from rule34.paheal.net by search-tags"""
|
|
|
|
subcategory = "tag"
|
2019-02-15 16:40:15 +01:00
|
|
|
directory_fmt = ("{category}", "{search_tags}")
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = (r"(?:https?://)?(?:rule34|rule63|cosplay)\.paheal\.net"
|
2020-10-22 23:12:59 +02:00
|
|
|
r"/post/list/([^/?#]+)")
|
2020-01-27 22:19:41 +01:00
|
|
|
test = ("https://rule34.paheal.net/post/list/Ayane_Suzuki/1", {
|
2019-06-05 11:42:01 +02:00
|
|
|
"pattern": r"https://[^.]+\.paheal\.net/_images/\w+/\d+%20-%20",
|
|
|
|
"count": ">= 15"
|
2019-02-08 13:45:40 +01:00
|
|
|
})
|
2018-01-15 16:39:05 +01:00
|
|
|
per_page = 70
|
|
|
|
|
|
|
|
def __init__(self, match):
|
2019-02-11 13:31:10 +01:00
|
|
|
PahealExtractor.__init__(self, match)
|
2018-01-15 16:39:05 +01:00
|
|
|
self.tags = text.unquote(match.group(1))
|
|
|
|
|
|
|
|
def get_metadata(self):
|
2019-02-15 16:40:15 +01:00
|
|
|
return {"search_tags": self.tags}
|
2018-01-15 16:39:05 +01:00
|
|
|
|
|
|
|
def get_posts(self):
|
|
|
|
pnum = 1
|
|
|
|
while True:
|
|
|
|
url = "{}/post/list/{}/{}".format(self.root, self.tags, pnum)
|
|
|
|
page = self.request(url).text
|
|
|
|
|
|
|
|
for post in text.extract_iter(
|
2020-10-28 21:51:31 +01:00
|
|
|
page, '<img id="thumb_', 'Only</a>'):
|
2018-01-15 16:39:05 +01:00
|
|
|
yield self._extract_data(post)
|
|
|
|
|
|
|
|
if ">Next<" not in page:
|
|
|
|
return
|
|
|
|
pnum += 1
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _extract_data(post):
|
|
|
|
pid , pos = text.extract(post, '', '"')
|
|
|
|
data, pos = text.extract(post, 'title="', '"', pos)
|
|
|
|
md5 , pos = text.extract(post, '/_thumbs/', '/', pos)
|
|
|
|
url , pos = text.extract(post, '<a href="', '"', pos)
|
|
|
|
|
2020-10-28 21:51:31 +01:00
|
|
|
tags, data, date = data.split("\n")
|
|
|
|
dimensions, size, ext = data.split(" // ")
|
2018-01-15 16:39:05 +01:00
|
|
|
width, _, height = dimensions.partition("x")
|
|
|
|
|
|
|
|
return {
|
|
|
|
"id": pid, "md5": md5, "tags": tags, "file_url": url,
|
|
|
|
"width": width, "height": height,
|
2018-05-10 22:07:55 +02:00
|
|
|
"size": text.parse_bytes(size[:-1]),
|
2018-01-15 16:39:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class PahealPostExtractor(PahealExtractor):
|
|
|
|
"""Extractor for single images from rule34.paheal.net"""
|
|
|
|
subcategory = "post"
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = (r"(?:https?://)?(?:rule34|rule63|cosplay)\.paheal\.net"
|
|
|
|
r"/post/view/(\d+)")
|
|
|
|
test = ("https://rule34.paheal.net/post/view/481609", {
|
2021-11-01 02:58:53 +01:00
|
|
|
"pattern": r"https://tulip\.paheal\.net/_images"
|
|
|
|
r"/bbdc1c33410c2cdce7556c7990be26b7/481609%20-%20"
|
|
|
|
r"Azumanga_Daioh%20Osaka%20Vuvuzela%20inanimate\.jpg",
|
|
|
|
"keyword": "abe7c1220ba5601f9639aa79fbb9689674ec8f5c",
|
2018-01-15 16:39:05 +01:00
|
|
|
"content": "7b924bcf150b352ac75c9d281d061e174c851a11",
|
2019-02-08 13:45:40 +01:00
|
|
|
})
|
2018-01-15 16:39:05 +01:00
|
|
|
|
|
|
|
def __init__(self, match):
|
2019-02-11 13:31:10 +01:00
|
|
|
PahealExtractor.__init__(self, match)
|
2018-01-15 16:39:05 +01:00
|
|
|
self.post_id = match.group(1)
|
|
|
|
|
|
|
|
def get_posts(self):
|
|
|
|
url = "{}/post/view/{}".format(self.root, self.post_id)
|
|
|
|
page = self.request(url).text
|
|
|
|
|
|
|
|
tags , pos = text.extract(page, ": ", "<")
|
|
|
|
md5 , pos = text.extract(page, "/_thumbs/", "/", pos)
|
|
|
|
url , pos = text.extract(page, "id='main_image' src='", "'", pos)
|
2021-02-14 15:40:37 +01:00
|
|
|
width , pos = text.extract(page, "data-width=", " ", pos)
|
|
|
|
height, pos = text.extract(page, "data-height=", " ", pos)
|
2018-01-15 16:39:05 +01:00
|
|
|
|
|
|
|
return ({
|
|
|
|
"id": self.post_id, "md5": md5, "tags": tags, "file_url": url,
|
2021-02-14 15:40:37 +01:00
|
|
|
"size" : 0,
|
|
|
|
"width" : width.strip("'\""),
|
|
|
|
"height": height.strip("'\""),
|
2018-01-15 16:39:05 +01:00
|
|
|
},)
|