更换migu搜索接口

pull/166/head
lyswhut 2020-01-13 13:20:04 +08:00
parent 914e738931
commit ae9b4bc2f5
2 changed files with 55 additions and 86 deletions

View File

@ -126,8 +126,8 @@ export default {
if (limit != null) this.limit = limit if (limit != null) this.limit = limit
// http://newlyric.kuwo.cn/newlyric.lrc?62355680 // http://newlyric.kuwo.cn/newlyric.lrc?62355680
return this.musicSearch(str, page).then(result => { return this.musicSearch(str, page).then(result => {
// console.log(result)
if (!result || (result.TOTAL !== '0' && result.SHOW === '0')) return this.search(str, page, { limit }, ++retryNum) if (!result || (result.TOTAL !== '0' && result.SHOW === '0')) return this.search(str, page, { limit }, ++retryNum)
console.log(result)
let list = this.handleResult(result.abslist) let list = this.handleResult(result.abslist)
if (list == null) return this.search(str, page, { limit }) if (list == null) return this.search(str, page, { limit })

View File

@ -1,7 +1,7 @@
// import '../../polyfill/array.find' // import '../../polyfill/array.find'
// import jshtmlencode from 'js-htmlencode' // import jshtmlencode from 'js-htmlencode'
import { httpFetch } from '../../request' import { httpFetch } from '../../request'
// import { sizeFormate } from '../../index' import { sizeFormate } from '../../index'
// import { debug } from '../../utils/env' // import { debug } from '../../utils/env'
// import { formatSinger } from './util' // import { formatSinger } from './util'
@ -13,7 +13,18 @@ export default {
allPage: 1, allPage: 1,
musicSearch(str, page) { musicSearch(str, page) {
if (searchRequest && searchRequest.cancelHttp) searchRequest.cancelHttp() if (searchRequest && searchRequest.cancelHttp) searchRequest.cancelHttp()
searchRequest = httpFetch(`http://m.music.migu.cn/migu/remoting/scr_search_tag?rows=${this.limit}&type=2&keyword=${encodeURIComponent(str)}&pgc=${page}`) 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=${this.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=${this.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(`https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/search_all.do?isCopyright=1&isCorrect=1&pageNo=${page}&pageSize=${this.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) return searchRequest.promise.then(({ body }) => body)
}, },
@ -33,80 +44,54 @@ export default {
ids.add(item.id) ids.add(item.id)
const types = [] const types = []
const _types = {} const _types = {}
types.push({ type: '128k' }) item.rateFormats && item.rateFormats.forEach(type => {
_types['128k'] = {} let size
if (item.hasHQqq) { switch (type.formatType) {
types.push({ type: '320k' }) case 'PQ':
_types['320k'] = {} size = sizeFormate(type.size)
types.push({ type: '128k', size })
_types['128k'] = {
size,
} }
if (item.hasSQqq) { break
types.push({ type: 'flac' }) case 'HQ':
_types.flac = {} size = sizeFormate(type.size)
types.push({ type: '320k', size })
_types['320k'] = {
size,
} }
// item.rateFormats && item.rateFormats.forEach(type => { break
// let size case 'SQ':
// switch (type.formatType) { size = sizeFormate(type.size)
// case 'PQ': types.push({ type: 'flac', size })
// size = sizeFormate(type.size) _types.flac = {
// types.push({ type: '128k', size }) size,
// _types['128k'] = { }
// size, break
// } }
// break })
// case 'HQ':
// size = sizeFormate(type.size) const albumNInfo = item.albums && item.albums.length ? {
// types.push({ type: '320k', size }) id: item.albums[0].id,
// _types['320k'] = { name: item.albums[0].name,
// size, } : {}
// }
// break
// case 'SQ':
// size = sizeFormate(type.size)
// types.push({ type: 'flac', size })
// _types.flac = {
// size,
// }
// break
// }
// })
list.push({ list.push({
singer: item.singerName.replace(', ', '、'), singer: this.getSinger(item.singers),
name: item.songName, name: item.name,
albumName: item.albumName, albumName: albumNInfo.name,
albumId: item.albumId, albumId: albumNInfo.id,
songmid: item.copyrightId, songmid: item.id,
copyrightId: item.copyrightId, copyrightId: item.copyrightId,
source: 'mg', source: 'mg',
interval: null, interval: null,
img: item.cover, img: item.imgItems && item.imgItems.length ? item.imgItems[0].img : null,
lrc: null, lrc: null,
// lrcUrl: item.lyrics, lrcUrl: item.lyricUrl,
types, types,
_types, _types,
typeUrl: {}, typeUrl: {},
}) })
// 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.id,
// copyrightId: item.copyrightId,
// source: 'mg',
// interval: null,
// img: item.imgItems && item.imgItems.length ? item.imgItems[0].img : null,
// lrc: null,
// lrcUrl: item.lyricUrl,
// types,
// _types,
// typeUrl: {},
// })
}) })
return list return list
}, },
@ -116,12 +101,12 @@ export default {
// http://newlyric.kuwo.cn/newlyric.lrc?62355680 // http://newlyric.kuwo.cn/newlyric.lrc?62355680
return this.musicSearch(str, page).then(result => { return this.musicSearch(str, page).then(result => {
// console.log(result) // console.log(result)
if (!result || result.success !== true) return Promise.reject(new Error(result ? result.info : '搜索失败')) if (!result || result.code !== '000000') return Promise.reject(new Error(result ? result.info : '搜索失败'))
let list = result.musics ? this.handleResult(result.musics) : [] let list = this.handleResult(result.songResultData.resultList.flat())
if (list == null) return this.search(str, page, { limit }, retryNum) if (list == null) return this.search(str, page, { limit }, retryNum)
this.total = parseInt(result.pgt) this.total = parseInt(result.songResultData.totalCount)
this.page = page this.page = page
this.allPage = Math.ceil(this.total / this.limit) this.allPage = Math.ceil(this.total / this.limit)
@ -132,22 +117,6 @@ export default {
total: this.total, total: this.total,
source: 'mg', source: 'mg',
}) })
// if (!result || result.code !== '000000') return Promise.reject(new Error(result ? result.info : '搜索失败'))
// let list = this.handleResult(result.songResultData.resultList.flat())
// if (list == null) return this.search(str, page, { limit })
// this.total = parseInt(result.songResultData.totalCount)
// this.page = page
// this.allPage = Math.ceil(this.total / this.limit)
// return Promise.resolve({
// list,
// allPage: this.allPage,
// limit: this.limit,
// total: this.total,
// source: 'mg',
// })
}) })
}, },
} }