预留歌手API (#1407)
* 更新歌手API --------- Co-authored-by: lyswhut <lyswhut@qq.com> Co-authored-by: 彭狸花喵 <helloplhm-qwq@outlook.com>
This commit is contained in:
co-authored by
lyswhut
彭狸花喵
parent
6403b8ce38
commit
94403be9a8
@@ -1,59 +1,85 @@
|
||||
import { httpFetch } from '../../request'
|
||||
// import { decodeName, formatPlayTime, sizeFormate } from '../../index'
|
||||
// import { signatureParams } from './util'
|
||||
import { getMusicInfosByList } from './musicInfo'
|
||||
import { createHttpFetch } from './util'
|
||||
|
||||
export default {
|
||||
filterAlbum(rawList) {
|
||||
let returnList = []
|
||||
rawList.forEach((albumInfo) => {
|
||||
returnList.push({
|
||||
name: albumInfo.albumname,
|
||||
author: albumInfo.singername,
|
||||
img: albumInfo.replaceAll('{size}', '480'),
|
||||
album_id: albumInfo.albumid,
|
||||
})
|
||||
/**
|
||||
* 获取歌手信息
|
||||
* @param {*} id
|
||||
*/
|
||||
getInfo(id) {
|
||||
if (id == 0) throw new Error('歌手不存在') // kg源某些歌曲在歌手没被kg收录时返回的歌手id为0
|
||||
return createHttpFetch(`http://mobiles.kugou.com/api/v5/singer/info?singerid=${id}`).then(body => {
|
||||
if (!body) throw new Error('get singer info faild.')
|
||||
|
||||
return {
|
||||
source: 'kg',
|
||||
id: body.singerid,
|
||||
info: {
|
||||
name: body.singername,
|
||||
desc: body.intro,
|
||||
avatar: body.imgurl.replace('{size}', 480),
|
||||
gender: body.grade === 1 ? 'man' : 'woman',
|
||||
},
|
||||
count: {
|
||||
music: body.songcount,
|
||||
album: body.albumcount,
|
||||
},
|
||||
}
|
||||
})
|
||||
},
|
||||
async getSingerInfo(singerid) {
|
||||
if (singerid == 0) throw new Error('歌手不存在') // kg源某些歌曲在歌手没被kg收录时返回的歌手id为0
|
||||
const requestObj = httpFetch(`http://mobiles.kugou.com/api/v5/singer/info?singerid=${singerid}`)
|
||||
let { body, statusCode } = await requestObj.promise
|
||||
if (statusCode !== 200) throw new Error('获取歌手信息失败')
|
||||
/**
|
||||
* 获取歌手专辑列表
|
||||
* @param {*} id
|
||||
* @param {*} page
|
||||
* @param {*} limit
|
||||
*/
|
||||
getAlbumList(id, page = 1, limit = 10) {
|
||||
if (id == 0) throw new Error('歌手不存在')
|
||||
return createHttpFetch(`http://mobiles.kugou.com/api/v5/singer/album?singerid=${id}&page=${page}&pagesize=${limit}`).then(body => {
|
||||
if (!body.info) throw new Error('get singer album list faild.')
|
||||
|
||||
const list = this.filterAlbumList(body.info)
|
||||
return {
|
||||
source: 'kg',
|
||||
list,
|
||||
limit,
|
||||
page,
|
||||
total: body.total,
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 获取歌手歌曲列表
|
||||
* @param {*} id
|
||||
* @param {*} page
|
||||
* @param {*} limit
|
||||
*/
|
||||
async getSongList(id, page = 1, limit = 100) {
|
||||
if (id == 0) throw new Error('歌手不存在')
|
||||
const body = await createHttpFetch(`http://mobiles.kugou.com/api/v5/singer/song?singerid=${id}&page=${page}&pagesize=${limit}`)
|
||||
if (!body.info) throw new Error('get singer song list faild.')
|
||||
|
||||
const list = await getMusicInfosByList(body.info)
|
||||
return {
|
||||
source: 'kg',
|
||||
singerid,
|
||||
info: {
|
||||
name: body.data.singername,
|
||||
desc: body.data.intro,
|
||||
img: body.data.imgurl.replace('{size}', '480'),
|
||||
},
|
||||
list,
|
||||
limit,
|
||||
page,
|
||||
total: body.total,
|
||||
}
|
||||
},
|
||||
async getSingerSongList(singerid, page, limit) {
|
||||
if (singerid == 0) throw new Error('歌手不存在') // kg源某些歌曲在歌手没被kg收录时返回的歌手id为0
|
||||
const requestObj = httpFetch(`http://mobiles.kugou.com/api/v5/singer/song?singerid=${singerid}&page=${page}&pagesize=${limit}`)
|
||||
let { body, statusCode } = await requestObj.promise
|
||||
if (statusCode !== 200) throw new Error('获取歌手歌曲列表失败')
|
||||
let listData = await getMusicInfosByList(body.data.info)
|
||||
return {
|
||||
source: 'kg',
|
||||
list: listData,
|
||||
id: `kg__singer_${singerid}`,
|
||||
singerid,
|
||||
total: body.data.total,
|
||||
allPage: Math.ceil(body.data.total / limit),
|
||||
}
|
||||
},
|
||||
async getSingerAlbumList(singerid, page, limit) {
|
||||
if (singerid == 0) throw new Error('歌手不存在') // kg源某些歌曲在歌手没被kg收录时返回的歌手id为0
|
||||
const requestObj = httpFetch(`http://mobiles.kugou.com/api/v5/singer/song?singerid=${singerid}&page=${page}&pagesize=${limit}`)
|
||||
let { body, statusCode } = await requestObj.promise
|
||||
if (statusCode !== 200) throw new Error('获取歌手专辑列表失败')
|
||||
return {
|
||||
source: 'kg',
|
||||
albums: this.filterAlbum(body.data.info),
|
||||
singerid,
|
||||
}
|
||||
filterAlbumList(raw) {
|
||||
return raw.map(item => {
|
||||
return {
|
||||
id: item.albumid,
|
||||
count: item.songcount,
|
||||
info: {
|
||||
name: item.albumname,
|
||||
author: item.singername,
|
||||
img: item.replaceAll('{size}', '480'),
|
||||
desc: item.intro,
|
||||
},
|
||||
}
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user