预留tx歌手API & 优化代码
This commit is contained in:
parent
5d2bfd5beb
commit
f0ece1d9d7
@ -18,7 +18,7 @@ export default {
|
|||||||
name: body.singername,
|
name: body.singername,
|
||||||
desc: body.intro,
|
desc: body.intro,
|
||||||
avatar: body.imgurl.replace('{size}', 480),
|
avatar: body.imgurl.replace('{size}', 480),
|
||||||
gender: body.grade === 1 ? '1' : '2',
|
gender: body.grade === 1 ? 'man' : 'woman',
|
||||||
},
|
},
|
||||||
count: {
|
count: {
|
||||||
music: body.songcount,
|
music: body.songcount,
|
||||||
@ -33,10 +33,10 @@ export default {
|
|||||||
* @param {*} page
|
* @param {*} page
|
||||||
* @param {*} limit
|
* @param {*} limit
|
||||||
*/
|
*/
|
||||||
getAlbumList(id, page, limit) {
|
getAlbumList(id, page = 1, limit = 10) {
|
||||||
if (id == 0) throw new Error('歌手不存在')
|
if (id == 0) throw new Error('歌手不存在')
|
||||||
return createHttpFetch(`http://mobiles.kugou.com/api/v5/singer/album?singerid=${id}&page=${page}&pagesize=${limit}`).then(body => {
|
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 faild.')
|
if (!body.info) throw new Error('get singer album list faild.')
|
||||||
|
|
||||||
const list = this.filterAlbumList(body.info)
|
const list = this.filterAlbumList(body.info)
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../request'
|
||||||
import { formatPlayTime, sizeFormate } from '../../index'
|
import { formatPlayTime, sizeFormate } from '../../index'
|
||||||
import { formatSingerName } from '../utils'
|
import { formatSingerName, formatSingerList } from '../utils'
|
||||||
import { formatSingerList } from './util'
|
|
||||||
|
|
||||||
let boardList = [{ id: 'tx__4', name: '流行指数榜', bangid: '4' }, { id: 'tx__26', name: '热歌榜', bangid: '26' }, { id: 'tx__27', name: '新歌榜', bangid: '27' }, { id: 'tx__62', name: '飙升榜', bangid: '62' }, { id: 'tx__58', name: '说唱榜', bangid: '58' }, { id: 'tx__57', name: '喜力电音榜', bangid: '57' }, { id: 'tx__28', name: '网络歌曲榜', bangid: '28' }, { id: 'tx__5', name: '内地榜', bangid: '5' }, { id: 'tx__3', name: '欧美榜', bangid: '3' }, { id: 'tx__59', name: '香港地区榜', bangid: '59' }, { id: 'tx__16', name: '韩国榜', bangid: '16' }, { id: 'tx__60', name: '抖快榜', bangid: '60' }, { id: 'tx__29', name: '影视金曲榜', bangid: '29' }, { id: 'tx__17', name: '日本榜', bangid: '17' }, { id: 'tx__52', name: '腾讯音乐人原创榜', bangid: '52' }, { id: 'tx__36', name: 'K歌金曲榜', bangid: '36' }, { id: 'tx__61', name: '台湾地区榜', bangid: '61' }, { id: 'tx__63', name: 'DJ舞曲榜', bangid: '63' }, { id: 'tx__64', name: '综艺新歌榜', bangid: '64' }, { id: 'tx__65', name: '国风热歌榜', bangid: '65' }, { id: 'tx__67', name: '听歌识曲榜', bangid: '67' }, { id: 'tx__72', name: '动漫音乐榜', bangid: '72' }, { id: 'tx__73', name: '游戏音乐榜', bangid: '73' }, { id: 'tx__75', name: '有声榜', bangid: '75' }, { id: 'tx__131', name: '校园音乐人排行榜', bangid: '131' }]
|
let boardList = [{ id: 'tx__4', name: '流行指数榜', bangid: '4' }, { id: 'tx__26', name: '热歌榜', bangid: '26' }, { id: 'tx__27', name: '新歌榜', bangid: '27' }, { id: 'tx__62', name: '飙升榜', bangid: '62' }, { id: 'tx__58', name: '说唱榜', bangid: '58' }, { id: 'tx__57', name: '喜力电音榜', bangid: '57' }, { id: 'tx__28', name: '网络歌曲榜', bangid: '28' }, { id: 'tx__5', name: '内地榜', bangid: '5' }, { id: 'tx__3', name: '欧美榜', bangid: '3' }, { id: 'tx__59', name: '香港地区榜', bangid: '59' }, { id: 'tx__16', name: '韩国榜', bangid: '16' }, { id: 'tx__60', name: '抖快榜', bangid: '60' }, { id: 'tx__29', name: '影视金曲榜', bangid: '29' }, { id: 'tx__17', name: '日本榜', bangid: '17' }, { id: 'tx__52', name: '腾讯音乐人原创榜', bangid: '52' }, { id: 'tx__36', name: 'K歌金曲榜', bangid: '36' }, { id: 'tx__61', name: '台湾地区榜', bangid: '61' }, { id: 'tx__63', name: 'DJ舞曲榜', bangid: '63' }, { id: 'tx__64', name: '综艺新歌榜', bangid: '64' }, { id: 'tx__65', name: '国风热歌榜', bangid: '65' }, { id: 'tx__67', name: '听歌识曲榜', bangid: '67' }, { id: 'tx__72', name: '动漫音乐榜', bangid: '72' }, { id: 'tx__73', name: '游戏音乐榜', bangid: '73' }, { id: 'tx__75', name: '有声榜', bangid: '75' }, { id: 'tx__131', name: '校园音乐人排行榜', bangid: '131' }]
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../request'
|
||||||
import getMusicInfo from './musicInfo'
|
import { getMusicInfo } from './musicInfo'
|
||||||
import { rendererInvoke } from '@common/rendererIpc'
|
import { rendererInvoke } from '@common/rendererIpc'
|
||||||
import { WIN_MAIN_RENDERER_EVENT_NAME } from '@common/ipcNames'
|
import { WIN_MAIN_RENDERER_EVENT_NAME } from '@common/ipcNames'
|
||||||
|
|
||||||
|
|||||||
@ -1,98 +1,77 @@
|
|||||||
import { httpFetch } from '../../request'
|
|
||||||
import { formatPlayTime, sizeFormate } from '../../index'
|
import { formatPlayTime, sizeFormate } from '../../index'
|
||||||
|
import { formatSingerName, formatSingerList } from '../utils'
|
||||||
|
import { createMusicuFetch } from './util'
|
||||||
|
|
||||||
const getSinger = (singers) => {
|
export const filterMusicInfoItem = (item) => {
|
||||||
let arr = []
|
const types = []
|
||||||
singers.forEach(singer => {
|
const _types = {}
|
||||||
arr.push(singer.name)
|
if (item.file.size_128mp3 != 0) {
|
||||||
})
|
let size = sizeFormate(item.file.size_128mp3)
|
||||||
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('获取歌曲信息失败')
|
|
||||||
const item = body.req.data.track_info
|
|
||||||
if (!item.file?.media_mid) return null
|
|
||||||
|
|
||||||
let types = []
|
|
||||||
let _types = {}
|
|
||||||
const file = item.file
|
|
||||||
if (file.size_128mp3 != 0) {
|
|
||||||
let size = sizeFormate(file.size_128mp3)
|
|
||||||
types.push({ type: '128k', size })
|
types.push({ type: '128k', size })
|
||||||
_types['128k'] = {
|
_types['128k'] = {
|
||||||
size,
|
size,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (file.size_320mp3 !== 0) {
|
if (item.file.size_320mp3 !== 0) {
|
||||||
let size = sizeFormate(file.size_320mp3)
|
let size = sizeFormate(item.file.size_320mp3)
|
||||||
types.push({ type: '320k', size })
|
types.push({ type: '320k', size })
|
||||||
_types['320k'] = {
|
_types['320k'] = {
|
||||||
size,
|
size,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (file.size_flac !== 0) {
|
if (item.file.size_flac !== 0) {
|
||||||
let size = sizeFormate(file.size_flac)
|
let size = sizeFormate(item.file.size_flac)
|
||||||
types.push({ type: 'flac', size })
|
types.push({ type: 'flac', size })
|
||||||
_types.flac = {
|
_types.flac = {
|
||||||
size,
|
size,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (file.size_hires !== 0) {
|
if (item.file.size_hires !== 0) {
|
||||||
let size = sizeFormate(file.size_hires)
|
let size = sizeFormate(item.file.size_hires)
|
||||||
types.push({ type: 'flac24bit', size })
|
types.push({ type: 'flac24bit', size })
|
||||||
_types.flac24bit = {
|
_types.flac24bit = {
|
||||||
size,
|
size,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// types.reverse()
|
|
||||||
let albumId = ''
|
const albumId = item.album.id ?? ''
|
||||||
let albumName = ''
|
const albumMid = item.album.mid ?? ''
|
||||||
if (item.album) {
|
const albumName = item.album.name ?? ''
|
||||||
albumName = item.album.name
|
|
||||||
albumId = item.album.mid
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
singer: getSinger(item.singer),
|
source: 'tx',
|
||||||
|
singer: formatSingerName(item.singer, 'name'),
|
||||||
|
singerList: formatSingerList(item.singer),
|
||||||
name: item.name,
|
name: item.name,
|
||||||
albumName,
|
albumName,
|
||||||
albumId,
|
albumId,
|
||||||
source: 'tx',
|
albumMid,
|
||||||
interval: formatPlayTime(item.interval),
|
interval: formatPlayTime(item.interval),
|
||||||
songId: item.id,
|
songId: item.id,
|
||||||
albumMid: item.album?.mid ?? '',
|
|
||||||
strMediaMid: item.file.media_mid,
|
|
||||||
songmid: item.mid,
|
songmid: item.mid,
|
||||||
|
strMediaMid: item.file.media_mid,
|
||||||
img: (albumId === '' || albumId === '空')
|
img: (albumId === '' || albumId === '空')
|
||||||
? item.singer?.length ? `https://y.gtimg.cn/music/photo_new/T001R500x500M000${item.singer[0].mid}.jpg` : ''
|
? 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`,
|
: `https://y.gtimg.cn/music/photo_new/T002R500x500M000${albumMid}.jpg`,
|
||||||
types,
|
types,
|
||||||
_types,
|
_types,
|
||||||
typeUrl: {},
|
typeUrl: {},
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getMusicInfo = (id) => {
|
||||||
|
return createMusicuFetch({
|
||||||
|
module: 'music.pf_song_detail_svr',
|
||||||
|
method: 'get_song_detail_yqq',
|
||||||
|
param: {
|
||||||
|
song_type: 0,
|
||||||
|
song_mid: id,
|
||||||
|
},
|
||||||
|
}).then(body => {
|
||||||
|
if (!body) throw new Error('get music info faild.')
|
||||||
|
|
||||||
|
const item = body.track_info
|
||||||
|
if (!item.file?.media_mid) return null
|
||||||
|
|
||||||
|
return filterMusicInfoItem(item)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../request'
|
||||||
import { formatPlayTime, sizeFormate } from '../../index'
|
import { filterMusicInfoItem } from './musicInfo'
|
||||||
import { formatSingerName } from '../utils'
|
|
||||||
import { formatSingerList } from './util'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
limit: 50,
|
limit: 50,
|
||||||
@ -51,68 +49,10 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
handleResult(rawList) {
|
handleResult(rawList) {
|
||||||
// console.log(rawList)
|
|
||||||
const list = []
|
const list = []
|
||||||
rawList.forEach(item => {
|
rawList.forEach(item => {
|
||||||
if (!item.file?.media_mid) return
|
if (!item.file?.media_mid) return
|
||||||
|
list.push(filterMusicInfoItem(item))
|
||||||
let types = []
|
|
||||||
let _types = {}
|
|
||||||
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
|
|
||||||
}
|
|
||||||
list.push({
|
|
||||||
singer: formatSingerName(item.singer, 'name'),
|
|
||||||
singerList: formatSingerList(item.singer),
|
|
||||||
name: item.name,
|
|
||||||
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: {},
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
// console.log(list)
|
// console.log(list)
|
||||||
return list
|
return list
|
||||||
|
|||||||
152
src/renderer/utils/musicSdk/tx/singer.js
Normal file
152
src/renderer/utils/musicSdk/tx/singer.js
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
import { createMusicuFetch, createMusicuFetchs } from './util'
|
||||||
|
import { filterMusicInfo } from './musicInfo'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
/**
|
||||||
|
* 获取歌手信息
|
||||||
|
* @param {*} id
|
||||||
|
*/
|
||||||
|
getInfo(id) {
|
||||||
|
return createMusicuFetchs({
|
||||||
|
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: '0025NhlN2yWrP4',
|
||||||
|
order: 1,
|
||||||
|
begin: 0,
|
||||||
|
num: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}).then(body => {
|
||||||
|
if (body.req_1.code != 0 || body.req_2.code != 0 || body.req_3.code != 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 {
|
||||||
|
source: 'tx',
|
||||||
|
id: info.basic_info.singer_mid,
|
||||||
|
info: {
|
||||||
|
name: info.basic_info.name,
|
||||||
|
desc: info.ex_info.desc,
|
||||||
|
avatar: info.pic.pic,
|
||||||
|
gender: info.ex_info.genre === 1 ? 'man' : 'woman',
|
||||||
|
},
|
||||||
|
count: {
|
||||||
|
music: music.totalNum,
|
||||||
|
album: album.total,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 获取歌手专辑列表
|
||||||
|
* @param {*} id
|
||||||
|
* @param {*} page
|
||||||
|
* @param {*} limit
|
||||||
|
*/
|
||||||
|
getAlbumList(id, page = 1, limit = 10) {
|
||||||
|
if (page === 1) page = 0
|
||||||
|
return createMusicuFetch({
|
||||||
|
module: 'music.musichallAlbum.AlbumListServer',
|
||||||
|
method: 'GetAlbumList',
|
||||||
|
param: {
|
||||||
|
singerMid: id,
|
||||||
|
order: 0,
|
||||||
|
begin: page * limit,
|
||||||
|
num: limit,
|
||||||
|
songNumTag: 0,
|
||||||
|
singerID: 0,
|
||||||
|
},
|
||||||
|
}).then(body => {
|
||||||
|
if (!body.albumList) throw new Error('get singer album faild.')
|
||||||
|
|
||||||
|
const list = this.filterAlbumList(body.albumList)
|
||||||
|
return {
|
||||||
|
source: 'tx',
|
||||||
|
list,
|
||||||
|
limit,
|
||||||
|
page,
|
||||||
|
total: body.total,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 获取歌手歌曲列表
|
||||||
|
* @param {*} id
|
||||||
|
* @param {*} page
|
||||||
|
* @param {*} limit
|
||||||
|
*/
|
||||||
|
async getSongList(id, page = 1, limit = 100) {
|
||||||
|
if (page === 1) page = 0
|
||||||
|
return createMusicuFetch({
|
||||||
|
module: 'musichall.song_list_server',
|
||||||
|
method: 'GetSingerSongList',
|
||||||
|
param: {
|
||||||
|
singerMid: id,
|
||||||
|
order: 1,
|
||||||
|
begin: page * limit,
|
||||||
|
num: limit,
|
||||||
|
},
|
||||||
|
}).then(body => {
|
||||||
|
if (!body.albumList) throw new Error('get singer song list faild.')
|
||||||
|
|
||||||
|
const list = this.filterSongList(body.songList)
|
||||||
|
return {
|
||||||
|
source: 'tx',
|
||||||
|
list,
|
||||||
|
limit,
|
||||||
|
page,
|
||||||
|
total: body.totalNum,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
filterAlbumList(raw) {
|
||||||
|
return raw.map(item => {
|
||||||
|
return {
|
||||||
|
id: item.albumID,
|
||||||
|
mid: item.albumMid,
|
||||||
|
count: item.totalNum,
|
||||||
|
info: {
|
||||||
|
name: item.albumName,
|
||||||
|
author: item.singerName,
|
||||||
|
img: `https://y.gtimg.cn/music/photo_new/T002R500x500M000${item.albumMid}.jpg`,
|
||||||
|
desc: null,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
filterSongList(raw) {
|
||||||
|
const list = []
|
||||||
|
raw.forEach(item => {
|
||||||
|
list.push(filterMusicInfo(item.songInfo))
|
||||||
|
})
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,7 +1,6 @@
|
|||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../request'
|
||||||
import { decodeName, formatPlayTime, sizeFormate, dateFormat, formatPlayCount } from '../../index'
|
import { decodeName, formatPlayTime, sizeFormate, dateFormat, formatPlayCount } from '../../index'
|
||||||
import { formatSingerName } from '../utils'
|
import { formatSingerName, formatSingerList } from '../utils'
|
||||||
import { formatSingerList } from './util'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
_requestObj_tags: null,
|
_requestObj_tags: null,
|
||||||
|
|||||||
@ -1,15 +1,76 @@
|
|||||||
|
import { httpFetch } from '../../request'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理歌手列表
|
* 创建一个适用于TX的Http请求
|
||||||
* @param {Array} rawList
|
* @param {*} url
|
||||||
|
* @param {*} options
|
||||||
|
* @param {*} retryNum
|
||||||
*/
|
*/
|
||||||
export const formatSingerList = (rawList) => {
|
export const createMusicuFetch = async(data, options, retryNum = 0) => {
|
||||||
let returnList = []
|
if (retryNum > 2) throw new Error('try max num')
|
||||||
rawList.forEach((s) => {
|
|
||||||
returnList.push({
|
let result
|
||||||
name: s.name,
|
try {
|
||||||
id: String(s.id),
|
result = await httpFetch('https://u.y.qq.com/cgi-bin/musicu.fcg', {
|
||||||
mid: s.mid,
|
method: 'POST',
|
||||||
})
|
body: {
|
||||||
})
|
comm: {
|
||||||
return returnList
|
cv: 4747474,
|
||||||
|
ct: 24,
|
||||||
|
format: 'json',
|
||||||
|
inCharset: 'utf-8',
|
||||||
|
outCharset: 'utf-8',
|
||||||
|
uin: 0,
|
||||||
|
},
|
||||||
|
req: data,
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
'User-Angent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
|
||||||
|
},
|
||||||
|
}).promise
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
return createMusicuFetch(data, options, ++retryNum)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.statusCode !== 200 || result.body.code != 0 || result.body.req.code != 0) return createMusicuFetch(data, options, ++retryNum)
|
||||||
|
if (result.body.req.data) return result.body.req.data
|
||||||
|
return result.body.req
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建许多个适用于TX的Http请求
|
||||||
|
* @param {*} url
|
||||||
|
* @param {*} options
|
||||||
|
* @param {*} retryNum
|
||||||
|
*/
|
||||||
|
export const createMusicuFetchs = async(data, options, 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,
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
'User-Angent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
|
||||||
|
},
|
||||||
|
}).promise
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
return createMusicuFetchs(data, options, ++retryNum)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.statusCode !== 200 || result.body.code != 0) return createMusicuFetchs(data, options, ++retryNum)
|
||||||
|
return result.body
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,3 +48,19 @@ export const formatSingerName = (singers, nameKey = 'name', join = '、') => {
|
|||||||
}
|
}
|
||||||
return decodeName(String(singers ?? ''))
|
return decodeName(String(singers ?? ''))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理歌手列表
|
||||||
|
* @param singers 歌手数组
|
||||||
|
*/
|
||||||
|
export const formatSingerList = (singers, nameKey = 'name', idKey = 'id', midKey = 'mid') => {
|
||||||
|
const list = []
|
||||||
|
singers.forEach((s) => {
|
||||||
|
list.push({
|
||||||
|
name: s[nameKey],
|
||||||
|
id: s[idKey],
|
||||||
|
mid: s[midKey],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ export default {
|
|||||||
name: body.artist.name,
|
name: body.artist.name,
|
||||||
desc: body.artist.briefDesc,
|
desc: body.artist.briefDesc,
|
||||||
avatar: body.user.avatarUrl,
|
avatar: body.user.avatarUrl,
|
||||||
gender: body.user.gender === 1 ? '1' : '2',
|
gender: body.user.gender === 1 ? 'man' : 'woman',
|
||||||
},
|
},
|
||||||
count: {
|
count: {
|
||||||
music: body.artist.musicSize,
|
music: body.artist.musicSize,
|
||||||
@ -39,7 +39,7 @@ export default {
|
|||||||
limit,
|
limit,
|
||||||
offset: limit * page
|
offset: limit * page
|
||||||
}).then(body => {
|
}).then(body => {
|
||||||
if (!body.songs) throw new Error("get singer songs faild.")
|
if (!body.songs) throw new Error("get singer song list faild.")
|
||||||
|
|
||||||
const list = this.filterSongList(body.songs)
|
const list = this.filterSongList(body.songs)
|
||||||
return {
|
return {
|
||||||
@ -63,7 +63,7 @@ export default {
|
|||||||
limit,
|
limit,
|
||||||
offset: limit * page
|
offset: limit * page
|
||||||
}).then(body => {
|
}).then(body => {
|
||||||
if (!body.hotAlbums) throw new Error("get singer songs faild.")
|
if (!body.hotAlbums) throw new Error("get singer album list faild.")
|
||||||
|
|
||||||
const list = this.filterAlbumList(body.hotAlbums)
|
const list = this.filterAlbumList(body.hotAlbums)
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user