Files
MusicServer/sdk/qian/lyric.ts
T
snowy-yang 8c02fb5c15 refactor(sdk): 审计 P2 卫生项清理——请求层收敛与死代码清除
- 删除旧 sdk/request.ts,全部 import 收敛到 sdk/common/request.ts(85 文件)
- 注释死代码 630+ 行、裸 console.log 吞错 6 处、未使用符号 26 处清零
- bili 状态校验去重;utils DNS 预解析失败日志改 warn 带上下文
- CODE-AUDIT.md:第四节 P2 清理记录 + 第八节线索逐条复核结论(kw/kg/tx/wy parse 骨架相似实质各异,不抽公共层)
2026-10-03 20:48:54 +08:00

35 lines
1.3 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/song/info → data[0].lyric 为歌词文本 URL(static-qianqian.taihe.com/*.txt)→ 直接下载文本。
// 返回 { lyric, tlyric: '' }(千千只有原文歌词,无翻译)。
import { httpFetch } from '../common/request.ts'
import { getSongInfo } from './musicInfo.ts'
import { requestHeaders } from './util.ts'
export const getLyric = (songInfo: any) => {
const requestObj: any = { promise: null, cancelHttp() {} }
const tsid = String(songInfo?.songmid ?? songInfo?.TSID ?? '').trim()
let lyricReq: any = null
requestObj.cancelHttp = () => {
lyricReq?.cancelHttp?.()
lyricReq = null
}
requestObj.promise = (async() => {
if (!tsid) throw new Error('千千歌词需要 songmid(TSID)')
const info = await getSongInfo(tsid)
const lyricUrl = info?.lyricUrl
if (!lyricUrl) throw new Error('千千该歌曲暂无歌词')
lyricReq = httpFetch(lyricUrl, { headers: requestHeaders(), timeout: 15000 })
const { statusCode, body, raw } = await lyricReq.promise as any
if (statusCode != 200) throw new Error(`千千歌词下载失败(HTTP ${statusCode})`)
const lyric = typeof body === 'string' ? body : raw?.toString('utf8') ?? ''
return { lyric, tlyric: '' }
})()
return requestObj
}
export default { getLyric }