Files
MusicServer/app/sdk/platforms/bd/lyric.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

31 lines
1.2 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/bd/lyric.ts)。
链路:`/v1/song/info` → `data[0].lyric` 为歌词文本 URL(static-qianqian.taihe.com/*.txt)
→ 直接下载文本。返回 `{lyric, tlyric: ''}`(千千只有原文歌词,无翻译)。
"""
from __future__ import annotations
from typing import Any
from app.sdk.common.request import http_fetch
from app.sdk.platforms.bd.music_info import get_song_info
from app.sdk.platforms.bd.util import request_headers
async def get_lyric(song_info: dict[str, Any]) -> dict[str, Any]:
tsid = str(song_info.get("songmid") or song_info.get("TSID") or "").strip()
if not tsid:
raise RuntimeError("千千歌词需要 songmid(TSID)")
info = await get_song_info(tsid)
lyric_url = str(info.get("lyricUrl") or "").strip()
if not lyric_url:
raise RuntimeError("千千该歌曲暂无歌词")
resp = await http_fetch(lyric_url, method="get", headers=request_headers(), timeout=15000)
if resp.status_code != 200:
raise RuntimeError(f"千千歌词下载失败(HTTP {resp.status_code})")
lyric = resp.body if isinstance(resp.body, str) else resp.raw.decode("utf-8", errors="replace")
return {"lyric": lyric, "tlyric": ""}