- 新增 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 路由验证通过
49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
"""千千音乐链接解析(对应 sdk/bd/parse.ts)。
|
|
|
|
歌曲:`music.91q.com/song/<TSID>`(上游 Parse:取 song/info 后顺带取直链,失败不影响返回)。
|
|
专辑:`music.91q.com/album/<P码>` / `?albumAssetCode=` / `?albumid=`。
|
|
歌单:`music.91q.com/songlist|tracklist|playlist/<id>` / `?*id=` / 裸歌单 id。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
from typing import Any
|
|
|
|
from app.sdk.platforms.bd import album as album_module
|
|
from app.sdk.platforms.bd import playlist as playlist_module
|
|
from app.sdk.platforms.bd.music_info import get_song_info
|
|
from app.sdk.platforms.bd.util import first_non_empty
|
|
|
|
_TSID_RE = re.compile(r"music\.91q\.com/song/(\w+)", re.ASCII)
|
|
|
|
|
|
async def parse_song(link: str) -> dict[str, Any]:
|
|
"""上游 Parse:歌曲链接 → Song(尽力附带直链 url/type)。"""
|
|
match = _TSID_RE.search(str(link if link is not None else ""))
|
|
if not match:
|
|
raise RuntimeError("无效的千千歌曲链接")
|
|
tsid = match.group(1)
|
|
|
|
song: dict[str, Any] = dict(await get_song_info(tsid))
|
|
try:
|
|
# 延迟导入:`apis/bd.py` 依赖本包的 util,顶层导入会让包初始化与 apis 互等
|
|
from app.sdk.apis.bd import get_download_url
|
|
|
|
hit = await get_download_url(tsid)
|
|
song["url"] = hit["url"]
|
|
song["type"] = hit["type"]
|
|
except Exception: # noqa: BLE001 - 与上游一致:直链获取失败忽略(VIP/下架曲目仍返回元数据)
|
|
pass
|
|
song.pop("lyricUrl", None)
|
|
song.pop("raw", None)
|
|
return {**song, "songmid": first_non_empty(song.get("songmid"), tsid), "source": "bd"}
|
|
|
|
|
|
async def parse_album(link: str) -> dict[str, Any]:
|
|
return await album_module.parse_album_link(link)
|
|
|
|
|
|
async def parse_playlist(link: str) -> dict[str, Any]:
|
|
return await playlist_module.parse_playlist_link(link)
|