Skip to content

Commit

Permalink
添加爱盘搜服务,优化短剧搜索功能。
Browse files Browse the repository at this point in the history
  • Loading branch information
rippergs committed Dec 4, 2024
1 parent 8803db5 commit aa7b910
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
15 changes: 11 additions & 4 deletions commands/system_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
from lxml import etree

from dto.command_dto import CommandContext
from config import TIKHUB_API_TOKEN
from service.aipanso_service import AiPanSoService


class SystemCommand:
"""
系统级别命令
"""

def __init__(self):
self.aipanso_service = AiPanSoService()

def video_parse(self, ctx: CommandContext):
"""
视频解析
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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/ [email protected] 09/28 aAT:/ ",
print(service.search_dj(CommandContext(
content="无声秘恋",
talker_wxid='',
sender_wxid=''
)))
38 changes: 35 additions & 3 deletions service/aipanso_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
import binascii
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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,
Expand All @@ -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("无声秘恋"))

0 comments on commit aa7b910

Please sign in to comment.