Files
MusicServer/sdk/bd/musicSearch.ts
T
snowy-yang e1357dd412 refactor(api)!: 平台 id 回退——joox/5sing/bili/apple 恢复全名,目录对齐 bd/mg
- 撤销 3381e9b/1b972ec 中 jx/5s/bl/ap 四个短码,恢复 joox/5sing/bili/apple;
  qian→bd、migu→mg 保留
- 目录与文件对齐保留的新 id:sdk/qian/→sdk/bd/、sdk/migu/→sdk/mg/、
  sdk/apis/qian.ts→bd.ts、migu.ts→mg.ts、src/http/migu-stream.ts→mg-stream.ts
  (规则改为「目录=对外 id」,聚合入口的模块变量同步更名;music.migu.cn 等域名、
  上游 music-lib 对照注释、miguGet 等功能标识符不动)
- 对外 id 全表:kw kg tx wy qs xm me qt lr mg bd joox 5sing bili apple

**破坏性变更**:joox/5sing/bili/apple 四平台的 URL、/sources 返回与
data/auth.json 凭据键恢复全名,已存短码键的登录态需重新登录。

验证:typecheck ✓、pnpm test 112/112 ✓
2026-10-03 21:04:55 +08:00

36 lines
1.4 KiB
TypeScript
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.
// 千千音乐搜索(/v1/search?word=&type=1&pageNo=&pageSize=,appid + 签名)
// 响应 data.typeTrack[]:TSID/title/albumTitle/albumAssetCode/pic/duration/artist/rateFileInfo/isVip
// 注:上游会跳过 isVip != 0 的曲目(VIP 无法匿名取流);本实现保留并标记 payPlay,
// 以便聚合搜索/顺播时仍能展示(取流失败会返回明确错误,路由可走兜底链路)。
import { APP_ID, apiGet, apiOk, mapTrack } from './util.ts'
export const search = async(keyword: string, page = 1, limit = 20) => {
const word = String(keyword ?? '').trim()
const empty = { list: [] as any[], allPage: 1, total: 0, limit, source: 'bd' as const }
if (!word) return empty
const body = await apiGet('/v1/search', {
word,
type: '1',
pageNo: String(page),
pageSize: String(limit),
appid: APP_ID,
})
if (!apiOk(body) && Number(body?.errno) !== 23001) {
throw new Error(body?.errmsg || `千千搜索失败(errno ${body?.errno})`)
}
const tracks = Array.isArray(body?.data?.typeTrack) ? body.data.typeTrack : []
const total = Number(body?.data?.total) || tracks.length
const haveMore = Number(body?.data?.haveMore) === 1
return {
list: tracks.map((item: any) => mapTrack(item)).filter((song: any) => song.songmid),
allPage: haveMore ? page + 1 : Math.max(page, Math.ceil(total / Math.max(1, limit)) || 1),
total,
limit,
source: 'bd' as const,
}
}
export default { search }