更新
This commit is contained in:
parent
4c0bd28629
commit
341bc7c048
@ -2,6 +2,7 @@ import { httpFetch } from '../../request'
|
||||
import { decodeName, formatPlayTime, sizeFormate } from '../../index'
|
||||
import { formatSingerName } from '../utils'
|
||||
|
||||
|
||||
export default {
|
||||
limit: 30,
|
||||
total: 0,
|
||||
|
||||
@ -1,61 +1,4 @@
|
||||
import { formatPlayTime, sizeFormate } from '../../index'
|
||||
import { formatSingerName } from '../utils'
|
||||
import { createMusicuFetch } from './util'
|
||||
|
||||
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'),
|
||||
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: {},
|
||||
}
|
||||
}
|
||||
import { createMusicuFetch, filterMusicInfoItem } from './util'
|
||||
|
||||
export const getMusicInfo = (id) => {
|
||||
return createMusicuFetch({
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { httpFetch } from '../../request'
|
||||
import { filterMusicInfoItem } from './musicInfo'
|
||||
import { filterMusicInfoItem } from './util'
|
||||
|
||||
export default {
|
||||
limit: 50,
|
||||
|
||||
@ -1,5 +1,42 @@
|
||||
import { createMusicuFetch } from './util'
|
||||
import { filterMusicInfoItem } from './musicInfo'
|
||||
import { createMusicuFetch, filterMusicInfoItem } from './util'
|
||||
import { httpFetch } from '../../request'
|
||||
|
||||
/**
|
||||
* 创建一个适用于TX的Http请求
|
||||
* @param {*} url
|
||||
* @param {*} options
|
||||
* @param {*} retryNum
|
||||
*/
|
||||
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,
|
||||
},
|
||||
...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) return createMusicuFetch(data, options, ++retryNum)
|
||||
|
||||
return result.body
|
||||
}
|
||||
|
||||
export default {
|
||||
/**
|
||||
@ -43,11 +80,11 @@ export default {
|
||||
},
|
||||
},
|
||||
}).then(body => {
|
||||
if (!body.req_1 || !body.req_2 || !body.req_3) throw new Error('get singer info faild.')
|
||||
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.singer_list[0]
|
||||
const music = body.req_3
|
||||
const album = body.req_3
|
||||
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,
|
||||
@ -86,15 +123,15 @@ export default {
|
||||
},
|
||||
},
|
||||
}).then(body => {
|
||||
if (!body.req) throw new Error('get singer album faild.')
|
||||
if (body.req.code != 0) throw new Error('get singer album faild.')
|
||||
|
||||
const list = this.filterAlbumList(body.req.albumList)
|
||||
const list = this.filterAlbumList(body.req.data.albumList)
|
||||
return {
|
||||
source: 'tx',
|
||||
list,
|
||||
limit,
|
||||
page,
|
||||
total: body.req.total,
|
||||
total: body.req.data.total,
|
||||
}
|
||||
})
|
||||
},
|
||||
@ -118,15 +155,15 @@ export default {
|
||||
},
|
||||
},
|
||||
}).then(body => {
|
||||
if (!body.req) throw new Error('get singer song list faild.')
|
||||
if (body.req.code != 0) throw new Error('get singer song list faild.')
|
||||
|
||||
const list = this.filterSongList(body.req.songList)
|
||||
const list = this.filterSongList(body.req.data.songList)
|
||||
return {
|
||||
source: 'tx',
|
||||
list,
|
||||
limit,
|
||||
page,
|
||||
total: body.req.totalNum,
|
||||
total: body.req.data.totalNum,
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
@ -1,43 +1,58 @@
|
||||
import { httpFetch } from '../../request'
|
||||
import { formatPlayTime, sizeFormate } from '../../index'
|
||||
import { formatSingerName } from '../utils'
|
||||
|
||||
/**
|
||||
* 创建一个适用于TX的Http请求
|
||||
* @param {*} url
|
||||
* @param {*} options
|
||||
* @param {*} retryNum
|
||||
*/
|
||||
export const createMusicuFetch = async(data, options, retryNum = 0) => {
|
||||
if (retryNum > 2) throw new Error('try max num')
|
||||
|
||||
let request
|
||||
try {
|
||||
request = 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 createMusicuFetch(data, options, ++retryNum)
|
||||
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'),
|
||||
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: {},
|
||||
}
|
||||
if (request.statusCode !== 200 || request.body.code != 0) return createMusicuFetch(data, options, ++retryNum)
|
||||
|
||||
const result = {}
|
||||
Object.keys(data).forEach(item => {
|
||||
if (request.body[item].code != 0) return
|
||||
result[item] = request.body[item].data
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { createEapiFetch } from './utils/index'
|
||||
import { eapiRequest } from './utils/index'
|
||||
import { formatPlayTime, sizeFormate } from '../../index'
|
||||
import { formatSingerName } from '../utils'
|
||||
|
||||
@ -8,8 +8,8 @@ export default {
|
||||
* @param {*} id
|
||||
*/
|
||||
getInfo(id) {
|
||||
return createEapiFetch('/api/artist/head/info/get', { id }).then(body => {
|
||||
if (!body) throw new Error("get singer info faild.")
|
||||
return eapiRequest('/api/artist/head/info/get', { id }).then(({ body }) => {
|
||||
if (!body || body.code != 200) throw new Error('get singer info faild.')
|
||||
return {
|
||||
source: 'wy',
|
||||
id: body.artist.id,
|
||||
@ -22,7 +22,7 @@ export default {
|
||||
count: {
|
||||
music: body.artist.musicSize,
|
||||
album: body.artist.albumSize,
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
},
|
||||
@ -34,12 +34,12 @@ export default {
|
||||
*/
|
||||
getSongList(id, page = 1, limit = 100) {
|
||||
if (page === 1) page = 0
|
||||
return createEapiFetch('/api/v2/artist/songs', {
|
||||
return eapiRequest('/api/v2/artist/songs', {
|
||||
id,
|
||||
limit,
|
||||
offset: limit * page
|
||||
}).then(body => {
|
||||
if (!body.songs) throw new Error("get singer song list faild.")
|
||||
offset: limit * page,
|
||||
}).then(({ body }) => {
|
||||
if (!body.songs || body.code != 200) throw new Error('get singer song list faild.')
|
||||
|
||||
const list = this.filterSongList(body.songs)
|
||||
return {
|
||||
@ -59,11 +59,11 @@ export default {
|
||||
*/
|
||||
getAlbumList(id, page = 1, limit = 10) {
|
||||
if (page === 1) page = 0
|
||||
return createEapiFetch(`/api/artist/albums/${id}`, {
|
||||
return eapiRequest(`/api/artist/albums/${id}`, {
|
||||
limit,
|
||||
offset: limit * page
|
||||
}).then(body => {
|
||||
if (!body.hotAlbums) throw new Error("get singer album list faild.")
|
||||
offset: limit * page,
|
||||
}).then(({ body }) => {
|
||||
if (!body.hotAlbums || body.code != 200) throw new Error('get singer album list faild.')
|
||||
|
||||
const list = this.filterAlbumList(body.hotAlbums)
|
||||
return {
|
||||
@ -71,7 +71,7 @@ export default {
|
||||
list,
|
||||
limit,
|
||||
page,
|
||||
total: body.artist.albumSize
|
||||
total: body.artist.albumSize,
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
@ -20,25 +20,3 @@ export const eapiRequest = (url, data) => {
|
||||
// })
|
||||
// return requestObj
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个Eapi请求
|
||||
* @param {*} url
|
||||
* @param {*} options
|
||||
* @param {*} retryNum
|
||||
*/
|
||||
export const createEapiFetch = async(url, data, retryNum = 0) => {
|
||||
if (retryNum > 2) throw new Error('try max num')
|
||||
|
||||
let result
|
||||
try {
|
||||
result = await eapiRequest(url, data).promise
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return createEapiFetch(url, data, ++retryNum)
|
||||
}
|
||||
|
||||
if (result.statusCode !== 200 || result.body.code != 200) return createEapiFetch(url, data, ++retryNum)
|
||||
if (result.body.data) return result.body.data
|
||||
return result.body
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user