2018-01-15 16:39:05 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2023-04-26 18:01:07 +02:00
|
|
|
# Copyright 2018-2023 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"""
|
2023-04-26 18:01:07 +02:00
|
|
|
basecategory = "shimmie2"
|
2018-01-15 16:39:05 +01:00
|
|
|
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):
|
2023-07-21 22:38:39 +02:00
|
|
|
self.cookies.set(
|
2020-10-28 21:51:31 +01:00
|
|
|
"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
|
2023-12-26 16:09:26 +01:00
|
|
|
yield Message.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"""
|
|
|
|
|
2022-05-30 17:23:08 +02:00
|
|
|
def _extract_post(self, post_id):
|
|
|
|
url = "{}/post/view/{}".format(self.root, post_id)
|
|
|
|
extr = text.extract_from(self.request(url).text)
|
|
|
|
|
|
|
|
post = {
|
|
|
|
"id" : post_id,
|
|
|
|
"tags" : extr(": ", "<"),
|
|
|
|
"md5" : extr("/_thumbs/", "/"),
|
2022-09-04 13:20:30 +02:00
|
|
|
"file_url": (extr("id='main_image' src='", "'") or
|
|
|
|
extr("<source src='", "'")),
|
2022-05-30 17:23:08 +02:00
|
|
|
"uploader": text.unquote(extr(
|
|
|
|
"class='username' href='/user/", "'")),
|
|
|
|
"date" : text.parse_datetime(
|
|
|
|
extr("datetime='", "'"), "%Y-%m-%dT%H:%M:%S%z"),
|
2023-07-07 20:03:00 +02:00
|
|
|
"source" : text.unescape(text.extr(
|
2024-01-19 22:24:39 +01:00
|
|
|
extr(">Source Link<", "</td>"), "href='", "'")),
|
2022-05-30 17:23:08 +02:00
|
|
|
}
|
|
|
|
|
2023-12-26 16:09:26 +01:00
|
|
|
dimensions, size, ext = extr("Info</th><td>", "<").split(" // ")
|
2022-05-30 17:23:08 +02:00
|
|
|
post["size"] = text.parse_bytes(size[:-1])
|
2023-12-26 16:09:26 +01:00
|
|
|
post["width"], _, height = dimensions.partition("x")
|
2022-09-04 13:20:30 +02:00
|
|
|
post["height"], _, duration = height.partition(", ")
|
|
|
|
post["duration"] = text.parse_float(duration[:-1])
|
2023-12-26 16:09:26 +01:00
|
|
|
post["filename"] = "{} - {}".format(post_id, post["tags"])
|
|
|
|
post["extension"] = ext
|
2022-05-30 17:23:08 +02:00
|
|
|
|
2022-06-04 16:05:49 +02:00
|
|
|
return post
|
2022-05-30 17:23:08 +02:00
|
|
|
|
2018-01-15 16:39:05 +01:00
|
|
|
|
|
|
|
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/([^/?#]+)")
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://rule34.paheal.net/post/list/TAG/1"
|
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))
|
|
|
|
|
2023-07-25 20:09:44 +02:00
|
|
|
def _init(self):
|
2022-06-04 16:05:49 +02:00
|
|
|
if self.config("metadata"):
|
|
|
|
self._extract_data = self._extract_data_ex
|
|
|
|
|
2018-01-15 16:39:05 +01:00
|
|
|
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
|
|
|
|
|
2023-07-04 17:36:41 +02:00
|
|
|
pos = page.find("id='image-list'")
|
2018-01-15 16:39:05 +01:00
|
|
|
for post in text.extract_iter(
|
2023-07-04 17:36:41 +02:00
|
|
|
page, "<img id='thumb_", "Only</a>", pos):
|
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):
|
2023-07-04 17:36:41 +02:00
|
|
|
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)
|
2018-01-15 16:39:05 +01:00
|
|
|
|
2020-10-28 21:51:31 +01:00
|
|
|
tags, data, date = data.split("\n")
|
|
|
|
dimensions, size, ext = data.split(" // ")
|
2023-12-26 16:09:26 +01:00
|
|
|
tags = text.unescape(tags)
|
2018-01-15 16:39:05 +01:00
|
|
|
width, _, height = dimensions.partition("x")
|
2022-09-04 13:20:30 +02:00
|
|
|
height, _, duration = height.partition(", ")
|
2018-01-15 16:39:05 +01:00
|
|
|
|
|
|
|
return {
|
2022-05-30 17:23:08 +02:00
|
|
|
"id": pid, "md5": md5, "file_url": url,
|
2018-01-15 16:39:05 +01:00
|
|
|
"width": width, "height": height,
|
2022-09-04 13:20:30 +02:00
|
|
|
"duration": text.parse_float(duration[:-1]),
|
2023-12-26 16:09:26 +01:00
|
|
|
"tags": tags,
|
2018-05-10 22:07:55 +02:00
|
|
|
"size": text.parse_bytes(size[:-1]),
|
2022-06-04 16:05:49 +02:00
|
|
|
"date": text.parse_datetime(date, "%B %d, %Y; %H:%M"),
|
2023-12-26 16:09:26 +01:00
|
|
|
"filename" : "{} - {}".format(pid, tags),
|
|
|
|
"extension": ext,
|
2018-01-15 16:39:05 +01:00
|
|
|
}
|
|
|
|
|
2022-06-04 16:05:49 +02:00
|
|
|
def _extract_data_ex(self, post):
|
2023-07-07 20:00:49 +02:00
|
|
|
pid = post[:post.index("'")]
|
2022-06-04 16:05:49 +02:00
|
|
|
return self._extract_post(pid)
|
|
|
|
|
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+)")
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://rule34.paheal.net/post/view/12345"
|
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):
|
2022-06-04 16:05:49 +02:00
|
|
|
return (self._extract_post(self.post_id),)
|