预留tx歌手API & 优化代码
This commit is contained in:
parent
5d2bfd5beb
commit
f0ece1d9d7
@ -18,7 +18,7 @@ export default {
|
||||
name: body.singername,
|
||||
desc: body.intro,
|
||||
avatar: body.imgurl.replace('{size}', 480),
|
||||
gender: body.grade === 1 ? '1' : '2',
|
||||
gender: body.grade === 1 ? 'man' : 'woman',
|
||||
},
|
||||
count: {
|
||||
music: body.songcount,
|
||||
@ -33,10 +33,10 @@ export default {
|
||||
* @param {*} page
|
||||
* @param {*} limit
|
||||
*/
|
||||
getAlbumList(id, page, 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 faild.')
|
||||
if (!body.info) throw new Error('get singer album list faild.')
|
||||
|
||||
const list = this.filterAlbumList(body.info)
|
||||
return {
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { httpFetch } from '../../request'
|
||||
import { formatPlayTime, sizeFormate } from '../../index'
|
||||
import { formatSingerName } from '../utils'
|
||||
import { formatSingerList } from './util'
|
||||
import { formatSingerName, formatSingerList } from '../utils'
|
||||
|
||||
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 getMusicInfo from './musicInfo'
|
||||
import { getMusicInfo } from './musicInfo'
|
||||
import { rendererInvoke } from '@common/rendererIpc'
|
||||
import { WIN_MAIN_RENDERER_EVENT_NAME } from '@common/ipcNames'
|
||||
|
||||
|
||||
@ -1,98 +1,77 @@
|
||||
import { httpFetch } from '../../request'
|
||||
import { formatPlayTime, sizeFormate } from '../../index'
|
||||
import { formatSingerName, formatSingerList } from '../utils'
|
||||
import { createMusicuFetch } from './util'
|
||||
|
||||
const getSinger = (singers) => {
|
||||
let arr = []
|
||||
singers.forEach(singer => {
|
||||
arr.push(singer.name)
|
||||
})
|
||||
return arr.join('、')
|
||||
export const filterMusicInfoItem = (item) => {
|
||||
const types = []
|
||||
const _types = {}
|
||||
if (item.file.size_128mp3 != 0) {
|
||||
let size = sizeFormate(item.file.size_128mp3)
|
||||
types.push({ type: '128k', size })
|
||||
_types['128k'] = {
|
||||
size,
|
||||
}
|
||||
}
|
||||
if (item.file.size_320mp3 !== 0) {
|
||||
let size = sizeFormate(item.file.size_320mp3)
|
||||
types.push({ type: '320k', size })
|
||||
_types['320k'] = {
|
||||
size,
|
||||
}
|
||||
}
|
||||
if (item.file.size_flac !== 0) {
|
||||
let size = sizeFormate(item.file.size_flac)
|
||||
types.push({ type: 'flac', size })
|
||||
_types.flac = {
|
||||
size,
|
||||
}
|
||||
}
|
||||
if (item.file.size_hires !== 0) {
|
||||
let size = sizeFormate(item.file.size_hires)
|
||||
types.push({ type: 'flac24bit', size })
|
||||
_types.flac24bit = {
|
||||
size,
|
||||
}
|
||||
}
|
||||
|
||||
const albumId = item.album.id ?? ''
|
||||
const albumMid = item.album.mid ?? ''
|
||||
const albumName = item.album.name ?? ''
|
||||
return {
|
||||
source: 'tx',
|
||||
singer: formatSingerName(item.singer, 'name'),
|
||||
singerList: formatSingerList(item.singer),
|
||||
name: item.name,
|
||||
albumName,
|
||||
albumId,
|
||||
albumMid,
|
||||
interval: formatPlayTime(item.interval),
|
||||
songId: item.id,
|
||||
songmid: item.mid,
|
||||
strMediaMid: item.file.media_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${albumMid}.jpg`,
|
||||
types,
|
||||
_types,
|
||||
typeUrl: {},
|
||||
}
|
||||
}
|
||||
|
||||
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)',
|
||||
export const getMusicInfo = (id) => {
|
||||
return createMusicuFetch({
|
||||
module: 'music.pf_song_detail_svr',
|
||||
method: 'get_song_detail_yqq',
|
||||
param: {
|
||||
song_type: 0,
|
||||
song_mid: id,
|
||||
},
|
||||
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
|
||||
}).then(body => {
|
||||
if (!body) throw new Error('get music info faild.')
|
||||
|
||||
const item = body.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['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
|
||||
}
|
||||
return {
|
||||
singer: getSinger(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: {},
|
||||
}
|
||||
return filterMusicInfoItem(item)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
import { httpFetch } from '../../request'
|
||||
import { formatPlayTime, sizeFormate } from '../../index'
|
||||
import { formatSingerName } from '../utils'
|
||||
import { formatSingerList } from './util'
|
||||
import { filterMusicInfoItem } from './musicInfo'
|
||||
|
||||
export default {
|
||||
limit: 50,
|
||||
@ -51,68 +49,10 @@ export default {
|
||||
})
|
||||
},
|
||||
handleResult(rawList) {
|
||||
// console.log(rawList)
|
||||
const list = []
|
||||
rawList.forEach(item => {
|
||||
if (!item.file?.media_mid) return
|
||||
|
||||
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: {},
|
||||
})
|
||||
list.push(filterMusicInfoItem(item))
|
||||
})
|
||||
// console.log(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 { decodeName, formatPlayTime, sizeFormate, dateFormat, formatPlayCount } from '../../index'
|
||||
import { formatSingerName } from '../utils'
|
||||
import { formatSingerList } from './util'
|
||||
import { formatSingerName, formatSingerList } from '../utils'
|
||||
|
||||
export default {
|
||||
_requestObj_tags: null,
|
||||
|
||||
@ -1,15 +1,76 @@
|
||||
import { httpFetch } from '../../request'
|
||||
|
||||
/**
|
||||
* 处理歌手列表
|
||||
* @param {Array} rawList
|
||||
* 创建一个适用于TX的Http请求
|
||||
* @param {*} url
|
||||
* @param {*} options
|
||||
* @param {*} retryNum
|
||||
*/
|
||||
export const formatSingerList = (rawList) => {
|
||||
let returnList = []
|
||||
rawList.forEach((s) => {
|
||||
returnList.push({
|
||||
name: s.name,
|
||||
id: String(s.id),
|
||||
mid: s.mid,
|
||||
})
|
||||
})
|
||||
return returnList
|
||||
export const createMusicuFetch = 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,
|
||||
},
|
||||
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 ?? ''))
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理歌手列表
|
||||
* @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,
|
||||
desc: body.artist.briefDesc,
|
||||
avatar: body.user.avatarUrl,
|
||||
gender: body.user.gender === 1 ? '1' : '2',
|
||||
gender: body.user.gender === 1 ? 'man' : 'woman',
|
||||
},
|
||||
count: {
|
||||
music: body.artist.musicSize,
|
||||
@ -39,7 +39,7 @@ export default {
|
||||
limit,
|
||||
offset: limit * page
|
||||
}).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)
|
||||
return {
|
||||
@ -63,7 +63,7 @@ export default {
|
||||
limit,
|
||||
offset: limit * page
|
||||
}).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)
|
||||
return {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user