From aa7b910b1c6ab0d64bcf3a626955c9219aa28484 Mon Sep 17 00:00:00 2001 From: ripper Date: Wed, 4 Dec 2024 19:50:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=88=B1=E7=9B=98=E6=90=9C?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=EF=BC=8C=E4=BC=98=E5=8C=96=E7=9F=AD=E5=89=A7?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/system_command.py | 15 +++++++++++---- service/aipanso_service.py | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/commands/system_command.py b/commands/system_command.py index 02ff25a..8e9ac6a 100644 --- a/commands/system_command.py +++ b/commands/system_command.py @@ -5,7 +5,7 @@ from lxml import etree from dto.command_dto import CommandContext -from config import TIKHUB_API_TOKEN +from service.aipanso_service import AiPanSoService class SystemCommand: @@ -13,6 +13,9 @@ class SystemCommand: 系统级别命令 """ + def __init__(self): + self.aipanso_service = AiPanSoService() + def video_parse(self, ctx: CommandContext): """ 视频解析 @@ -84,7 +87,11 @@ def search_dj(self, ctx: CommandContext): time.sleep(0.5) if content == "": - return "未找到相关短剧" + # 接入爱盘搜数据源 + content = self.aipanso_service.search_dj(ctx.content) + if content == "": + return "未找到相关短剧" + return content def search_dj_detail(self, url): @@ -126,8 +133,8 @@ def search_dj_detail(self, url): if __name__ == '__main__': service = SystemCommand() - print(service.video_parse(CommandContext( - content="3.89 复制打开抖音,看看【小刘不是程序员的作品】小米14换上澎湃OS2,老安卓用户的春天来了吗? ... https://v.douyin.com/iDyr9ug6/ o@d.nD 09/28 aAT:/ ", + print(service.search_dj(CommandContext( + content="无声秘恋", talker_wxid='', sender_wxid='' ))) diff --git a/service/aipanso_service.py b/service/aipanso_service.py index 879fdfb..bc7cfab 100644 --- a/service/aipanso_service.py +++ b/service/aipanso_service.py @@ -1,3 +1,5 @@ +import time + from Crypto.Cipher import AES from Crypto.Util.Padding import pad import binascii @@ -51,6 +53,7 @@ def get_egg_cookie(self, code: str): url = "https://www.aipanso.com/active" payload = f'code={code}' + self.global_headers['Cookie'] = '' # 根据参数获取 cookie 的值 (有效期 10 分钟) first_start_load_value = self.get_first_start_load_value("POST", url, payload) if first_start_load_value is None: @@ -97,6 +100,9 @@ def get_pan_url(self, fid: str): cookie_value = self.start_load(first_start_load_value) self.global_headers['Cookie'] = cookie + cookie_value + self.global_headers['Referer'] = url + self.global_headers[ + 'Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' # 获取最终网盘地址 response = requests.request("GET", url, headers=self.global_headers, timeout=30, allow_redirects=True) @@ -124,7 +130,6 @@ def start_load(self, input_data): return f"ck_ml_sea_={hex_output}" - def get_search_result(self, keyword): encoded_keyword = quote(keyword) url = f"https://www.aipanso.com/search?k={encoded_keyword}" @@ -157,7 +162,8 @@ def parse_data(html_content): # Extract full title (combining all text within the title div) title = ''.join( - row.xpath('.//div[@style="font-size:medium;font-weight: 550;padding-top: 5px;"]//text()')).strip() + row.xpath( + './/div[@style="font-size:medium;font-weight: 550;padding-top: 5px;"]//text()')).strip() results.append({ 'link': link, @@ -174,7 +180,33 @@ def parse_data(html_content): response = requests.request("GET", url, headers=self.global_headers, timeout=30) return parse_data(response.text) + def search_dj(self, keyword): + """ + 搜索短剧 + :param keyword: + :return: + """ + result_list = self.get_search_result(keyword) + content = "" + for i, item in enumerate(result_list, 1): + try: + if i > 2: + break + fid = item['link'][3:] + pan_url = self.get_pan_url(fid) + if pan_url is None: + content += f"{i}、{item['title']} - 获取网盘地址失败\n\n" + else: + content += f"{i}、{item['title']} - {pan_url}\n\n" + + except Exception as e: + print(f"爱搜盘数据获取失败: {e}") + finally: + time.sleep(0.5) + + return content + if __name__ == '__main__': ai_service = AiPanSoService() - print(ai_service.get_search_result("无声秘恋")) + print(ai_service.search_dj("无声秘恋"))