更新kg,kw的歌曲信息和搜索
This commit is contained in:
parent
4cb3ec9086
commit
8a50f23ec5
@ -1,13 +1,12 @@
|
||||
import { decodeName, formatPlayTime, sizeFormate } from '../../index'
|
||||
import { createHttpFetch } from './util'
|
||||
|
||||
const createGetMusicInfoTask = (hashs) => {
|
||||
const createGetMusicInfosTask = (hashs) => {
|
||||
let data = {
|
||||
appid: 1001,
|
||||
clienttime: 639437935,
|
||||
clientver: 9020,
|
||||
fields:
|
||||
'album_info,author_name,audio_info,ori_audio_name',
|
||||
fields: 'album_info,author_name,audio_info,ori_audio_name',
|
||||
is_publish: '1',
|
||||
key: '0475af1457cd3363c7b45b871e94428a',
|
||||
mid: '21511157a05844bd085308bc76ef3342',
|
||||
@ -101,8 +100,12 @@ export const filterMusicInfoList = (rawList) => {
|
||||
return list
|
||||
}
|
||||
|
||||
export const getMusicInfo = async(hash) => {
|
||||
return getMusicInfos([hash]).then(data => data[0])
|
||||
}
|
||||
|
||||
export const getMusicInfos = async(hashs) => {
|
||||
return filterMusicInfoList(await Promise.all(createGetMusicInfoTask(hashs)).then(data => data.flat()))
|
||||
return filterMusicInfoList(await Promise.all(createGetMusicInfosTask(hashs)).then(data => data.flat()))
|
||||
}
|
||||
|
||||
export const getMusicInfosByList = (list) => {
|
||||
|
||||
@ -6,11 +6,6 @@ export default {
|
||||
total: 0,
|
||||
page: 0,
|
||||
allPage: 1,
|
||||
musicSearch(str, page, limit) {
|
||||
const sign = signatureParams(`userid=0&area_code=1&appid=1005&dopicfull=1&page=${page}&token=0&privilegefilter=0&requestid=0&pagesize=${limit}&user_labels=&clienttime=0&sec_aggre=1&iscorrection=1&uuid=0&mid=0&keyword=${str}&dfid=-&clientver=11409&platform=AndroidFilter&tag=`, 3)
|
||||
const searchRequest = createHttpFetch(`https://gateway.kugou.com/complexsearch/v3/search/song?userid=0&area_code=1&appid=1005&dopicfull=1&page=${page}&token=0&privilegefilter=0&requestid=0&pagesize=${limit}&user_labels=&clienttime=0&sec_aggre=1&iscorrection=1&uuid=0&mid=0&dfid=-&clientver=11409&platform=AndroidFilter&tag=&keyword=${encodeURIComponent(str)}&signature=${sign}`)
|
||||
return searchRequest.then(body => body)
|
||||
},
|
||||
filterSongData(rawData) {
|
||||
let ids = new Set()
|
||||
const list = []
|
||||
@ -82,7 +77,6 @@ export default {
|
||||
if (++retryNum > 3) return Promise.reject(new Error('try max num'))
|
||||
if (limit == null) limit = this.limit
|
||||
|
||||
// http://newlyric.kuwo.cn/newlyric.lrc?62355680
|
||||
const sign = signatureParams(`userid=0&area_code=1&appid=1005&dopicfull=1&page=${page}&token=0&privilegefilter=0&requestid=0&pagesize=${limit}&user_labels=&clienttime=0&sec_aggre=1&iscorrection=1&uuid=0&mid=0&keyword=${str}&dfid=-&clientver=11409&platform=AndroidFilter&tag=`, 3)
|
||||
const searchResult = await createHttpFetch(`https://gateway.kugou.com/complexsearch/v3/search/song?userid=0&area_code=1&appid=1005&dopicfull=1&page=${page}&token=0&privilegefilter=0&requestid=0&pagesize=${limit}&user_labels=&clienttime=0&sec_aggre=1&iscorrection=1&uuid=0&mid=0&dfid=-&clientver=11409&platform=AndroidFilter&tag=&keyword=${encodeURIComponent(str)}&signature=${sign}`)
|
||||
|
||||
|
||||
@ -15,7 +15,6 @@ export const decodeLyric = str => new Promise((resolve, reject) => {
|
||||
resolve(result.toString())
|
||||
})
|
||||
})
|
||||
|
||||
// s.content[0].lyricContent.forEach(([str]) => {
|
||||
// console.log(str)
|
||||
// })
|
||||
@ -23,15 +22,13 @@ export const decodeLyric = str => new Promise((resolve, reject) => {
|
||||
/**
|
||||
* 签名
|
||||
* @param {*} params
|
||||
* @param {*} apiver
|
||||
* @param {*} apiVer
|
||||
*/
|
||||
export const signatureParams = (params, apiver = 9) => {
|
||||
let keyparam = 'OIlwieks28dk2k092lksi2UIkp'
|
||||
if (apiver === 5) keyparam = 'NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt'
|
||||
let param_list = params.split('&')
|
||||
param_list.sort()
|
||||
let sign_params = `${keyparam}${param_list.join('')}${keyparam}`
|
||||
return toMD5(sign_params)
|
||||
export const signatureParams = (params, apiVer = 9) => {
|
||||
let keyParam = 'OIlwieks28dk2k092lksi2UIkp'
|
||||
if (apiVer === 5) keyParam = 'NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt'
|
||||
let signParams = `${keyParam}${params.split('&').sort().join('')}${keyParam}`
|
||||
return toMD5(signParams)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { httpFetch } from '../../request'
|
||||
import { sizeFormate } from '../../index'
|
||||
import { createHttpFetch } from './util'
|
||||
|
||||
const getSinger = (singers) => {
|
||||
let arr = []
|
||||
@ -9,7 +9,24 @@ const getSinger = (singers) => {
|
||||
return arr.join('、')
|
||||
}
|
||||
|
||||
export const filterMusicInfoData = (rawList) => {
|
||||
const createGetMusicInfosTask = (ids, resType = 2) => {
|
||||
let list = ids
|
||||
let tasks = []
|
||||
while (list.length) {
|
||||
tasks.push(list.slice(0, 100))
|
||||
if (list.length < 100) break
|
||||
list = list.slice(100)
|
||||
}
|
||||
let url = `https://c.musicapp.migu.cn/MIGUM2.0/v1.0/content/resourceinfo.do?resourceType=${resType}`
|
||||
return tasks.map(task => createHttpFetch(url, {
|
||||
method: 'POST',
|
||||
form: {
|
||||
resourceId: task.join('|'),
|
||||
},
|
||||
}).then(data => data.resource))
|
||||
}
|
||||
|
||||
export const filterMusicInfoList = (rawList) => {
|
||||
// console.log(rawList)
|
||||
let ids = new Set()
|
||||
const list = []
|
||||
@ -74,27 +91,13 @@ export const filterMusicInfoData = (rawList) => {
|
||||
typeUrl: {},
|
||||
})
|
||||
})
|
||||
// console.log(list)
|
||||
return list
|
||||
}
|
||||
|
||||
export const getMusicInfos = (copyrightIds, retry = 0) => {
|
||||
if (++retry > 2) return Promise.reject(new Error('Failed to get music info try max'))
|
||||
return httpFetch('https://c.musicapp.migu.cn/MIGUM2.0/v1.0/content/resourceinfo.do?resourceType=2', {
|
||||
method: 'POST',
|
||||
form: {
|
||||
resourceId: copyrightIds.join('|'),
|
||||
},
|
||||
}).promise.then(({ body }) => {
|
||||
if (!body) return getMusicInfos(copyrightIds, retry)
|
||||
if (body.code !== '000000') return Promise.reject(new Error('Failed to get music info'))
|
||||
return filterMusicInfoData(body.resource)
|
||||
})
|
||||
export const getMusicInfo = async(copyrightId) => {
|
||||
return getMusicInfos([copyrightId]).then(data => data[0])
|
||||
}
|
||||
|
||||
export const getMusicInfo = (copyrightId) => {
|
||||
return getMusicInfos([copyrightId]).then(([musicInfo]) => {
|
||||
if (musicInfo) return musicInfo
|
||||
throw new Error('failed')
|
||||
})
|
||||
export const getMusicInfos = async(copyrightIds) => {
|
||||
return filterMusicInfoList(await Promise.all(createGetMusicInfosTask(copyrightIds)).then(data => data))
|
||||
}
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
import { httpFetch } from '../../request'
|
||||
import { sizeFormate, formatPlayTime } from '../../index'
|
||||
import { toMD5 } from '../utils'
|
||||
import { createHttpFetch } from './util'
|
||||
|
||||
const sign = (time, str) => {
|
||||
const deviceId = '963B7AA0D21511ED807EE5846EC87D20'
|
||||
const signatureMd5 = '6cdc72a439cef99a3418d2a78aa28c73'
|
||||
const sign = toMD5(`${str}${signatureMd5}yyapp2d16148780a1dcc7408e06336b98cfd50${deviceId}${time}`)
|
||||
return { sign, deviceId }
|
||||
const searchSign = (timeStr, str, deviceId) => {
|
||||
const key = '6cdc72a439cef99a3418d2a78aa28c73'
|
||||
return toMD5(`${str}${key}yyapp2d16148780a1dcc7408e06336b98cfd50${deviceId}${timeStr}`)
|
||||
}
|
||||
|
||||
export default {
|
||||
@ -14,116 +12,7 @@ export default {
|
||||
total: 0,
|
||||
page: 0,
|
||||
allPage: 1,
|
||||
|
||||
// 旧版API
|
||||
// musicSearch(str, page, limit) {
|
||||
// const searchRequest = httpFetch(`http://pd.musicapp.migu.cn/MIGUM2.0/v1.0/content/search_all.do?ua=Android_migu&version=5.0.1&text=${encodeURIComponent(str)}&pageNo=${page}&pageSize=${limit}&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A0%2C%22mvSong%22%3A0%2C%22songlist%22%3A0%2C%22bestShow%22%3A1%7D`, {
|
||||
// searchRequest = httpFetch(`http://pd.musicapp.migu.cn/MIGUM2.0/v1.0/content/search_all.do?ua=Android_migu&version=5.0.1&text=${encodeURIComponent(str)}&pageNo=${page}&pageSize=${limit}&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A0%2C%22mvSong%22%3A0%2C%22songlist%22%3A0%2C%22bestShow%22%3A1%7D`, {
|
||||
// searchRequest = httpFetch(`http://jadeite.migu.cn:7090/music_search/v2/search/searchAll?sid=4f87090d01c84984a11976b828e2b02c18946be88a6b4c47bcdc92fbd40762db&isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, {
|
||||
// searchRequest = httpFetch(`https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/search_all.do?isCopyright=1&isCorrect=1&pageNo=${page}&pageSize=${limit}&searchSwitch={%22song%22:1,%22album%22:0,%22singer%22:0,%22tagSong%22:0,%22mvSong%22:0,%22songlist%22:0,%22bestShow%22:0}&sort=0&text=${encodeURIComponent(str)}`)
|
||||
// // searchRequest = httpFetch(`http://jadeite.migu.cn:7090/music_search/v2/search/searchAll?sid=4f87090d01c84984a11976b828e2b02c18946be88a6b4c47bcdc92fbd40762db&isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, {
|
||||
// headers: {
|
||||
// // sign: 'c3b7ae985e2206e97f1b2de8f88691e2',
|
||||
// // timestamp: 1578225871982,
|
||||
// // appId: 'yyapp2',
|
||||
// // mode: 'android',
|
||||
// // ua: 'Android_migu',
|
||||
// // version: '6.9.4',
|
||||
// osVersion: 'android 7.0',
|
||||
// 'User-Agent': 'okhttp/3.9.1',
|
||||
// },
|
||||
// })
|
||||
// // searchRequest = httpFetch(`https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/search_all.do?isCopyright=1&isCorrect=1&pageNo=${page}&pageSize=${limit}&searchSwitch={%22song%22:1,%22album%22:0,%22singer%22:0,%22tagSong%22:0,%22mvSong%22:0,%22songlist%22:0,%22bestShow%22:0}&sort=0&text=${encodeURIComponent(str)}`)
|
||||
// return searchRequest.promise.then(({ body }) => body)
|
||||
// },
|
||||
// handleResult(rawData) {
|
||||
// // console.log(rawData)
|
||||
// let ids = new Set()
|
||||
// const list = []
|
||||
// rawData.forEach(item => {
|
||||
// if (ids.has(item.id)) return
|
||||
// ids.add(item.id)
|
||||
// const types = []
|
||||
// const _types = {}
|
||||
// item.newRateFormats && item.newRateFormats.forEach(type => {
|
||||
// let size
|
||||
// switch (type.formatType) {
|
||||
// case 'PQ':
|
||||
// size = sizeFormate(type.size ?? type.androidSize)
|
||||
// types.push({ type: '128k', size })
|
||||
// _types['128k'] = {
|
||||
// size,
|
||||
// }
|
||||
// break
|
||||
// case 'HQ':
|
||||
// size = sizeFormate(type.size ?? type.androidSize)
|
||||
// types.push({ type: '320k', size })
|
||||
// _types['320k'] = {
|
||||
// size,
|
||||
// }
|
||||
// break
|
||||
// case 'SQ':
|
||||
// size = sizeFormate(type.size ?? type.androidSize)
|
||||
// types.push({ type: 'flac', size })
|
||||
// _types.flac = {
|
||||
// size,
|
||||
// }
|
||||
// break
|
||||
// case 'ZQ':
|
||||
// size = sizeFormate(type.size ?? type.androidSize)
|
||||
// types.push({ type: 'flac24bit', size })
|
||||
// _types.flac24bit = {
|
||||
// size,
|
||||
// }
|
||||
// break
|
||||
// }
|
||||
// })
|
||||
|
||||
// const albumNInfo = item.albums && item.albums.length
|
||||
// ? {
|
||||
// id: item.albums[0].id,
|
||||
// name: item.albums[0].name,
|
||||
// }
|
||||
// : {}
|
||||
|
||||
// list.push({
|
||||
// singer: this.getSinger(item.singers),
|
||||
// name: item.name,
|
||||
// albumName: albumNInfo.name,
|
||||
// albumId: albumNInfo.id,
|
||||
// songmid: item.songId,
|
||||
// copyrightId: item.copyrightId,
|
||||
// source: 'mg',
|
||||
// interval: null,
|
||||
// img: item.imgItems && item.imgItems.length ? item.imgItems[0].img : null,
|
||||
// lrc: null,
|
||||
// lrcUrl: item.lyricUrl,
|
||||
// mrcUrl: item.mrcurl,
|
||||
// trcUrl: item.trcUrl,
|
||||
// otherSource: null,
|
||||
// types,
|
||||
// _types,
|
||||
// typeUrl: {},
|
||||
// })
|
||||
// })
|
||||
// return list
|
||||
// },
|
||||
|
||||
musicSearch(str, page, limit) {
|
||||
const time = Date.now().toString()
|
||||
const signData = sign(time, str)
|
||||
const searchRequest = httpFetch(`https://jadeite.migu.cn/music_search/v3/search/searchAll?isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, {
|
||||
headers: {
|
||||
uiVersion: 'A_music_3.6.1',
|
||||
deviceId: signData.deviceId,
|
||||
timestamp: time,
|
||||
sign: signData.sign,
|
||||
channel: '0146921',
|
||||
'User-Agent': 'Mozilla/5.0 (Linux; U; Android 11.0.0; zh-cn; MI 11 Build/OPR1.170623.032) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
|
||||
},
|
||||
})
|
||||
return searchRequest.promise.then(({ body }) => body)
|
||||
},
|
||||
deviceId: '963B7AA0D21511ED807EE5846EC87D20',
|
||||
getSinger(singers) {
|
||||
let arr = []
|
||||
singers.forEach(singer => {
|
||||
@ -131,100 +20,110 @@ export default {
|
||||
})
|
||||
return arr.join('、')
|
||||
},
|
||||
filterData(rawData) {
|
||||
// console.log(rawData)
|
||||
filterSongData(rawData) {
|
||||
const list = []
|
||||
const ids = new Set()
|
||||
|
||||
rawData.forEach(item => {
|
||||
item.forEach(data => {
|
||||
if (!data.songId || !data.copyrightId || ids.has(data.copyrightId)) return
|
||||
ids.add(data.copyrightId)
|
||||
rawData.forEach(data => {
|
||||
if (!data.songId || !data.copyrightId || ids.has(data.copyrightId)) return
|
||||
ids.add(data.copyrightId)
|
||||
|
||||
const types = []
|
||||
const _types = {}
|
||||
data.audioFormats && data.audioFormats.forEach(type => {
|
||||
let size
|
||||
switch (type.formatType) {
|
||||
case 'PQ':
|
||||
size = sizeFormate(type.asize ?? type.isize)
|
||||
types.push({ type: '128k', size })
|
||||
_types['128k'] = {
|
||||
size,
|
||||
}
|
||||
break
|
||||
case 'HQ':
|
||||
size = sizeFormate(type.asize ?? type.isize)
|
||||
types.push({ type: '320k', size })
|
||||
_types['320k'] = {
|
||||
size,
|
||||
}
|
||||
break
|
||||
case 'SQ':
|
||||
size = sizeFormate(type.asize ?? type.isize)
|
||||
types.push({ type: 'flac', size })
|
||||
_types.flac = {
|
||||
size,
|
||||
}
|
||||
break
|
||||
case 'ZQ24':
|
||||
size = sizeFormate(type.asize ?? type.isize)
|
||||
types.push({ type: 'flac24bit', size })
|
||||
_types.flac24bit = {
|
||||
size,
|
||||
}
|
||||
break
|
||||
}
|
||||
})
|
||||
const types = []
|
||||
const _types = {}
|
||||
data.audioFormats && data.audioFormats.forEach(type => {
|
||||
let size
|
||||
switch (type.formatType) {
|
||||
case 'PQ':
|
||||
size = sizeFormate(type.asize ?? type.isize)
|
||||
types.push({ type: '128k', size })
|
||||
_types['128k'] = {
|
||||
size,
|
||||
}
|
||||
break
|
||||
case 'HQ':
|
||||
size = sizeFormate(type.asize ?? type.isize)
|
||||
types.push({ type: '320k', size })
|
||||
_types['320k'] = {
|
||||
size,
|
||||
}
|
||||
break
|
||||
case 'SQ':
|
||||
size = sizeFormate(type.asize ?? type.isize)
|
||||
types.push({ type: 'flac', size })
|
||||
_types.flac = {
|
||||
size,
|
||||
}
|
||||
break
|
||||
case 'ZQ24':
|
||||
size = sizeFormate(type.asize ?? type.isize)
|
||||
types.push({ type: 'flac24bit', size })
|
||||
_types.flac24bit = {
|
||||
size,
|
||||
}
|
||||
break
|
||||
}
|
||||
})
|
||||
|
||||
let img = data.img3 || data.img2 || data.img1 || null
|
||||
if (img && !/https?:/.test(data.img3)) img = 'http://d.musicapp.migu.cn' + img
|
||||
let img = data.img3 || data.img2 || data.img1 || null
|
||||
if (img && !/https?:/.test(data.img3)) img = 'http://d.musicapp.migu.cn' + img
|
||||
|
||||
list.push({
|
||||
singer: this.getSinger(data.singerList),
|
||||
name: data.name,
|
||||
albumName: data.album,
|
||||
albumId: data.albumId,
|
||||
songmid: data.songId,
|
||||
copyrightId: data.copyrightId,
|
||||
source: 'mg',
|
||||
interval: formatPlayTime(data.duration),
|
||||
img,
|
||||
lrc: null,
|
||||
lrcUrl: data.lrcUrl,
|
||||
mrcUrl: data.mrcurl,
|
||||
trcUrl: data.trcUrl,
|
||||
types,
|
||||
_types,
|
||||
typeUrl: {},
|
||||
})
|
||||
list.push({
|
||||
singer: this.getSinger(data.singerList),
|
||||
name: data.name,
|
||||
albumName: data.album,
|
||||
albumId: data.albumId,
|
||||
songmid: data.songId,
|
||||
copyrightId: data.copyrightId,
|
||||
source: 'mg',
|
||||
interval: formatPlayTime(data.duration),
|
||||
img,
|
||||
lrc: null,
|
||||
lrcUrl: data.lrcUrl,
|
||||
mrcUrl: data.mrcurl,
|
||||
trcUrl: data.trcUrl,
|
||||
types,
|
||||
_types,
|
||||
typeUrl: {},
|
||||
})
|
||||
})
|
||||
return list
|
||||
},
|
||||
search(str, page = 1, limit, retryNum = 0) {
|
||||
// 旧版API
|
||||
// searchRequest = httpFetch(`http://pd.musicapp.migu.cn/MIGUM2.0/v1.0/content/search_all.do?ua=Android_migu&version=5.0.1&text=${encodeURIComponent(str)}&pageNo=${page}&pageSize=${limit}&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A0%2C%22mvSong%22%3A0%2C%22songlist%22%3A0%2C%22bestShow%22%3A1%7D`, {
|
||||
// searchRequest = httpFetch(`http://pd.musicapp.migu.cn/MIGUM2.0/v1.0/content/search_all.do?ua=Android_migu&version=5.0.1&text=${encodeURIComponent(str)}&pageNo=${page}&pageSize=${limit}&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A0%2C%22mvSong%22%3A0%2C%22songlist%22%3A0%2C%22bestShow%22%3A1%7D`, {
|
||||
// searchRequest = httpFetch(`http://jadeite.migu.cn:7090/music_search/v2/search/searchAll?sid=4f87090d01c84984a11976b828e2b02c18946be88a6b4c47bcdc92fbd40762db&isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, {
|
||||
// searchRequest = httpFetch(`https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/search_all.do?isCopyright=1&isCorrect=1&pageNo=${page}&pageSize=${limit}&searchSwitch={%22song%22:1,%22album%22:0,%22singer%22:0,%22tagSong%22:0,%22mvSong%22:0,%22songlist%22:0,%22bestShow%22:0}&sort=0&text=${encodeURIComponent(str)}`)
|
||||
async search(str, page = 1, limit, retryNum = 0) {
|
||||
if (++retryNum > 3) return Promise.reject(new Error('try max num'))
|
||||
if (limit == null) limit = this.limit
|
||||
// http://newlyric.kuwo.cn/newlyric.lrc?62355680
|
||||
return this.musicSearch(str, page, limit).then(result => {
|
||||
// console.log(result)
|
||||
if (!result || result.code !== '000000') return Promise.reject(new Error(result ? result.info : '搜索失败'))
|
||||
const songResultData = result.songResultData || { resultList: [], totalCount: 0 }
|
||||
|
||||
let list = this.filterData(songResultData.resultList)
|
||||
if (list == null) return this.search(str, page, limit, retryNum)
|
||||
|
||||
this.total = parseInt(songResultData.totalCount)
|
||||
this.page = page
|
||||
this.allPage = Math.ceil(this.total / limit)
|
||||
|
||||
return {
|
||||
list,
|
||||
allPage: this.allPage,
|
||||
limit,
|
||||
total: this.total,
|
||||
source: 'mg',
|
||||
}
|
||||
const timeStr = Date.now().toString()
|
||||
const signResult = searchSign(timeStr, str, this.deviceId)
|
||||
const searchResult = await createHttpFetch(`https://jadeite.migu.cn/music_search/v3/search/searchAll?isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, {
|
||||
headers: {
|
||||
uiVersion: 'A_music_3.6.1',
|
||||
deviceId: this.deviceId,
|
||||
timestamp: timeStr,
|
||||
sign: signResult,
|
||||
channel: '0146921',
|
||||
'User-Agent': 'Mozilla/5.0 (Linux; U; Android 11.0.0; zh-cn; MI 11 Build/OPR1.170623.032) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
|
||||
},
|
||||
})
|
||||
const songResultData = searchResult.songResultData || { resultList: [], totalCount: 0 }
|
||||
|
||||
let list = this.filterSongData(songResultData.resultList.flat())
|
||||
if (list == null) return this.search(str, page, limit, retryNum)
|
||||
|
||||
this.total = parseInt(songResultData.totalCount)
|
||||
this.page = page
|
||||
this.allPage = Math.ceil(this.total / limit)
|
||||
|
||||
return {
|
||||
list,
|
||||
allPage: this.allPage,
|
||||
limit,
|
||||
total: this.total,
|
||||
source: 'mg',
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
20
src/renderer/utils/musicSdk/mg/util.js
Normal file
20
src/renderer/utils/musicSdk/mg/util.js
Normal file
@ -0,0 +1,20 @@
|
||||
import { httpFetch } from '../../request'
|
||||
|
||||
/**
|
||||
* 创建一个适用于MG的Http请求
|
||||
* @param {*} url
|
||||
* @param {*} options
|
||||
* @param {*} retryNum
|
||||
*/
|
||||
export const createHttpFetch = async(url, options, retryNum = 0) => {
|
||||
if (retryNum > 2) throw new Error('try max num')
|
||||
let result
|
||||
try {
|
||||
result = await httpFetch(url, options).promise
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return createHttpFetch(url, options, ++retryNum)
|
||||
}
|
||||
if (result.statusCode !== 200 || result.body.code !== '000000') return createHttpFetch(url, options, ++retryNum)
|
||||
if (result.body) return result.body
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user