refactor(sdk): musicSdk 全量迁移至 TypeScript

This commit is contained in:
snowy-yang committed 2026-08-29 00:23:50 +08:00
1 parent f289df4cd7
commit 1dfb7a59ca
83 files changed
+924 -732

No files matched your search

+150
View File
@@ -0,0 +1,150 @@
import { eapiRequest } from './utils/index.ts'
import { formatPlayTime, sizeFormate } from '../index.ts'
import { formatSingerName } from '../utils.ts'
export default {
/**
* 获取歌手信息
* @param {*} id
*/
getInfo(id) {
return (eapiRequest('/api/artist/head/info/get', { id }) as any).then(({ body }) => {
if (!body || body.code != 200) throw new Error('get singer info faild.')
return {
source: 'wy',
id: body.artist.id,
info: {
name: body.artist.name,
desc: body.artist.briefDesc,
avatar: body.user.avatarUrl,
gender: body.user.gender === 1 ? 'man' : 'woman',
},
count: {
music: body.artist.musicSize,
album: body.artist.albumSize,
},
}
})
},
/**
* 获取歌手歌曲列表
* @param {*} id
* @param {*} page
* @param {*} limit
*/
getSongList(id, page = 1, limit = 100) {
if (page === 1) page = 0
return (eapiRequest('/api/v2/artist/songs', {
id,
limit,
offset: limit * page,
}) as any).then(({ body }) => {
if (!body.songs || body.code != 200) throw new Error('get singer song list faild.')
const list = this.filterSongList(body.songs)
return {
list,
limit,
page,
total: body.total,
source: 'wy',
}
})
},
/**
* 获取歌手专辑列表
* @param {*} id
* @param {*} page
* @param {*} limit
*/
getAlbumList(id, page = 1, limit = 10) {
if (page === 1) page = 0
return (eapiRequest(`/api/artist/albums/${id}`, {
limit,
offset: limit * page,
}) as any).then(({ body }) => {
if (!body.hotAlbums || body.code != 200) throw new Error('get singer album list faild.')
const list = this.filterAlbumList(body.hotAlbums)
return {
source: 'wy',
list,
limit,
page,
total: body.artist.albumSize,
}
})
},
filterAlbumList(raw) {
const list: any[] = []
raw.forEach(item => {
if (!item.id) return
list.push({
id: item.id,
count: item.size,
info: {
name: item.name,
author: formatSingerName(item.artists),
img: item.picUrl,
desc: null,
},
})
})
return list
},
filterSongList(raw) {
const list: any[] = []
raw.forEach(item => {
if (!item.id) return
const types: Array<{ type: string, size: string | null }> = []
const _types: Record<string, { size: string | null }> = {}
let size
item.privilege.chargeInfoList.forEach(i => {
switch (i.rate) {
case 128000:
size = item.lMusic ? sizeFormate(item.lMusic.size) : null
types.push({ type: '128k', size })
_types['128k'] = {
size,
}
case 320000:
size = item.hMusic ? sizeFormate(item.hMusic.size) : null
types.push({ type: '320k', size })
_types['320k'] = {
size,
}
case 999000:
size = item.sqMusic ? sizeFormate(item.sqMusic.size) : null
types.push({ type: 'flac', size })
_types.flac = {
size,
}
case 1999000:
size = item.hrMusic ? sizeFormate(item.hrMusic.size) : null
types.push({ type: 'flac24bit', size })
_types.flac24bit = {
size,
}
}
})
list.push({
singer: formatSingerName(item.artists),
name: item.name,
albumName: item.album.name,
albumId: item.album.id,
songmid: item.id,
source: 'wy',
interval: formatPlayTime(item.duration),
img: null,
lrc: null,
otherSource: null,
types,
_types,
typeUrl: {},
})
})
return list
},
}