Files
MusicServer/sdk/apis/wy.ts
T
snowy-yang 66d06ef48a refactor(sdk): tipSearch 全删、歌词解码器归位、IPC 桥移除、api-source 层拆除
- 四平台 tipSearch 全部删除(永不做搜索联想),types 同步去掉 tipSearch 字段
- 歌词解码器归位:kg/krcDecode、tx/qrcDecode、kw/lyricDecode(原 common/ 下三处)
- rendererIpc/ipcNames IPC 桥删除,SDK 纯服务端化
- supportQuality 由各平台 apis 内联导出(sdk/index 汇总),kg/kw/tx/wy 改直连 apis/*,api-source 旧层移除
2026-10-01 16:33:53 +08:00

52 lines
1.9 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.
// 网易云音乐 URL 获取(直连)
// 接口: https://interface3.music.163.com/eapi/song/enhance/player/url/v1(eapi 加密请求,响应为明文 JSON)
// 音质: 128k → standard, 320k → exhigh, flac → lossless
// 统一接口约定:apis('wy').getMusicUrl(songInfo, type) → { promise, cancelHttp }
// promise resolve → { type, url }
import { httpFetch } from '../common/request.ts'
// crypto.js 为 tsc 就地发射产物(源 sdk/wy/utils/crypto.ts);统一走 .js,避免同进程出现 .ts/.js 双实例
import { eapi } from '../wy/utils/crypto.ts'
import { getWyCookie } from '../auth/store.ts'
const levelMap = {
'128k': 'standard',
'320k': 'exhigh',
flac: 'lossless',
flac24bit: 'hires',
}
// 官方直连接口支持的音质(sdk/index.ts 汇总为 supportQuality)
export const supportQualitys = Object.keys(levelMap)
export const getMusicUrl = (songInfo, type) => {
const requestObj = { cancelHttp() {}, promise: null as any }
const data = {
ids: `[${songInfo.songmid}]`,
level: levelMap[type] || 'standard',
encodeType: 'flac',
}
const cookie = getWyCookie()
const request = httpFetch('https://interface3.music.163.com/eapi/song/enhance/player/url/v1', {
method: 'post',
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
origin: 'https://music.163.com',
...(cookie ? { cookie } : {}),
},
form: eapi('/api/song/enhance/player/url/v1', data),
timeout: 15000,
})
requestObj.promise = request.promise.then(({ statusCode, body }) => {
if (statusCode != 200 || body.code != 200) {
return Promise.reject(new Error('获取失败'))
}
const item = body.data?.[0]
if (!item?.url) return Promise.reject(new Error('获取失败'))
return { type, url: item.url }
})
return requestObj
}
export default { getMusicUrl }