commit
7a2f0b6e29
@ -2,6 +2,7 @@ import { httpFetch } from '../../request'
|
|||||||
import { decodeName, formatPlayTime, sizeFormate } from '../../index'
|
import { decodeName, formatPlayTime, sizeFormate } from '../../index'
|
||||||
import { formatSingerName } from '../utils'
|
import { formatSingerName } from '../utils'
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
limit: 30,
|
limit: 30,
|
||||||
total: 0,
|
total: 0,
|
||||||
|
|||||||
@ -1,61 +1,4 @@
|
|||||||
import { formatPlayTime, sizeFormate } from '../../index'
|
import { createMusicuFetch, filterMusicInfoItem } from './util'
|
||||||
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: {},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getMusicInfo = (id) => {
|
export const getMusicInfo = (id) => {
|
||||||
return createMusicuFetch({
|
return createMusicuFetch({
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../request'
|
||||||
import { filterMusicInfoItem } from './musicInfo'
|
import { filterMusicInfoItem } from './util'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
limit: 50,
|
limit: 50,
|
||||||
|
|||||||
@ -1,5 +1,42 @@
|
|||||||
import { createMusicuFetch } from './util'
|
import { createMusicuFetch, filterMusicInfoItem } from './util'
|
||||||
import { filterMusicInfoItem } from './musicInfo'
|
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 {
|
export default {
|
||||||
/**
|
/**
|
||||||
@ -43,11 +80,11 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}).then(body => {
|
}).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 info = body.req_1.data.singer_list[0]
|
||||||
const music = body.req_3
|
const music = body.req_3.data
|
||||||
const album = body.req_3
|
const album = body.req_3.data
|
||||||
return {
|
return {
|
||||||
source: 'tx',
|
source: 'tx',
|
||||||
id: info.basic_info.singer_mid,
|
id: info.basic_info.singer_mid,
|
||||||
@ -86,15 +123,15 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}).then(body => {
|
}).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 {
|
return {
|
||||||
source: 'tx',
|
source: 'tx',
|
||||||
list,
|
list,
|
||||||
limit,
|
limit,
|
||||||
page,
|
page,
|
||||||
total: body.req.total,
|
total: body.req.data.total,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -118,15 +155,15 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}).then(body => {
|
}).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 {
|
return {
|
||||||
source: 'tx',
|
source: 'tx',
|
||||||
list,
|
list,
|
||||||
limit,
|
limit,
|
||||||
page,
|
page,
|
||||||
total: body.req.totalNum,
|
total: body.req.data.totalNum,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,43 +1,58 @@
|
|||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../request'
|
||||||
|
import { formatPlayTime, sizeFormate } from '../../index'
|
||||||
|
import { formatSingerName } from '../utils'
|
||||||
|
|
||||||
/**
|
export const filterMusicInfoItem = item => {
|
||||||
* 创建一个适用于TX的Http请求
|
const types = []
|
||||||
* @param {*} url
|
const _types = {}
|
||||||
* @param {*} options
|
if (item.file.size_128mp3 != 0) {
|
||||||
* @param {*} retryNum
|
let size = sizeFormate(item.file.size_128mp3)
|
||||||
*/
|
types.push({ type: '128k', size })
|
||||||
export const createMusicuFetch = async(data, options, retryNum = 0) => {
|
_types['128k'] = {
|
||||||
if (retryNum > 2) throw new Error('try max num')
|
size,
|
||||||
|
}
|
||||||
let request
|
}
|
||||||
try {
|
if (item.file.size_320mp3 !== 0) {
|
||||||
request = await httpFetch('https://u.y.qq.com/cgi-bin/musicu.fcg', {
|
let size = sizeFormate(item.file.size_320mp3)
|
||||||
method: 'POST',
|
types.push({ type: '320k', size })
|
||||||
body: {
|
_types['320k'] = {
|
||||||
comm: {
|
size,
|
||||||
cv: 4747474,
|
}
|
||||||
ct: 24,
|
}
|
||||||
format: 'json',
|
if (item.file.size_flac !== 0) {
|
||||||
inCharset: 'utf-8',
|
let size = sizeFormate(item.file.size_flac)
|
||||||
outCharset: 'utf-8',
|
types.push({ type: 'flac', size })
|
||||||
uin: 0,
|
_types.flac = {
|
||||||
},
|
size,
|
||||||
...data,
|
}
|
||||||
},
|
}
|
||||||
headers: {
|
if (item.file.size_hires !== 0) {
|
||||||
'User-Angent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
|
let size = sizeFormate(item.file.size_hires)
|
||||||
},
|
types.push({ type: 'flac24bit', size })
|
||||||
}).promise
|
_types.flac24bit = {
|
||||||
} catch (err) {
|
size,
|
||||||
console.log(err)
|
}
|
||||||
return createMusicuFetch(data, options, ++retryNum)
|
}
|
||||||
|
|
||||||
|
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 { formatPlayTime, sizeFormate } from '../../index'
|
||||||
import { formatSingerName } from '../utils'
|
import { formatSingerName } from '../utils'
|
||||||
|
|
||||||
@ -8,8 +8,8 @@ export default {
|
|||||||
* @param {*} id
|
* @param {*} id
|
||||||
*/
|
*/
|
||||||
getInfo(id) {
|
getInfo(id) {
|
||||||
return createEapiFetch('/api/artist/head/info/get', { id }).then(body => {
|
return eapiRequest('/api/artist/head/info/get', { id }).then(({ body }) => {
|
||||||
if (!body) throw new Error("get singer info faild.")
|
if (!body || body.code != 200) throw new Error('get singer info faild.')
|
||||||
return {
|
return {
|
||||||
source: 'wy',
|
source: 'wy',
|
||||||
id: body.artist.id,
|
id: body.artist.id,
|
||||||
@ -22,7 +22,7 @@ export default {
|
|||||||
count: {
|
count: {
|
||||||
music: body.artist.musicSize,
|
music: body.artist.musicSize,
|
||||||
album: body.artist.albumSize,
|
album: body.artist.albumSize,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -34,12 +34,12 @@ export default {
|
|||||||
*/
|
*/
|
||||||
getSongList(id, page = 1, limit = 100) {
|
getSongList(id, page = 1, limit = 100) {
|
||||||
if (page === 1) page = 0
|
if (page === 1) page = 0
|
||||||
return createEapiFetch('/api/v2/artist/songs', {
|
return eapiRequest('/api/v2/artist/songs', {
|
||||||
id,
|
id,
|
||||||
limit,
|
limit,
|
||||||
offset: limit * page
|
offset: limit * page,
|
||||||
}).then(body => {
|
}).then(({ body }) => {
|
||||||
if (!body.songs) throw new Error("get singer song list faild.")
|
if (!body.songs || body.code != 200) throw new Error('get singer song list faild.')
|
||||||
|
|
||||||
const list = this.filterSongList(body.songs)
|
const list = this.filterSongList(body.songs)
|
||||||
return {
|
return {
|
||||||
@ -59,11 +59,11 @@ export default {
|
|||||||
*/
|
*/
|
||||||
getAlbumList(id, page = 1, limit = 10) {
|
getAlbumList(id, page = 1, limit = 10) {
|
||||||
if (page === 1) page = 0
|
if (page === 1) page = 0
|
||||||
return createEapiFetch(`/api/artist/albums/${id}`, {
|
return eapiRequest(`/api/artist/albums/${id}`, {
|
||||||
limit,
|
limit,
|
||||||
offset: limit * page
|
offset: limit * page,
|
||||||
}).then(body => {
|
}).then(({ body }) => {
|
||||||
if (!body.hotAlbums) throw new Error("get singer album list faild.")
|
if (!body.hotAlbums || body.code != 200) throw new Error('get singer album list faild.')
|
||||||
|
|
||||||
const list = this.filterAlbumList(body.hotAlbums)
|
const list = this.filterAlbumList(body.hotAlbums)
|
||||||
return {
|
return {
|
||||||
@ -71,7 +71,7 @@ export default {
|
|||||||
list,
|
list,
|
||||||
limit,
|
limit,
|
||||||
page,
|
page,
|
||||||
total: body.artist.albumSize
|
total: body.artist.albumSize,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|||||||
@ -20,25 +20,3 @@ export const eapiRequest = (url, data) => {
|
|||||||
// })
|
// })
|
||||||
// return requestObj
|
// 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