Files
MusicServer/app/sdk/platforms/lr/music_search.py
T
snowy-yang dfc06bf4de feat(python): 完成 Python 全量迁移——剩余平台、登录通道与公共层修复
- 新增 5sing/apple/xm/me/qt/lr 平台包与取流实现(含 xm-sign、MissEvan 签名、蜻蜓 HMAC、Apple developer token)
- 新增 wy/kg/tx/lr 登录:扫码、手机号、账密(kg 20028 风控指纹)、cookie 绑定、kg/tx 续期
- request 层:保留多值 Set-Cookie;JSON body 紧凑化(修复 kg 网关验签);直连不经系统代理(对齐 Node)
- 登录路由统一 Body(embed=True),修复扫码轮询 422;lifespan 接入登录续期调度
- ruff/format/pyright 全绿;14 平台真实联网与 HTTP 路由验证通过
2026-10-23 21:55:45 +08:00

59 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""懒人听书搜索(对应 sdk/lr/musicSearch.ts,App 通道,游客匿名)。
接口: /yyting/search/searchBatch.action?keyWord=&searchOption=1&pageSize=&type=0&q=2150
实测(2026-10-02)匿名可用;结果分 data.bookResult/albumResult/folderResult/...
书籍条目字段:id(baseEntityId 同值)/name/announcer/cover
"""
from __future__ import annotations
import math
from typing import Any
from app.sdk.common.utils import as_dict, as_list
from app.sdk.platforms.lr.app_api import app_api_get
async def search(keyword: str, page: int = 1, limit: int = 20, retry_num: int = 0) -> dict[str, Any]:
del retry_num # 契约参数,游客搜索无重试语义
body = await app_api_get(
"/yyting/search/searchBatch.action",
{
"keyWord": keyword,
"searchOption": "1",
"pageSize": str(limit),
"type": str(page - 1),
"q": "2150",
},
)
api_status = body.get("apiStatus")
if api_status is not None and api_status != 0:
raise RuntimeError(str(body.get("msg") or f"搜索失败(code {api_status})"))
book_result = as_dict(as_dict(body.get("data")).get("bookResult"))
books = [item for item in as_list(book_result.get("list")) if isinstance(item, dict)]
total = int(book_result.get("count") or len(books))
return {
"allPage": math.ceil(total / limit) or page,
"total": total,
"limit": limit,
"source": "lr",
"list": [
{
"songmid": str(item.get("id", item.get("baseEntityId"))),
"name": item.get("name") or "",
"singer": item.get("announcer") or item.get("author") or "",
"albumId": "",
"albumName": "",
"interval": 0,
"payPlay": False,
"img": item.get("cover") or None,
"lrc": "",
"lrcx": "",
"types": [],
"_types": {},
"disabled": False,
}
for item in books
],
}