- 删除旧 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 骨架相似实质各异,不抽公共层)
88 lines
2.5 KiB
TypeScript
88 lines
2.5 KiB
TypeScript
import { httpFetch } from '../common/request.ts'
|
|
import musicSearch from './musicSearch.ts'
|
|
import { formatSinger } from './util.ts'
|
|
import leaderboard from './leaderboard.ts'
|
|
import lyric from './lyric.ts'
|
|
import pic from './pic.ts'
|
|
import kwApi from '../apis/kw.ts'
|
|
import songList from './songList.ts'
|
|
import hotSearch from './hotSearch.ts'
|
|
import comment from './comment.ts'
|
|
import album from './album.ts'
|
|
import playlist from './playlist.ts'
|
|
import parse from './parse.ts'
|
|
import type { HttpRequestObject } from '../types.ts'
|
|
|
|
const kw = {
|
|
_musicInfoRequestObj: null as HttpRequestObject | null,
|
|
_musicInfoPromiseCancelFn: null,
|
|
_musicPicRequestObj: null as HttpRequestObject | null,
|
|
_musicPicPromiseCancelFn: null,
|
|
album,
|
|
playlist,
|
|
parse,
|
|
|
|
musicSearch,
|
|
leaderboard,
|
|
songList,
|
|
hotSearch,
|
|
comment,
|
|
getLyric(songInfo, isGetLyricx) {
|
|
// let singer = songInfo.singer.indexOf('、') > -1 ? songInfo.singer.split('、')[0] : songInfo.singer
|
|
return lyric.getLyric(songInfo, isGetLyricx)
|
|
},
|
|
handleMusicInfo(songInfo) {
|
|
return this.getMusicInfo(songInfo).then(info => {
|
|
songInfo.name = info.name
|
|
songInfo.singer = formatSinger(info.artist)
|
|
songInfo.img = info.pic
|
|
songInfo.albumName = info.album
|
|
return songInfo
|
|
// return Object.assign({}, songInfo, {
|
|
// name: info.name,
|
|
// singer: formatSinger(info.artist),
|
|
// img: info.pic,
|
|
// albumName: info.album,
|
|
// })
|
|
})
|
|
},
|
|
|
|
getMusicUrl(songInfo, type) {
|
|
return kwApi.getMusicUrl(songInfo, type)
|
|
},
|
|
|
|
getMusicInfo(songInfo) {
|
|
if (this._musicInfoRequestObj) this._musicInfoRequestObj.cancelHttp()
|
|
this._musicInfoRequestObj = httpFetch(`http://www.kuwo.cn/api/www/music/musicInfo?mid=${songInfo.songmid}`)
|
|
return this._musicInfoRequestObj!.promise.then(({ body }) => {
|
|
return body.code === 200 ? body.data : Promise.reject(new Error(body.msg))
|
|
})
|
|
},
|
|
|
|
getMusicUrls(musicInfo, cb) {
|
|
let tasks: Array<Promise<any>> = []
|
|
let songId = musicInfo.songmid
|
|
musicInfo.types.forEach(type => {
|
|
tasks.push(kw.getMusicUrl(songId, type.type).promise)
|
|
})
|
|
Promise.all(tasks).then(urlInfo => {
|
|
let typeUrl = {}
|
|
urlInfo.forEach(info => {
|
|
typeUrl[info.type] = info.url
|
|
})
|
|
cb(typeUrl)
|
|
})
|
|
},
|
|
|
|
getPic(songInfo) {
|
|
return pic.getPic(songInfo)
|
|
},
|
|
|
|
getMusicDetailPageUrl(songInfo) {
|
|
return `http://www.kuwo.cn/play_detail/${songInfo.songmid}`
|
|
},
|
|
|
|
}
|
|
|
|
export default kw
|