# -*- coding: utf-8 -*-
# Copyright 2018-2020 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.
"""Extractors for https://rule34.paheal.net/"""
from .common import Extractor, Message
from .. import text
class PahealExtractor(Extractor):
"""Base class for paheal extractors"""
basecategory = "booru"
category = "paheal"
filename_fmt = "{category}_{id}_{md5}.{extension}"
archive_fmt = "{id}"
root = "https://rule34.paheal.net"
def items(self):
self.session.cookies.set(
"ui-tnc-agreed", "true", domain="rule34.paheal.net")
data = self.get_metadata()
for post in self.get_posts():
url = post["file_url"]
for key in ("id", "width", "height"):
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)
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"
directory_fmt = ("{category}", "{search_tags}")
pattern = (r"(?:https?://)?(?:rule34|rule63|cosplay)\.paheal\.net"
r"/post/list/([^/?#]+)")
test = ("https://rule34.paheal.net/post/list/Ayane_Suzuki/1", {
"pattern": r"https://[^.]+\.paheal\.net/_images/\w+/\d+%20-%20",
"count": ">= 15"
})
per_page = 70
def __init__(self, match):
PahealExtractor.__init__(self, match)
self.tags = text.unquote(match.group(1))
def get_metadata(self):
return {"search_tags": self.tags}
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(
page, '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, '