From d301f5e370f8e6cdb9cd0357a6de3eb9fdf5d82d Mon Sep 17 00:00:00 2001 From: omg-xtao <100690902+omg-xtao@users.noreply.github.com> Date: Mon, 29 Jul 2024 12:44:05 +0800 Subject: [PATCH] =?UTF-8?q?zpr=20=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zpr/main.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/zpr/main.py b/zpr/main.py index 6691532..44c03d7 100644 --- a/zpr/main.py +++ b/zpr/main.py @@ -1,21 +1,19 @@ import contextlib import shutil -from os import makedirs -from os.path import exists, dirname, abspath from pagermaid.listener import listener from pagermaid.enums import Client, Message, AsyncClient from pyrogram.types import InputMediaPhoto from pyrogram.errors import RPCError from pathlib import Path -pixiv_img_host = "pixiv.yuki.sh" +pixiv_img_host = "i.pixiv.cat" headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.42" } data_path = Path("data/zpr") -async def get_result(message, request, r18=2): +async def get_result(message, request, r18=0): # r18: 0为非 R18,1为 R18,2为混合(在库中的分类,不等同于作品本身的 R18 标识) # num: 图片的数量 # size: 返回图片的尺寸质量 @@ -23,7 +21,7 @@ async def get_result(message, request, r18=2): size = "regular" des = "出错了,没有纸片人看了。" data = await request.get( - f"https://api.lolicon.app/setu/v2?num=5&r18={r18}&size={size}", + f"https://api.lolicon.app/setu/v2?num=1&r18={r18}&size={size}", headers=headers, timeout=10, ) @@ -36,8 +34,10 @@ async def get_result(message, request, r18=2): return None, "解析JSON出错。" setu_list = [] # 发送 await message.edit("努力获取中 。。。") - for i in range(5): + for i in range(1): urls = result[i]["urls"][size].replace("i.pixiv.re", pixiv_img_host) + pid = result[i]["pid"] + title = result[i]["title"] img_name = f"{result[i]['pid']}_{i}.jpg" file_path = data_path / img_name try: @@ -48,7 +48,8 @@ async def get_result(message, request, r18=2): f.write(img.content) except Exception: return None, None, "连接二次元出错。。。" - setu_list.append(InputMediaPhoto(media=str(file_path))) + spoiler = r18 == 1 + setu_list.append(InputMediaPhoto(media=str(file_path), caption=f"[Pixiv] {title} PID:{pid}", has_spoiler=spoiler)) return setu_list, des if setu_list else None @@ -58,7 +59,7 @@ async def zpr(client: Client, message: Message, request: AsyncClient): message = await message.edit("正在前往二次元。。。") try: photoList, des = await get_result( - message, request, r18=2 if arguments == "R18" else 0 + message, request, r18=1 if arguments == "R18" else 0 ) if not photoList: shutil.rmtree("data/zpr")