分离歌曲URL的缓存
This commit is contained in:
@@ -3,7 +3,7 @@ import fs from 'fs'
|
||||
import path from 'path'
|
||||
import music from '../../utils/music'
|
||||
import { getMusicType } from '../../utils/music/utils'
|
||||
import { setMeta, saveLrc, getLyric, setLyric } from '../../utils'
|
||||
import { setMeta, saveLrc, getLyric, setLyric, getMusicUrl, setMusicUrl } from '../../utils'
|
||||
|
||||
// state
|
||||
const state = {
|
||||
@@ -147,15 +147,20 @@ const pauseTasks = async(store, list, runs = []) => {
|
||||
await pauseTasks(store, list, runs)
|
||||
}
|
||||
|
||||
const getUrl = (downloadInfo, isRefresh) => {
|
||||
const url = downloadInfo.musicInfo.typeUrl[downloadInfo.type]
|
||||
const getUrl = async(downloadInfo, isRefresh) => {
|
||||
const cachedUrl = await getMusicUrl(downloadInfo.musicInfo, downloadInfo.type)
|
||||
if (!downloadInfo.musicInfo._types[downloadInfo.type]) {
|
||||
// 兼容旧版酷我源搜索列表过滤128k音质的bug
|
||||
if (!(downloadInfo.musicInfo.source == 'kw' && downloadInfo.type == '128k')) return Promise.reject(new Error('该歌曲没有可下载的音频'))
|
||||
if (!(downloadInfo.musicInfo.source == 'kw' && downloadInfo.type == '128k')) throw new Error('该歌曲没有可下载的音频')
|
||||
|
||||
// return Promise.reject(new Error('该歌曲没有可下载的音频'))
|
||||
}
|
||||
return url && !isRefresh ? Promise.resolve({ url }) : music[downloadInfo.musicInfo.source].getMusicUrl(downloadInfo.musicInfo, downloadInfo.type).promise
|
||||
return cachedUrl && !isRefresh
|
||||
? cachedUrl
|
||||
: music[downloadInfo.musicInfo.source].getMusicUrl(downloadInfo.musicInfo, downloadInfo.type).promise.then(({ url }) => {
|
||||
setMusicUrl(downloadInfo.musicInfo, downloadInfo.type, url)
|
||||
return url
|
||||
})
|
||||
}
|
||||
|
||||
// 修复 1.1.x版本 酷狗源歌词格式
|
||||
@@ -228,12 +233,12 @@ const downloadLyric = (downloadInfo, filePath) => {
|
||||
|
||||
const refreshUrl = function(commit, downloadInfo) {
|
||||
commit('setStatusText', { downloadInfo, text: '链接失效,正在刷新链接' })
|
||||
getUrl(downloadInfo, true).then(result => {
|
||||
commit('updateUrl', { downloadInfo, url: result.url })
|
||||
getUrl(downloadInfo, true).then(url => {
|
||||
commit('updateUrl', { downloadInfo, url })
|
||||
commit('setStatusText', { downloadInfo, text: '链接刷新成功' })
|
||||
const dl = dls[downloadInfo.key]
|
||||
if (!dl) return
|
||||
dl.refreshUrl(result.url)
|
||||
dl.refreshUrl(url)
|
||||
dl.start().catch(err => {
|
||||
commit('onError', { downloadInfo, errorMsg: err.message })
|
||||
commit('setStatusText', { downloadInfo, text: err.message })
|
||||
@@ -389,10 +394,10 @@ const actions = {
|
||||
commit('setStatusText', { downloadInfo, text: '获取URL中...' })
|
||||
let p = options.url
|
||||
? Promise.resolve()
|
||||
: getUrl(downloadInfo).then(result => {
|
||||
commit('updateUrl', { downloadInfo, url: result.url })
|
||||
if (!result.url) return Promise.reject(new Error('获取URL失败'))
|
||||
options.url = result.url
|
||||
: getUrl(downloadInfo).then(url => {
|
||||
commit('updateUrl', { downloadInfo, url })
|
||||
if (!url) return Promise.reject(new Error('获取URL失败'))
|
||||
options.url = url
|
||||
})
|
||||
p.then(() => {
|
||||
tryNum[downloadInfo.key] = 0
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import musicSdk from '../../utils/music'
|
||||
import { clearLyric } from '../../utils'
|
||||
import { clearLyric, clearMusicUrl } from '../../utils'
|
||||
|
||||
let allList = {}
|
||||
window.allList = allList
|
||||
@@ -215,6 +215,7 @@ const mutations = {
|
||||
if (item.tlrc) delete item.tlrc
|
||||
}
|
||||
}
|
||||
clearMusicUrl()
|
||||
clearLyric()
|
||||
},
|
||||
setOtherSource(state, { musicInfo, otherSource }) {
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import path from 'path'
|
||||
import music from '../../utils/music'
|
||||
import { getRandom, checkPath, getLyric as getStoreLyric, setLyric } from '../../utils'
|
||||
import {
|
||||
getRandom,
|
||||
checkPath,
|
||||
getLyric as getStoreLyric,
|
||||
setLyric,
|
||||
setMusicUrl,
|
||||
getMusicUrl,
|
||||
} from '../../utils'
|
||||
|
||||
// state
|
||||
const state = {
|
||||
@@ -147,20 +154,19 @@ const getters = {
|
||||
|
||||
// actions
|
||||
const actions = {
|
||||
getUrl({ commit, state }, { musicInfo, originMusic, type, isRefresh }) {
|
||||
async getUrl({ commit, state }, { musicInfo, originMusic, type, isRefresh }) {
|
||||
if (!musicInfo._types[type]) {
|
||||
// 兼容旧版酷我源搜索列表过滤128k音质的bug
|
||||
if (!(musicInfo.source == 'kw' && type == '128k')) return Promise.reject(new Error('该歌曲没有可播放的音频'))
|
||||
if (!(musicInfo.source == 'kw' && type == '128k')) throw new Error('该歌曲没有可播放的音频')
|
||||
|
||||
// return Promise.reject(new Error('该歌曲没有可播放的音频'))
|
||||
}
|
||||
if (urlRequest && urlRequest.cancelHttp) urlRequest.cancelHttp()
|
||||
if (musicInfo.typeUrl[type] && !isRefresh) return Promise.resolve(musicInfo.typeUrl[type])
|
||||
try {
|
||||
urlRequest = music[musicInfo.source].getMusicUrl(musicInfo, type)
|
||||
} catch (err) {
|
||||
return Promise.reject(err)
|
||||
}
|
||||
const cachedUrl = await getMusicUrl(musicInfo, type)
|
||||
if (cachedUrl && !isRefresh) return cachedUrl
|
||||
|
||||
urlRequest = music[musicInfo.source].getMusicUrl(musicInfo, type)
|
||||
|
||||
return urlRequest.promise.then(({ url }) => {
|
||||
if (originMusic) commit('setUrl', { musicInfo: originMusic, url, type })
|
||||
commit('setUrl', { musicInfo, url, type })
|
||||
@@ -328,8 +334,8 @@ const actions = {
|
||||
|
||||
// mitations
|
||||
const mutations = {
|
||||
setUrl(state, datas) {
|
||||
datas.musicInfo.typeUrl = Object.assign({}, datas.musicInfo.typeUrl, { [datas.type]: datas.url })
|
||||
setUrl(state, { musicInfo, type, url }) {
|
||||
setMusicUrl(musicInfo, type, url)
|
||||
},
|
||||
getPic(state, datas) {
|
||||
datas.musicInfo.img = datas.url
|
||||
|
||||
Reference in New Issue
Block a user