2022-06-20 11:25:42 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2023-01-05 12:29:31 +01:00
|
|
|
# Copyright 2022-2023 Mike Fährmann
|
2022-06-20 11:25:42 +02: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.
|
|
|
|
|
|
|
|
"""Extractors for https://poipiku.com/"""
|
|
|
|
|
|
|
|
from .common import Extractor, Message
|
|
|
|
from .. import text
|
|
|
|
|
|
|
|
BASE_PATTERN = r"(?:https?://)?poipiku\.com"
|
|
|
|
|
|
|
|
|
|
|
|
class PoipikuExtractor(Extractor):
|
|
|
|
"""Base class for poipiku extractors"""
|
|
|
|
category = "poipiku"
|
|
|
|
root = "https://poipiku.com"
|
|
|
|
directory_fmt = ("{category}", "{user_id} {user_name}")
|
|
|
|
filename_fmt = "{post_id}_{num}.{extension}"
|
|
|
|
archive_fmt = "{post_id}_{num}"
|
|
|
|
request_interval = (0.5, 1.5)
|
|
|
|
|
2024-05-09 15:14:08 +02:00
|
|
|
def _init(self):
|
2024-05-17 02:50:31 +02:00
|
|
|
self.cookies.set(
|
|
|
|
"LANG", "en", domain="poipiku.com")
|
2024-05-09 15:14:08 +02:00
|
|
|
self.cookies.set(
|
|
|
|
"POIPIKU_CONTENTS_VIEW_MODE", "1", domain="poipiku.com")
|
|
|
|
|
2022-06-20 11:25:42 +02:00
|
|
|
def items(self):
|
2022-06-22 18:21:01 +02:00
|
|
|
password = self.config("password", "")
|
|
|
|
|
2022-06-20 11:25:42 +02:00
|
|
|
for post_url in self.posts():
|
|
|
|
parts = post_url.split("/")
|
|
|
|
if post_url[0] == "/":
|
|
|
|
post_url = self.root + post_url
|
|
|
|
page = self.request(post_url).text
|
|
|
|
extr = text.extract_from(page)
|
|
|
|
|
|
|
|
post = {
|
|
|
|
"post_category": extr("<title>[", "]"),
|
|
|
|
"count" : extr("(", " "),
|
|
|
|
"post_id" : parts[-1].partition(".")[0],
|
|
|
|
"user_id" : parts[-2],
|
|
|
|
"user_name" : text.unescape(extr(
|
|
|
|
'<h2 class="UserInfoUserName">', '</').rpartition(">")[2]),
|
|
|
|
"description": text.unescape(extr(
|
2023-05-15 23:16:31 +02:00
|
|
|
'class="IllustItemDesc" >', '</h1>')),
|
2022-09-12 11:21:01 +02:00
|
|
|
"_http_headers": {"Referer": post_url},
|
2022-06-20 11:25:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
yield Message.Directory, post
|
|
|
|
post["num"] = 0
|
|
|
|
|
|
|
|
while True:
|
|
|
|
thumb = extr('class="IllustItemThumbImg" src="', '"')
|
|
|
|
if not thumb:
|
|
|
|
break
|
2022-08-01 12:36:19 +02:00
|
|
|
elif thumb.startswith(("//img.poipiku.com/img/", "/img/")):
|
2022-06-20 11:25:42 +02:00
|
|
|
continue
|
|
|
|
post["num"] += 1
|
2022-09-12 11:21:01 +02:00
|
|
|
url = text.ensure_http_scheme(thumb[:-8]).replace(
|
|
|
|
"//img.", "//img-org.", 1)
|
2022-06-20 11:25:42 +02:00
|
|
|
yield Message.Url, url, text.nameext_from_url(url, post)
|
|
|
|
|
2024-05-13 20:42:02 +02:00
|
|
|
if not extr('ShowAppendFile', '<'):
|
2022-06-20 11:25:42 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
url = self.root + "/f/ShowAppendFileF.jsp"
|
|
|
|
headers = {
|
|
|
|
"Accept" : "application/json, text/javascript, */*; q=0.01",
|
|
|
|
"X-Requested-With": "XMLHttpRequest",
|
|
|
|
"Origin" : self.root,
|
|
|
|
"Referer": post_url,
|
|
|
|
}
|
|
|
|
data = {
|
|
|
|
"UID": post["user_id"],
|
|
|
|
"IID": post["post_id"],
|
2022-06-22 18:21:01 +02:00
|
|
|
"PAS": password,
|
2022-06-20 11:25:42 +02:00
|
|
|
"MD" : "0",
|
|
|
|
"TWF": "-1",
|
|
|
|
}
|
2023-06-27 21:45:44 +02:00
|
|
|
resp = self.request(
|
|
|
|
url, method="POST", headers=headers, data=data).json()
|
2022-06-20 11:25:42 +02:00
|
|
|
|
2023-06-27 21:45:44 +02:00
|
|
|
page = resp["html"]
|
|
|
|
if (resp.get("result_num") or 0) < 0:
|
|
|
|
self.log.warning("'%s'", page.replace("<br/>", " "))
|
2023-01-05 12:29:31 +01:00
|
|
|
|
2022-06-20 11:25:42 +02:00
|
|
|
for thumb in text.extract_iter(
|
|
|
|
page, 'class="IllustItemThumbImg" src="', '"'):
|
|
|
|
post["num"] += 1
|
2022-09-12 11:21:01 +02:00
|
|
|
url = text.ensure_http_scheme(thumb[:-8]).replace(
|
|
|
|
"//img.", "//img-org.", 1)
|
2022-06-20 11:25:42 +02:00
|
|
|
yield Message.Url, url, text.nameext_from_url(url, post)
|
|
|
|
|
|
|
|
|
|
|
|
class PoipikuUserExtractor(PoipikuExtractor):
|
|
|
|
"""Extractor for posts from a poipiku user"""
|
|
|
|
subcategory = "user"
|
|
|
|
pattern = (BASE_PATTERN + r"/(?:IllustListPcV\.jsp\?PG=(\d+)&ID=)?"
|
|
|
|
r"(\d+)/?(?:$|[?&#])")
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://poipiku.com/12345/"
|
2022-06-20 11:25:42 +02:00
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
PoipikuExtractor.__init__(self, match)
|
|
|
|
self._page, self.user_id = match.groups()
|
|
|
|
|
|
|
|
def posts(self):
|
|
|
|
url = self.root + "/IllustListPcV.jsp"
|
|
|
|
params = {
|
|
|
|
"PG" : text.parse_int(self._page, 0),
|
|
|
|
"ID" : self.user_id,
|
|
|
|
"KWD": "",
|
|
|
|
}
|
|
|
|
|
|
|
|
while True:
|
|
|
|
page = self.request(url, params=params).text
|
|
|
|
|
|
|
|
cnt = 0
|
|
|
|
for path in text.extract_iter(
|
|
|
|
page, 'class="IllustInfo" href="', '"'):
|
|
|
|
yield path
|
|
|
|
cnt += 1
|
|
|
|
|
|
|
|
if cnt < 48:
|
|
|
|
return
|
|
|
|
params["PG"] += 1
|
|
|
|
|
|
|
|
|
|
|
|
class PoipikuPostExtractor(PoipikuExtractor):
|
|
|
|
"""Extractor for a poipiku post"""
|
|
|
|
subcategory = "post"
|
|
|
|
pattern = BASE_PATTERN + r"/(\d+)/(\d+)"
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://poipiku.com/12345/12345.html"
|
2022-06-20 11:25:42 +02:00
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
PoipikuExtractor.__init__(self, match)
|
|
|
|
self.user_id, self.post_id = match.groups()
|
|
|
|
|
|
|
|
def posts(self):
|
|
|
|
return ("/{}/{}.html".format(self.user_id, self.post_id),)
|