- 移除 bd/mg 两平台及磁盘残留产物;清理 api-test 死脚本、musicSdk/message+options 死模块、infSign vendor - musicSdk/ 改名 sdk/;src/common、src/auth、src/apis 整体移入 sdk/,依赖方向定为 src → sdk 严格单向 - src/ 手写 JS 全量转 .ts,删除 JS 类型垫片 modules.d.ts;源码 import 统一 .ts 后缀 - Node 原生类型剥离直接运行 .ts(engines >=22.18),取消 tsc 发射产物,tsc 仅类型检查(pnpm typecheck) - 删除 kwdes 备用实现与 src/index.ts 转发垫片;测试移至 test/smoke-test.ts - common/request.ts 补显式导出类型;修复 set-cookie 单值形态、ApiError 类字段等隐患 验证:tsc 零错误,smoke-test 41/41
100 lines
2.6 KiB
TypeScript
100 lines
2.6 KiB
TypeScript
import type { HttpRequestObject, SongType, Quality, QualityInfo } from '../types.ts'
|
|
import { httpFetch } from '../request.ts'
|
|
import { formatPlayTime, sizeFormate } from '../index.ts'
|
|
|
|
const getSinger = (singers) => {
|
|
let arr: string[] = []
|
|
singers.forEach(singer => {
|
|
arr.push(singer.name)
|
|
})
|
|
return arr.join('、')
|
|
}
|
|
|
|
export default (songmid) => {
|
|
const requestObj = httpFetch('https://u.y.qq.com/cgi-bin/musicu.fcg', {
|
|
method: 'post',
|
|
headers: {
|
|
'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
|
|
},
|
|
body: {
|
|
comm: {
|
|
ct: '19',
|
|
cv: '1859',
|
|
uin: '0',
|
|
},
|
|
req: {
|
|
module: 'music.pf_song_detail_svr',
|
|
method: 'get_song_detail_yqq',
|
|
param: {
|
|
song_type: 0,
|
|
song_mid: songmid,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
return requestObj.promise.then(({ body }) => {
|
|
// console.log(body)
|
|
if (body.code != 0 || body.req.code != 0) return Promise.reject(new Error('获取歌曲信息失败'))
|
|
const item = body.req.data.track_info
|
|
if (!item.file?.media_mid) return null
|
|
|
|
let types: SongType[] = []
|
|
let _types: Partial<Record<Quality, QualityInfo>> = {}
|
|
const file = item.file
|
|
if (file.size_128mp3 != 0) {
|
|
let size = sizeFormate(file.size_128mp3)
|
|
types.push({ type: '128k', size })
|
|
_types['128k'] = {
|
|
size,
|
|
}
|
|
}
|
|
if (file.size_320mp3 !== 0) {
|
|
let size = sizeFormate(file.size_320mp3)
|
|
types.push({ type: '320k', size })
|
|
_types['320k'] = {
|
|
size,
|
|
}
|
|
}
|
|
if (file.size_flac !== 0) {
|
|
let size = sizeFormate(file.size_flac)
|
|
types.push({ type: 'flac', size })
|
|
_types.flac = {
|
|
size,
|
|
}
|
|
}
|
|
if (file.size_hires !== 0) {
|
|
let size = sizeFormate(file.size_hires)
|
|
types.push({ type: 'flac24bit', size })
|
|
_types.flac24bit = {
|
|
size,
|
|
}
|
|
}
|
|
// types.reverse()
|
|
let albumId = ''
|
|
let albumName = ''
|
|
if (item.album) {
|
|
albumName = item.album.name
|
|
albumId = item.album.mid
|
|
}
|
|
return {
|
|
singer: getSinger(item.singer),
|
|
name: item.title,
|
|
albumName,
|
|
albumId,
|
|
source: 'tx',
|
|
interval: formatPlayTime(item.interval),
|
|
songId: item.id,
|
|
albumMid: item.album?.mid ?? '',
|
|
strMediaMid: item.file.media_mid,
|
|
songmid: item.mid,
|
|
img: (albumId === '' || albumId === '空')
|
|
? item.singer?.length ? `https://y.gtimg.cn/music/photo_new/T001R500x500M000${item.singer[0].mid}.jpg` : ''
|
|
: `https://y.gtimg.cn/music/photo_new/T002R500x500M000${albumId}.jpg`,
|
|
types,
|
|
_types,
|
|
typeUrl: {},
|
|
}
|
|
})
|
|
}
|
|
|