更新mg搜索接口
This commit is contained in:
parent
5f073ff76d
commit
87662ff25f
@ -2,19 +2,7 @@ import { httpFetch } from '../../request'
|
||||
|
||||
export default {
|
||||
getAlbum(songInfo, tryNum = 0) {
|
||||
let requestObj = httpFetch(`http://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/queryAlbumSong?albumId=${songInfo.albumId}&pageNo=1`, {
|
||||
// headers: {
|
||||
// sign: '46DB65104950B98FE451AD41047CC6C4',
|
||||
// timestamp: 1603451430776,
|
||||
// appId: 'yyapp2',
|
||||
// mode: 'android',
|
||||
// ua: 'Android_migu',
|
||||
// version: '6.9.4',
|
||||
// osVersion: 'android 7.0',
|
||||
// 'User-Agent': 'okhttp/3.9.1',
|
||||
// channel: '0146832',
|
||||
// },
|
||||
})
|
||||
let requestObj = httpFetch(`http://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/queryAlbumSong?albumId=${songInfo.albumId}&pageNo=1`)
|
||||
requestObj.promise = requestObj.promise.then(({ body }) => {
|
||||
if (body.code !== '000000') {
|
||||
if (tryNum > 5) return Promise.reject('获取专辑失败')
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { httpFetch } from '../../request'
|
||||
import getSongId from './songId'
|
||||
import { getSongId } from './songId'
|
||||
import { dateFormat2 } from '../../index'
|
||||
|
||||
export default {
|
||||
@ -29,7 +29,7 @@ export default {
|
||||
if (this._requestObj2) this._requestObj2.cancelHttp()
|
||||
|
||||
if (!musicInfo.songId) {
|
||||
let id = await this.getSongId(musicInfo)
|
||||
let id = await getSongId(musicInfo)
|
||||
if (!id) throw new Error('获取评论失败')
|
||||
musicInfo.songId = id
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { httpFetch } from '../../request'
|
||||
import { sizeFormate, formatPlayTime } from '../../index'
|
||||
import { sign } from './util'
|
||||
import { toMD5 } from '../utils'
|
||||
|
||||
export default {
|
||||
limit: 20,
|
||||
@ -8,21 +8,18 @@ export default {
|
||||
page: 0,
|
||||
allPage: 1,
|
||||
musicSearch(str, page, limit) {
|
||||
const time = Date.now()
|
||||
const signData = sign(str, time)
|
||||
const time = Date.now().toString()
|
||||
const signData = this.signWithSearch(time, str)
|
||||
const searchRequest = httpFetch(`https://jadeite.migu.cn/music_search/v3/search/searchAll?pageNo=${page}&pageSize=${limit}&sort=0&text=${encodeURI(str)}&searchSwitch={"song":1}&isCopyright=1&isCorrect=1`, {
|
||||
headers: {
|
||||
uiVersion: 'A_music_3.6.1',
|
||||
deviceId: signData.deviceId,
|
||||
timestamp: time.toString(),
|
||||
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',
|
||||
},
|
||||
})
|
||||
// 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)}`)
|
||||
return searchRequest.promise.then(({ body }) => body)
|
||||
},
|
||||
@ -33,14 +30,31 @@ export default {
|
||||
})
|
||||
return arr.join('、')
|
||||
},
|
||||
handleResult(rawData) {
|
||||
async getMusicInfo(copyrightIds) {
|
||||
return httpFetch('https://c.musicapp.migu.cn/MIGUM2.0/v1.0/content/resourceinfo.do?resourceType=2', {
|
||||
method: 'POST',
|
||||
formData: { resourceId: copyrightIds },
|
||||
}).promise.then(({ body }) => {
|
||||
if (body.code !== '000000') return Promise.reject(new Error('Failed to get music info.'))
|
||||
return body.resource
|
||||
})
|
||||
},
|
||||
signWithSearch(time, str) {
|
||||
const deviceId = '963B7AA0D21511ED807EE5846EC87D16'
|
||||
const signatureMd5 = '6cdc72a439cef99a3418d2a78aa28c73'
|
||||
const sign = toMD5(`${str}${signatureMd5}yyapp2d16148780a1dcc7408e06336b98cfd50${deviceId}${time}`)
|
||||
return { sign, deviceId }
|
||||
},
|
||||
filterData(rawData) {
|
||||
// console.log(rawData)
|
||||
let ids = new Set()
|
||||
const list = []
|
||||
const list = new Map()
|
||||
const ids = new Set()
|
||||
|
||||
rawData.forEach(item => {
|
||||
item.forEach(data => {
|
||||
if (ids.has(data.id)) return
|
||||
ids.add(data.id)
|
||||
if (ids.has(data.copyrightId) || !data.songId || !data.copyrightId) return
|
||||
ids.add(data.copyrightId)
|
||||
|
||||
const types = []
|
||||
const _types = {}
|
||||
data.audioFormats && data.audioFormats.forEach(type => {
|
||||
@ -77,7 +91,7 @@ export default {
|
||||
}
|
||||
})
|
||||
|
||||
list.push({
|
||||
list.set(data.songId, {
|
||||
singer: this.getSinger(data.singerList),
|
||||
name: data.name,
|
||||
albumName: data.album,
|
||||
@ -87,7 +101,7 @@ export default {
|
||||
copyrightId: data.copyrightId,
|
||||
source: 'mg',
|
||||
interval: formatPlayTime(data.duration),
|
||||
img: data.img3,
|
||||
img: /https?:/.test(data.img3) ? data.img3 : 'http://d.musicapp.migu.cn' + data.img3,
|
||||
lrc: null,
|
||||
lrcUrl: data.lrcUrl,
|
||||
mrcUrl: data.mrcurl,
|
||||
@ -101,16 +115,34 @@ export default {
|
||||
})
|
||||
return list
|
||||
},
|
||||
async handleResult(rawData) {
|
||||
// console.log(rawData)
|
||||
const list = []
|
||||
const datas = this.filterData(rawData)
|
||||
if (!datas) throw new Error('Failed to filter data')
|
||||
const songInfo = await this.getMusicInfo([...datas.keys()].join('|'))
|
||||
songInfo.forEach(item => {
|
||||
let data = datas.get(item.songId)
|
||||
if (!data) return
|
||||
list.push({
|
||||
...data,
|
||||
lrcUrl: item.lrcUrl,
|
||||
mrcUrl: item.mrcUrl,
|
||||
trcUrl: item.trcUrl,
|
||||
})
|
||||
})
|
||||
return list
|
||||
},
|
||||
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 => {
|
||||
return this.musicSearch(str, page, limit).then(async result => {
|
||||
// console.log(result)
|
||||
if (!result || result.code !== '000000') return Promise.reject(new Error(result ? result.info : '搜索失败'))
|
||||
const songResultData = result.songResultData || { result: [], totalCount: 0 }
|
||||
|
||||
let list = this.handleResult(songResultData.resultList)
|
||||
let list = await this.handleResult(songResultData.resultList)
|
||||
if (list == null) return this.search(str, page, limit, retryNum)
|
||||
|
||||
this.total = parseInt(songResultData.totalCount)
|
||||
|
||||
@ -1,22 +1,22 @@
|
||||
import { httpFetch } from '../../request'
|
||||
|
||||
const getSongId = async(mInfo, retry = 0) => {
|
||||
if (mInfo.songmid != mInfo.copyrightId) return mInfo.songmid
|
||||
export const getSongId = async(musicInfo, retry = 0) => {
|
||||
if (musicInfo.songmid != musicInfo.copyrightId) return musicInfo.songmid
|
||||
if (++retry > 2) return Promise.reject(new Error('max retry'))
|
||||
|
||||
const requestObj = httpFetch(`https://app.c.nf.migu.cn/MIGUM2.0/v2.0/content/listen-url?netType=00&resourceType=2&songId=${mInfo.copyrightId}&toneFlag=PQ`, {
|
||||
const requestObj = httpFetch(`https://app.c.nf.migu.cn/MIGUM2.0/v2.0/content/listen-url?netType=00&resourceType=2&songId=${musicInfo.copyrightId}&toneFlag=PQ`, {
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
|
||||
channel: '0146921',
|
||||
},
|
||||
})
|
||||
|
||||
return requestObj.promise.then(({ body }) => {
|
||||
if (!body || body.code !== '000000') return getSongId(mInfo, retry)
|
||||
console.log(body)
|
||||
if (!body || body.code !== '000000') return this.getSongId(musicInfo, retry)
|
||||
const id = body.data.songItem.songId
|
||||
if (!id) throw new Error('failed')
|
||||
return id
|
||||
})
|
||||
}
|
||||
|
||||
export default getSongId
|
||||
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
import { toMD5 } from '../utils'
|
||||
|
||||
export const sign = (keyword, timestamp) => {
|
||||
const deviceId = '963B7AA0D21511ED807EE5846EC87D16'
|
||||
const signatureMd5 = '6cdc72a439cef99a3418d2a78aa28c73'
|
||||
const text = `${keyword}${signatureMd5}yyapp2d16148780a1dcc7408e06336b98cfd50${deviceId}${timestamp}`
|
||||
return { sign: toMD5(text), deviceId }
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user