优化逻辑
parent
895198b7b8
commit
a8dcb0b973
|
@ -604,37 +604,21 @@ export default {
|
||||||
if (highQuality && songInfo._types['320k'] && list && list.includes('320k')) type = '320k'
|
if (highQuality && songInfo._types['320k'] && list && list.includes('320k')) type = '320k'
|
||||||
return type
|
return type
|
||||||
},
|
},
|
||||||
setUrl(targetSong, isRefresh, isRetryed = false, retryedSource = [], originMusic = null) {
|
setUrl(targetSong, isRefresh, isRetryed = false) {
|
||||||
if (!retryedSource.includes(targetSong.source)) retryedSource.push(targetSong.source)
|
|
||||||
|
|
||||||
let type = this.getPlayType(this.setting.player.highQuality, targetSong)
|
let type = this.getPlayType(this.setting.player.highQuality, targetSong)
|
||||||
// this.musicInfo.url = await getMusicUrl(targetSong, type)
|
// this.musicInfo.url = await getMusicUrl(targetSong, type)
|
||||||
this.status = this.statusText = this.$t('core.player.geting_url')
|
this.status = this.statusText = this.$t('core.player.geting_url')
|
||||||
|
|
||||||
return this.getUrl({ musicInfo: targetSong, originMusic, type, isRefresh }).then(url => {
|
return this.getUrl({ musicInfo: targetSong, type, isRefresh }).then(url => {
|
||||||
if ((targetSong !== this.targetSong && originMusic !== this.targetSong) || this.isPlay) return
|
if (targetSong !== this.targetSong || this.isPlay) return
|
||||||
audio.src = this.musicInfo.url = url
|
audio.src = this.musicInfo.url = url
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
// console.log('err', err.message)
|
// console.log('err', err.message)
|
||||||
if (err.message == requestMsg.cancelRequest) return
|
if (err.message == requestMsg.cancelRequest) return
|
||||||
if (!isRetryed) return this.setUrl(targetSong, isRefresh, true, retryedSource, originMusic)
|
if (!isRetryed) return this.setUrl(targetSong, isRefresh, true)
|
||||||
if (!originMusic) originMusic = targetSong
|
this.status = this.statusText = err.message
|
||||||
|
this.addDelayNextTimeout()
|
||||||
this.status = this.statusText = 'Try toggle source...'
|
return Promise.reject(err)
|
||||||
|
|
||||||
return this.getOtherSource(originMusic).then(otherSource => {
|
|
||||||
console.log('find otherSource', otherSource)
|
|
||||||
if (otherSource.length) {
|
|
||||||
for (const item of otherSource) {
|
|
||||||
if (retryedSource.includes(item.source) || !this.assertApiSupport(item.source)) continue
|
|
||||||
console.log('try toggle to: ', item.source, item.name, item.singer, item.interval)
|
|
||||||
return this.setUrl(item, isRefresh, false, retryedSource, originMusic)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.status = this.statusText = err.message
|
|
||||||
this.addDelayNextTimeout()
|
|
||||||
return Promise.reject(err)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
setImg(targetSong) {
|
setImg(targetSong) {
|
||||||
|
|
|
@ -165,12 +165,12 @@ const handleGetMusicUrl = function(musicInfo, type, retryedSource = [], originMu
|
||||||
reqPromise = Promise.reject(err)
|
reqPromise = Promise.reject(err)
|
||||||
}
|
}
|
||||||
return reqPromise.catch(err => {
|
return reqPromise.catch(err => {
|
||||||
if (!retryedSource.includes(musicInfo.source) || !assertApiSupport(musicInfo.source)) retryedSource.push(musicInfo.source)
|
if (!retryedSource.includes(musicInfo.source)) retryedSource.push(musicInfo.source)
|
||||||
return this.dispatch('list/getOtherSource', originMusic).then(otherSource => {
|
return this.dispatch('list/getOtherSource', originMusic).then(otherSource => {
|
||||||
console.log('find otherSource', otherSource)
|
console.log('find otherSource', otherSource)
|
||||||
if (otherSource.length) {
|
if (otherSource.length) {
|
||||||
for (const item of otherSource) {
|
for (const item of otherSource) {
|
||||||
if (retryedSource.includes(item.source)) continue
|
if (retryedSource.includes(item.source) || !assertApiSupport(item.source)) continue
|
||||||
console.log('try toggle to: ', item.source, item.name, item.singer, item.interval)
|
console.log('try toggle to: ', item.source, item.name, item.singer, item.interval)
|
||||||
return handleGetMusicUrl.call(this, item, type, retryedSource, originMusic)
|
return handleGetMusicUrl.call(this, item, type, retryedSource, originMusic)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@ import {
|
||||||
getLyric as getStoreLyric,
|
getLyric as getStoreLyric,
|
||||||
setLyric,
|
setLyric,
|
||||||
setMusicUrl,
|
setMusicUrl,
|
||||||
getMusicUrl,
|
getMusicUrl as getStoreMusicUrl,
|
||||||
|
assertApiSupport,
|
||||||
} from '../../utils'
|
} from '../../utils'
|
||||||
|
|
||||||
// state
|
// state
|
||||||
|
@ -66,6 +67,31 @@ const filterList = async({ playedList, listInfo, savePath, commit }) => {
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getMusicUrl = function(musicInfo, type, retryedSource = [], originMusic) {
|
||||||
|
// console.log(musicInfo.source)
|
||||||
|
if (!originMusic) originMusic = musicInfo
|
||||||
|
let reqPromise
|
||||||
|
try {
|
||||||
|
reqPromise = music[musicInfo.source].getMusicUrl(musicInfo, type).promise
|
||||||
|
} catch (err) {
|
||||||
|
reqPromise = Promise.reject(err)
|
||||||
|
}
|
||||||
|
return reqPromise.catch(err => {
|
||||||
|
if (!retryedSource.includes(musicInfo.source)) retryedSource.push(musicInfo.source)
|
||||||
|
return this.dispatch('list/getOtherSource', originMusic).then(otherSource => {
|
||||||
|
console.log('find otherSource', otherSource)
|
||||||
|
if (otherSource.length) {
|
||||||
|
for (const item of otherSource) {
|
||||||
|
if (retryedSource.includes(item.source) || !assertApiSupport(item.source)) continue
|
||||||
|
console.log('try toggle to: ', item.source, item.name, item.singer, item.interval)
|
||||||
|
return getMusicUrl.call(this, item, type, retryedSource, originMusic)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Promise.reject(err)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const getPic = function(musicInfo, retryedSource = [], originMusic) {
|
const getPic = function(musicInfo, retryedSource = [], originMusic) {
|
||||||
// console.log(musicInfo.source)
|
// console.log(musicInfo.source)
|
||||||
if (!originMusic) originMusic = musicInfo
|
if (!originMusic) originMusic = musicInfo
|
||||||
|
@ -163,24 +189,17 @@ const getters = {
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
const actions = {
|
const actions = {
|
||||||
async getUrl({ commit, state }, { musicInfo, originMusic, type, isRefresh }) {
|
async getUrl({ commit, state }, { musicInfo, type, isRefresh }) {
|
||||||
if (!musicInfo._types[type]) {
|
if (!musicInfo._types[type]) {
|
||||||
// 兼容旧版酷我源搜索列表过滤128k音质的bug
|
// 兼容旧版酷我源搜索列表过滤128k音质的bug
|
||||||
if (!(musicInfo.source == 'kw' && type == '128k')) throw new Error('该歌曲没有可播放的音频')
|
if (!(musicInfo.source == 'kw' && type == '128k')) throw new Error('该歌曲没有可播放的音频')
|
||||||
|
|
||||||
// return Promise.reject(new Error('该歌曲没有可播放的音频'))
|
// return Promise.reject(new Error('该歌曲没有可播放的音频'))
|
||||||
}
|
}
|
||||||
const cachedUrl = await getMusicUrl(musicInfo, type)
|
const cachedUrl = await getStoreMusicUrl(musicInfo, type)
|
||||||
if (cachedUrl && !isRefresh) return cachedUrl
|
if (cachedUrl && !isRefresh) return cachedUrl
|
||||||
|
|
||||||
let reqPromise
|
return getMusicUrl.call(this, musicInfo, type).then(({ url }) => {
|
||||||
try {
|
|
||||||
reqPromise = music[musicInfo.source].getMusicUrl(musicInfo, type).promise
|
|
||||||
} catch (err) {
|
|
||||||
reqPromise = Promise.reject(err)
|
|
||||||
}
|
|
||||||
return reqPromise.then(({ url }) => {
|
|
||||||
if (originMusic) commit('setUrl', { musicInfo: originMusic, url, type })
|
|
||||||
commit('setUrl', { musicInfo, url, type })
|
commit('setUrl', { musicInfo, url, type })
|
||||||
return url
|
return url
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
|
|
Loading…
Reference in New Issue