feat(api): 新增歌手与专辑接口,修复各平台死代码中的多处隐藏 bug
This commit is contained in:
1 parent
d142dd6096
commit
23c7ad91e4
14 files changed
+317
-115
No files matched your search
@@ -6,6 +6,8 @@ import pic from './pic.ts'
|
||||
import lyric from './lyric.ts'
|
||||
import hotSearch from './hotSearch.ts'
|
||||
import comment from './comment.ts'
|
||||
import singer from './singer.ts'
|
||||
import album from './album.ts'
|
||||
// import tipSearch from './tipSearch.js'
|
||||
|
||||
const kg = {
|
||||
@@ -15,6 +17,8 @@ const kg = {
|
||||
musicSearch,
|
||||
hotSearch,
|
||||
comment,
|
||||
singer,
|
||||
album,
|
||||
getMusicUrl(songInfo, type) {
|
||||
return apis('kg').getMusicUrl!(songInfo, type)
|
||||
},
|
||||
|
||||
@@ -76,7 +76,7 @@ export default {
|
||||
info: {
|
||||
name: item.albumname,
|
||||
author: item.singername,
|
||||
img: item.replaceAll('{size}', '480'),
|
||||
img: String(item.imgurl || item.img || '').replace('{size}', '480'),
|
||||
desc: item.intro,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -29,23 +29,21 @@ export default {
|
||||
play_count: listInfo.play_count,
|
||||
},
|
||||
}
|
||||
},
|
||||
/**
|
||||
}, /**
|
||||
* 通过AlbumId获取专辑信息
|
||||
* @param {*} id
|
||||
* @param {*} page
|
||||
*/
|
||||
async getAlbumInfo(id) {
|
||||
const info = await createHttpFetch(`https://app.c.nf.migu.cn/MIGUM3.0/resource/album/v2.0?albumId=${id}`)
|
||||
if (!info) return Promise.reject(new Error('Get album info error.'))
|
||||
|
||||
return {
|
||||
name: info.title,
|
||||
image: info.imgItems.length ? info.imgItems[0].img : null,
|
||||
desc: info.summary,
|
||||
author: info.singer,
|
||||
play_count: formatPlayCount(info.opNumItem.playNum),
|
||||
total: info.totalCount,
|
||||
name: info.title ?? null,
|
||||
image: info.imgItems?.length ? info.imgItems[0].img : null,
|
||||
desc: info.summary ?? null,
|
||||
author: info.singer ?? null,
|
||||
play_count: formatPlayCount(info.opNumItem?.playNum ?? 0),
|
||||
total: parseInt(info.totalCount) || null,
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import pic from './pic.ts'
|
||||
import lyric from './lyric.ts'
|
||||
import hotSearch from './hotSearch.ts'
|
||||
import comment from './comment.ts'
|
||||
import album from './album.js'
|
||||
// import tipSearch from './tipSearch.ts'
|
||||
|
||||
const mg = {
|
||||
@@ -15,6 +16,7 @@ const mg = {
|
||||
leaderboard,
|
||||
hotSearch,
|
||||
comment,
|
||||
album,
|
||||
getMusicUrl(songInfo, type) {
|
||||
return apis('mg').getMusicUrl!(songInfo, type)
|
||||
},
|
||||
|
||||
@@ -5,6 +5,7 @@ import musicSearch from './musicSearch.ts'
|
||||
import { apis } from '../api-source.ts'
|
||||
import hotSearch from './hotSearch.ts'
|
||||
import comment from './comment.ts'
|
||||
import singer from './singer.ts'
|
||||
// import tipSearch from './tipSearch.ts'
|
||||
|
||||
const tx = {
|
||||
@@ -14,6 +15,7 @@ const tx = {
|
||||
musicSearch,
|
||||
hotSearch,
|
||||
comment,
|
||||
singer,
|
||||
|
||||
getMusicUrl(songInfo, type) {
|
||||
return apis('tx')!.getMusicUrl(songInfo, type)
|
||||
|
||||
+43
-85
@@ -61,38 +61,30 @@ export const filterMusicInfoItem = item => {
|
||||
|
||||
|
||||
/**
|
||||
* 创建一个适用于TX的Http请求
|
||||
* @param {*} url
|
||||
* @param {*} options
|
||||
* @param {*} retryNum
|
||||
* musicu.fcg 通用请求(comm 参数对齐榜单模块的可用配置)。
|
||||
* 注意:musichallSinger.GetSingerDetail 等歌手详情接口在该通道已停用(104403),
|
||||
* 歌手名/统计改由歌单与专辑接口合成。
|
||||
*/
|
||||
const createMusicuFetch = async(data, options?, retryNum = 0) => {
|
||||
const createMusicuFetch = async(data, retryNum = 0) => {
|
||||
if (retryNum > 2) throw new Error('try max num')
|
||||
|
||||
let result
|
||||
try {
|
||||
result = await httpFetch('https://u.y.qq.com/cgi-bin/musicu.fcg', {
|
||||
method: 'POST',
|
||||
body: {
|
||||
comm: {
|
||||
cv: 4747474,
|
||||
ct: 24,
|
||||
format: 'json',
|
||||
inCharset: 'utf-8',
|
||||
outCharset: 'utf-8',
|
||||
uin: 0,
|
||||
},
|
||||
...data,
|
||||
},
|
||||
method: 'post',
|
||||
headers: {
|
||||
'User-Angent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
|
||||
'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
|
||||
},
|
||||
body: {
|
||||
comm: { uin: 0, format: 'json', ct: 20, cv: 1859 },
|
||||
...data,
|
||||
},
|
||||
}).promise
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return createMusicuFetch(data, options, ++retryNum)
|
||||
return createMusicuFetch(data, ++retryNum)
|
||||
}
|
||||
if (result.statusCode !== 200 || result.body.code != 0) return createMusicuFetch(data, options, ++retryNum)
|
||||
if (result.statusCode !== 200 || result.body.code != 0) return createMusicuFetch(data, ++retryNum)
|
||||
|
||||
return result.body
|
||||
}
|
||||
@@ -103,59 +95,28 @@ export default {
|
||||
* @param {*} id
|
||||
*/
|
||||
getInfo(id) {
|
||||
return createMusicuFetch({
|
||||
req_1: {
|
||||
module: 'music.musichallSinger.SingerInfoInter',
|
||||
method: 'GetSingerDetail',
|
||||
param: {
|
||||
singer_mid: [id],
|
||||
ex_singer: 1,
|
||||
wiki_singer: 1,
|
||||
group_singer: 0,
|
||||
pic: 1,
|
||||
photos: 0,
|
||||
},
|
||||
},
|
||||
req_2: {
|
||||
module: 'music.musichallAlbum.AlbumListServer',
|
||||
method: 'GetAlbumList',
|
||||
param: {
|
||||
singerMid: id,
|
||||
order: 0,
|
||||
begin: 0,
|
||||
num: 1,
|
||||
songNumTag: 0,
|
||||
singerID: 0,
|
||||
},
|
||||
},
|
||||
req_3: {
|
||||
module: 'musichall.song_list_server',
|
||||
method: 'GetSingerSongList',
|
||||
param: {
|
||||
singerMid: id,
|
||||
order: 1,
|
||||
begin: 0,
|
||||
num: 1,
|
||||
},
|
||||
},
|
||||
}).then(body => {
|
||||
if (body.req_1.code != 0 || body.req_2 != 0 || body.req_3 != 0) throw new Error('get singer info faild.')
|
||||
|
||||
const info = body.req_1.data.singer_list[0]
|
||||
const music = body.req_3.data
|
||||
const album = body.req_3.data
|
||||
return Promise.all([
|
||||
createMusicuFetch({ req: { module: 'musichall.song_list_server', method: 'GetSingerSongList', param: { singerMid: id, order: 1, begin: 0, num: 1 } } }),
|
||||
createMusicuFetch({ req: { module: 'music.musichallAlbum.AlbumListServer', method: 'GetAlbumList', param: { singerMid: id, order: 0, begin: 0, num: 1, songNumTag: 0, singerID: 0 } } }),
|
||||
]).then(([songBody, albumBody]) => {
|
||||
if (songBody.req.code != 0 || albumBody.req.code != 0) throw new Error('get singer info faild.')
|
||||
const songData = songBody.req.data
|
||||
const albumData = albumBody.req.data
|
||||
// 详情接口停用:歌手名从歌曲条目反查,头像用平台的固定图片 URL 规则
|
||||
const singers = songData.songList?.[0]?.songInfo?.singer ?? []
|
||||
const self = singers.find(s => s.mid === id) ?? singers[0]
|
||||
return {
|
||||
source: 'tx',
|
||||
id: info.basic_info.singer_mid,
|
||||
id,
|
||||
info: {
|
||||
name: info.basic_info.name,
|
||||
desc: info.ex_info.desc,
|
||||
avatar: info.pic.pic,
|
||||
gender: info.ex_info.genre === 1 ? 'man' : 'woman',
|
||||
name: self?.name ?? '',
|
||||
desc: null,
|
||||
avatar: `https://y.gtimg.cn/music/photo_new/T001R500x500M000${id}.jpg`,
|
||||
gender: null,
|
||||
},
|
||||
count: {
|
||||
music: music.totalNum,
|
||||
album: album.total,
|
||||
music: songData.totalNum,
|
||||
album: albumData.total,
|
||||
},
|
||||
}
|
||||
})
|
||||
@@ -167,7 +128,6 @@ export default {
|
||||
* @param {*} limit
|
||||
*/
|
||||
getAlbumList(id, page = 1, limit = 10) {
|
||||
if (page === 1) page = 0
|
||||
return createMusicuFetch({
|
||||
req: {
|
||||
module: 'music.musichallAlbum.AlbumListServer',
|
||||
@@ -175,7 +135,7 @@ export default {
|
||||
param: {
|
||||
singerMid: id,
|
||||
order: 0,
|
||||
begin: page * limit,
|
||||
begin: (page - 1) * limit,
|
||||
num: limit,
|
||||
songNumTag: 0,
|
||||
singerID: 0,
|
||||
@@ -201,30 +161,28 @@ export default {
|
||||
* @param {*} limit
|
||||
*/
|
||||
async getSongList(id, page = 1, limit = 100) {
|
||||
if (page === 1) page = 0
|
||||
return createMusicuFetch({
|
||||
const body = await createMusicuFetch({
|
||||
req: {
|
||||
module: 'musichall.song_list_server',
|
||||
method: 'GetSingerSongList',
|
||||
param: {
|
||||
singerMid: id,
|
||||
order: 1,
|
||||
begin: page * limit,
|
||||
begin: (page - 1) * limit,
|
||||
num: limit,
|
||||
},
|
||||
},
|
||||
}).then(body => {
|
||||
if (body.req.code != 0) throw new Error('get singer song list faild.')
|
||||
|
||||
const list = this.filterSongList(body.req.data.songList)
|
||||
return {
|
||||
source: 'tx',
|
||||
list,
|
||||
limit,
|
||||
page,
|
||||
total: body.req.data.totalNum,
|
||||
}
|
||||
})
|
||||
if (body.req.code != 0) throw new Error('get singer song list faild.')
|
||||
|
||||
const list = this.filterSongList(body.req.data.songList)
|
||||
return {
|
||||
source: 'tx',
|
||||
list,
|
||||
limit,
|
||||
page,
|
||||
total: body.req.data.totalNum,
|
||||
}
|
||||
},
|
||||
filterAlbumList(raw) {
|
||||
return raw.map(item => {
|
||||
@@ -242,7 +200,7 @@ export default {
|
||||
})
|
||||
},
|
||||
filterSongList(raw) {
|
||||
raw.map(item => {
|
||||
return raw.map(item => {
|
||||
return filterMusicInfoItem(item.songInfo)
|
||||
})
|
||||
},
|
||||
|
||||
@@ -6,6 +6,7 @@ import musicSearch from './musicSearch.ts'
|
||||
import songList from './songList.ts'
|
||||
import hotSearch from './hotSearch.ts'
|
||||
import comment from './comment.ts'
|
||||
import singer from './singer.ts'
|
||||
// import tipSearch from './tipSearch.js'
|
||||
|
||||
const wy = {
|
||||
@@ -15,6 +16,7 @@ const wy = {
|
||||
songList,
|
||||
hotSearch,
|
||||
comment,
|
||||
singer,
|
||||
getMusicUrl(songInfo, type) {
|
||||
return apis('wy').getMusicUrl!(songInfo, type)
|
||||
},
|
||||
|
||||
+22
-17
@@ -8,20 +8,23 @@ export default {
|
||||
* @param {*} id
|
||||
*/
|
||||
getInfo(id) {
|
||||
return (eapiRequest('/api/artist/head/info/get', { id }) as any).then(({ body }) => {
|
||||
return eapiRequest('/api/artist/head/info/get', { id }).promise.then(({ body }) => {
|
||||
if (!body || body.code != 200) throw new Error('get singer info faild.')
|
||||
// 响应结构为 { code, data: { artist: { ... } } },无 body.user
|
||||
const artist = body.data?.artist
|
||||
if (!artist) throw new Error('get singer info faild.')
|
||||
return {
|
||||
source: 'wy',
|
||||
id: body.artist.id,
|
||||
id: artist.id,
|
||||
info: {
|
||||
name: body.artist.name,
|
||||
desc: body.artist.briefDesc,
|
||||
avatar: body.user.avatarUrl,
|
||||
gender: body.user.gender === 1 ? 'man' : 'woman',
|
||||
name: artist.name,
|
||||
desc: artist.briefDesc,
|
||||
avatar: artist.avatar ?? artist.cover ?? null,
|
||||
gender: null,
|
||||
},
|
||||
count: {
|
||||
music: body.artist.musicSize,
|
||||
album: body.artist.albumSize,
|
||||
music: artist.musicSize,
|
||||
album: artist.albumSize,
|
||||
},
|
||||
}
|
||||
})
|
||||
@@ -33,12 +36,11 @@ export default {
|
||||
* @param {*} limit
|
||||
*/
|
||||
getSongList(id, page = 1, limit = 100) {
|
||||
if (page === 1) page = 0
|
||||
return (eapiRequest('/api/v2/artist/songs', {
|
||||
return eapiRequest('/api/v2/artist/songs', {
|
||||
id,
|
||||
limit,
|
||||
offset: limit * page,
|
||||
}) as any).then(({ body }) => {
|
||||
offset: (page - 1) * limit,
|
||||
}).promise.then(({ body }) => {
|
||||
if (!body.songs || body.code != 200) throw new Error('get singer song list faild.')
|
||||
|
||||
const list = this.filterSongList(body.songs)
|
||||
@@ -58,11 +60,10 @@ export default {
|
||||
* @param {*} limit
|
||||
*/
|
||||
getAlbumList(id, page = 1, limit = 10) {
|
||||
if (page === 1) page = 0
|
||||
return (eapiRequest(`/api/artist/albums/${id}`, {
|
||||
return eapiRequest(`/api/artist/albums/${id}`, {
|
||||
limit,
|
||||
offset: limit * page,
|
||||
}) as any).then(({ body }) => {
|
||||
offset: (page - 1) * limit,
|
||||
}).promise.then(({ body }) => {
|
||||
if (!body.hotAlbums || body.code != 200) throw new Error('get singer album list faild.')
|
||||
|
||||
const list = this.filterAlbumList(body.hotAlbums)
|
||||
@@ -108,24 +109,28 @@ export default {
|
||||
_types['128k'] = {
|
||||
size,
|
||||
}
|
||||
break
|
||||
case 320000:
|
||||
size = item.hMusic ? sizeFormate(item.hMusic.size) : null
|
||||
types.push({ type: '320k', size })
|
||||
_types['320k'] = {
|
||||
size,
|
||||
}
|
||||
break
|
||||
case 999000:
|
||||
size = item.sqMusic ? sizeFormate(item.sqMusic.size) : null
|
||||
types.push({ type: 'flac', size })
|
||||
_types.flac = {
|
||||
size,
|
||||
}
|
||||
break
|
||||
case 1999000:
|
||||
size = item.hrMusic ? sizeFormate(item.hrMusic.size) : null
|
||||
types.push({ type: 'flac24bit', size })
|
||||
_types.flac24bit = {
|
||||
size,
|
||||
}
|
||||
break
|
||||
}
|
||||
})
|
||||
|
||||
@@ -136,7 +141,7 @@ export default {
|
||||
albumId: item.album.id,
|
||||
songmid: item.id,
|
||||
source: 'wy',
|
||||
interval: formatPlayTime(item.duration),
|
||||
interval: formatPlayTime((item.dt ?? item.duration) / 1000),
|
||||
img: null,
|
||||
lrc: null,
|
||||
otherSource: null,
|
||||
|
||||
Reference in new issue
Block a user