fix(bili): 取流 CDN 分级选址——backupUrl 按 host 分级探测,根治 PCDN 点歌卡死

playurl 的 baseUrl 大概率落在 PCDN(京东云无线宝 mcdn.bilivideo.cn、迅雷
mountaintoys 等),旧代码只取 baseUrl(backupUrl 0 处使用)且探测失败仍
原样返回坏地址,点歌端连 PCDN 挂死。现候选 = baseUrl+backupUrl 按 host
分级(upos/Akamai 正规 CDN > cn-* 等 bilivideo.com 系 > PCDN),探测改为
fetch 只读响应头即断开(不等 body,CDN 忽略 Range 回 200 全量时不再整文件
缓冲),单跳 8s / 总预算 20s / 至多 3 候选,全败回退最优候选(fail-soft);
CDN 探测不再携带 Cookie(直链自带签名,避免登录态泄给第三方 PCDN 域名)。
getAudioUrl 返回 urls[],parse 改取 urls[0]。

新增 test/bili-cdn-test.ts(SDK 层 PCDN 硬断言,并入 pnpm test)与 smoke
「URL bili(CDN 分级选址)」软断言项。
This commit is contained in:
snowy-yang committed 2026-10-04 17:29:28 +08:00
1 parent e1357dd412
commit cec63f864e
5 files changed
+186 -41

No files matched your search

+3 -3
View File
@@ -51,12 +51,12 @@ export const parseSong = async(link: string) => {
page,
})
// 上游 Parse 会立即填充音频地址(失败忽略)
// 上游 Parse 会立即填充音频地址(失败忽略);urls 已按 CDN 分级排序,取最优候选
if (cid) {
try {
const audio = await getAudioUrl(song.bvid, cid)
if (audio?.url) {
song.url = audio.url
if (audio?.urls?.[0]) {
song.url = audio.urls[0]
song.type = audio.type
}
} catch {