添加繁忙重试重试

pull/1395/head
lyswhut 2023-05-05 19:01:57 +08:00
parent 1a3d84d4c4
commit b0bf1bf4be
13 changed files with 104 additions and 42 deletions

View File

@ -208,6 +208,7 @@
"player__end": "Stopped", "player__end": "Stopped",
"player__error": "Error loading music. Switch to next song after 5 seconds", "player__error": "Error loading music. Switch to next song after 5 seconds",
"player__geting_url": "Getting music link...", "player__geting_url": "Getting music link...",
"player__geting_url_delay_retry": "The service is busy, try again in {time} seconds...",
"player__hide_detail_tip": "Hide detail page (Right-click in the view to quickly hide the details page)", "player__hide_detail_tip": "Hide detail page (Right-click in the view to quickly hide the details page)",
"player__loading": "Music loading...", "player__loading": "Music loading...",
"player__music_album": "Album: ", "player__music_album": "Album: ",
@ -231,20 +232,20 @@
"player__sound_effect_biquad_filter": "Equalizer", "player__sound_effect_biquad_filter": "Equalizer",
"player__sound_effect_biquad_filter_reset_btn": "Reset equalizer", "player__sound_effect_biquad_filter_reset_btn": "Reset equalizer",
"player__sound_effect_convolution": "Ambient reverb sound effect", "player__sound_effect_convolution": "Ambient reverb sound effect",
"player__sound_effect_convolution_file_telephone": "Telephone",
"player__sound_effect_convolution_file_s2_r4_bd": "Church",
"player__sound_effect_convolution_file_s3_r1_bd": "Church 2",
"player__sound_effect_convolution_file_matrix_1": "Matrix",
"player__sound_effect_convolution_file_matrix_2": "Matrix 2",
"player__sound_effect_convolution_file_bright_hall": "Hall", "player__sound_effect_convolution_file_bright_hall": "Hall",
"player__sound_effect_convolution_file_cardiod_35_10_spread": "Rock",
"player__sound_effect_convolution_file_cinema_diningroom": "Cinema", "player__sound_effect_convolution_file_cinema_diningroom": "Cinema",
"player__sound_effect_convolution_file_dining_living_true_stereo": "Dining Room", "player__sound_effect_convolution_file_dining_living_true_stereo": "Dining Room",
"player__sound_effect_convolution_file_living_bedroom_leveled": "Bathroom",
"player__sound_effect_convolution_file_spreader50_65ms": "Indoor",
"player__sound_effect_convolution_file_spreader25_125ms": "Indoor 2",
"player__sound_effect_convolution_file_cardiod_35_10_spread": "Rock",
"player__sound_effect_convolution_file_tim_omni_35_10_magnetic": "Rock 2",
"player__sound_effect_convolution_file_feedback_spring": "Feedback Spring", "player__sound_effect_convolution_file_feedback_spring": "Feedback Spring",
"player__sound_effect_convolution_file_living_bedroom_leveled": "Bathroom",
"player__sound_effect_convolution_file_matrix_1": "Matrix",
"player__sound_effect_convolution_file_matrix_2": "Matrix 2",
"player__sound_effect_convolution_file_s2_r4_bd": "Church",
"player__sound_effect_convolution_file_s3_r1_bd": "Church 2",
"player__sound_effect_convolution_file_spreader25_125ms": "Indoor 2",
"player__sound_effect_convolution_file_spreader50_65ms": "Indoor",
"player__sound_effect_convolution_file_telephone": "Telephone",
"player__sound_effect_convolution_file_tim_omni_35_10_magnetic": "Rock 2",
"player__sound_effect_convolution_main_gain": "Original Audio Gain", "player__sound_effect_convolution_main_gain": "Original Audio Gain",
"player__sound_effect_convolution_send_gain": "Ambient Sound Effect Gain", "player__sound_effect_convolution_send_gain": "Ambient Sound Effect Gain",
"player__sound_effect_panner": "3D stereo surround (need to use headphones)", "player__sound_effect_panner": "3D stereo surround (need to use headphones)",

View File

@ -208,6 +208,7 @@
"player__end": "播放完毕", "player__end": "播放完毕",
"player__error": "音频加载出错5 秒后切换下一首", "player__error": "音频加载出错5 秒后切换下一首",
"player__geting_url": "歌曲链接获取中...", "player__geting_url": "歌曲链接获取中...",
"player__geting_url_delay_retry": "服务繁忙,{time}秒后重试...",
"player__hide_detail_tip": "隐藏详情页(界面内右键双击可快速隐藏详情页)", "player__hide_detail_tip": "隐藏详情页(界面内右键双击可快速隐藏详情页)",
"player__loading": "音乐加载中...", "player__loading": "音乐加载中...",
"player__music_album": "专辑名:", "player__music_album": "专辑名:",
@ -231,20 +232,20 @@
"player__sound_effect_biquad_filter": "均衡器", "player__sound_effect_biquad_filter": "均衡器",
"player__sound_effect_biquad_filter_reset_btn": "重置均衡器", "player__sound_effect_biquad_filter_reset_btn": "重置均衡器",
"player__sound_effect_convolution": "环境混响音效", "player__sound_effect_convolution": "环境混响音效",
"player__sound_effect_convolution_file_telephone": "电话",
"player__sound_effect_convolution_file_s2_r4_bd": "教堂",
"player__sound_effect_convolution_file_s3_r1_bd": "教堂2",
"player__sound_effect_convolution_file_matrix_1": "矩阵",
"player__sound_effect_convolution_file_matrix_2": "矩阵2",
"player__sound_effect_convolution_file_bright_hall": "大厅", "player__sound_effect_convolution_file_bright_hall": "大厅",
"player__sound_effect_convolution_file_cardiod_35_10_spread": "摇滚",
"player__sound_effect_convolution_file_cinema_diningroom": "电影院", "player__sound_effect_convolution_file_cinema_diningroom": "电影院",
"player__sound_effect_convolution_file_dining_living_true_stereo": "餐厅", "player__sound_effect_convolution_file_dining_living_true_stereo": "餐厅",
"player__sound_effect_convolution_file_living_bedroom_leveled": "卫生间",
"player__sound_effect_convolution_file_spreader50_65ms": "室内",
"player__sound_effect_convolution_file_spreader25_125ms": "室内2",
"player__sound_effect_convolution_file_cardiod_35_10_spread": "摇滚",
"player__sound_effect_convolution_file_tim_omni_35_10_magnetic": "摇滚2",
"player__sound_effect_convolution_file_feedback_spring": "反馈弹簧", "player__sound_effect_convolution_file_feedback_spring": "反馈弹簧",
"player__sound_effect_convolution_file_living_bedroom_leveled": "卫生间",
"player__sound_effect_convolution_file_matrix_1": "矩阵",
"player__sound_effect_convolution_file_matrix_2": "矩阵2",
"player__sound_effect_convolution_file_s2_r4_bd": "教堂",
"player__sound_effect_convolution_file_s3_r1_bd": "教堂2",
"player__sound_effect_convolution_file_spreader25_125ms": "室内2",
"player__sound_effect_convolution_file_spreader50_65ms": "室内",
"player__sound_effect_convolution_file_telephone": "电话",
"player__sound_effect_convolution_file_tim_omni_35_10_magnetic": "摇滚2",
"player__sound_effect_convolution_main_gain": "原始音频增益", "player__sound_effect_convolution_main_gain": "原始音频增益",
"player__sound_effect_convolution_send_gain": "环境音效增益", "player__sound_effect_convolution_send_gain": "环境音效增益",
"player__sound_effect_panner": "3D立体环绕需使用耳机", "player__sound_effect_panner": "3D立体环绕需使用耳机",

View File

@ -209,6 +209,7 @@
"player__end": "播放完畢", "player__end": "播放完畢",
"player__error": "音頻加載出錯5 秒後切換下一首", "player__error": "音頻加載出錯5 秒後切換下一首",
"player__geting_url": "歌曲鏈接獲取中...", "player__geting_url": "歌曲鏈接獲取中...",
"player__geting_url_delay_retry": "服務繁忙,{time}秒後重試...",
"player__hide_detail_tip": "隱藏詳情頁(界面內右鍵雙擊可快速隱藏詳情頁)", "player__hide_detail_tip": "隱藏詳情頁(界面內右鍵雙擊可快速隱藏詳情頁)",
"player__loading": "音樂加載中...", "player__loading": "音樂加載中...",
"player__music_name": "歌曲名:", "player__music_name": "歌曲名:",
@ -231,20 +232,20 @@
"player__sound_effect_biquad_filter": "均衡器", "player__sound_effect_biquad_filter": "均衡器",
"player__sound_effect_biquad_filter_reset_btn": "重置均衡器", "player__sound_effect_biquad_filter_reset_btn": "重置均衡器",
"player__sound_effect_convolution": "環境混響音效", "player__sound_effect_convolution": "環境混響音效",
"player__sound_effect_convolution_file_telephone": "電話",
"player__sound_effect_convolution_file_s2_r4_bd": "教堂",
"player__sound_effect_convolution_file_s3_r1_bd": "教堂2",
"player__sound_effect_convolution_file_matrix_1": "矩陣",
"player__sound_effect_convolution_file_matrix_2": "矩陣2",
"player__sound_effect_convolution_file_bright_hall": "大廳", "player__sound_effect_convolution_file_bright_hall": "大廳",
"player__sound_effect_convolution_file_cardiod_35_10_spread": "搖滾",
"player__sound_effect_convolution_file_cinema_diningroom": "電影院", "player__sound_effect_convolution_file_cinema_diningroom": "電影院",
"player__sound_effect_convolution_file_dining_living_true_stereo": "餐廳", "player__sound_effect_convolution_file_dining_living_true_stereo": "餐廳",
"player__sound_effect_convolution_file_living_bedroom_leveled": "衛生間",
"player__sound_effect_convolution_file_spreader50_65ms": "室內",
"player__sound_effect_convolution_file_spreader25_125ms": "室內2",
"player__sound_effect_convolution_file_cardiod_35_10_spread": "搖滾",
"player__sound_effect_convolution_file_tim_omni_35_10_magnetic": "搖滾2",
"player__sound_effect_convolution_file_feedback_spring": "反饋彈簧", "player__sound_effect_convolution_file_feedback_spring": "反饋彈簧",
"player__sound_effect_convolution_file_living_bedroom_leveled": "衛生間",
"player__sound_effect_convolution_file_matrix_1": "矩陣",
"player__sound_effect_convolution_file_matrix_2": "矩陣2",
"player__sound_effect_convolution_file_s2_r4_bd": "教堂",
"player__sound_effect_convolution_file_s3_r1_bd": "教堂2",
"player__sound_effect_convolution_file_spreader25_125ms": "室內2",
"player__sound_effect_convolution_file_spreader50_65ms": "室內",
"player__sound_effect_convolution_file_telephone": "電話",
"player__sound_effect_convolution_file_tim_omni_35_10_magnetic": "搖滾2",
"player__sound_effect_convolution_main_gain": "原始音頻增益", "player__sound_effect_convolution_main_gain": "原始音頻增益",
"player__sound_effect_convolution_send_gain": "環境音效增益", "player__sound_effect_convolution_send_gain": "環境音效增益",
"player__sound_effect_panner": "3D立體環繞需使用耳機", "player__sound_effect_panner": "3D立體環繞需使用耳機",

View File

@ -9,6 +9,7 @@ import {
} from '@renderer/utils/ipc' } from '@renderer/utils/ipc'
import { appSetting } from '@renderer/store/setting' import { appSetting } from '@renderer/store/setting'
import { langS2T, toNewMusicInfo, toOldMusicInfo } from '@renderer/utils' import { langS2T, toNewMusicInfo, toOldMusicInfo } from '@renderer/utils'
import { requestMsg } from '@renderer/utils/message'
const getOtherSourcePromises = new Map() const getOtherSourcePromises = new Map()
@ -187,6 +188,7 @@ export const getOnlineOtherSourceMusicUrl = async({ musicInfos, quality, onToggl
return { musicInfo, url, quality: type, isFromCache: false } return { musicInfo, url, quality: type, isFromCache: false }
// eslint-disable-next-line @typescript-eslint/promise-function-async // eslint-disable-next-line @typescript-eslint/promise-function-async
}).catch((err: any) => { }).catch((err: any) => {
if (err.message == requestMsg.tooManyRequests) throw err
console.log(err) console.log(err)
return getOnlineOtherSourceMusicUrl({ musicInfos, quality, onToggleSource, isRefresh, retryedSource }) return getOnlineOtherSourceMusicUrl({ musicInfos, quality, onToggleSource, isRefresh, retryedSource })
}) })
@ -220,7 +222,7 @@ export const handleGetOnlineMusicUrl = async({ musicInfo, quality, onToggleSourc
return { musicInfo, url, quality: type, isFromCache: false } return { musicInfo, url, quality: type, isFromCache: false }
}).catch(async(err: any) => { }).catch(async(err: any) => {
console.log(err) console.log(err)
if (!allowToggleSource) throw err if (!allowToggleSource || err.message == requestMsg.tooManyRequests) throw err
onToggleSource() onToggleSource()
// eslint-disable-next-line @typescript-eslint/promise-function-async // eslint-disable-next-line @typescript-eslint/promise-function-async
return await getOtherSource(musicInfo).then(otherSource => { return await getOtherSource(musicInfo).then(otherSource => {

View File

@ -52,12 +52,36 @@ const { addDelayNextTimeout: addLoadTimeout, clearDelayNextTimeout: clearLoadTim
* *
*/ */
const diffCurrentMusicInfo = (curMusicInfo: LX.Music.MusicInfo | LX.Download.ListItem): boolean => { const diffCurrentMusicInfo = (curMusicInfo: LX.Music.MusicInfo | LX.Download.ListItem): boolean => {
return curMusicInfo !== playMusicInfo.musicInfo || isPlay.value // return curMusicInfo !== playMusicInfo.musicInfo || isPlay.value
return gettingUrlId != curMusicInfo.id || curMusicInfo.id != playMusicInfo.musicInfo?.id || isPlay.value
} }
let cancelDelayRetry: (() => void) | null = null
const delayRetry = async(musicInfo: LX.Music.MusicInfo | LX.Download.ListItem, isRefresh = false): Promise<string | null> => {
// if (cancelDelayRetry) cancelDelayRetry()
return new Promise<string | null>((resolve, reject) => {
const time = getRandom(2, 6)
setAllStatus(window.i18n.t('player__geting_url_delay_retry', { time }))
const tiemout = setTimeout(() => {
getMusicPlayUrl(musicInfo, isRefresh, true).then((result) => {
cancelDelayRetry = null
resolve(result)
}).catch(async(err: any) => {
cancelDelayRetry = null
reject(err)
})
}, time * 1000)
cancelDelayRetry = () => {
clearTimeout(tiemout)
cancelDelayRetry = null
resolve(null)
}
})
}
const getMusicPlayUrl = async(musicInfo: LX.Music.MusicInfo | LX.Download.ListItem, isRefresh = false, isRetryed = false): Promise<string | null> => { const getMusicPlayUrl = async(musicInfo: LX.Music.MusicInfo | LX.Download.ListItem, isRefresh = false, isRetryed = false): Promise<string | null> => {
// this.musicInfo.url = await getMusicPlayUrl(targetSong, type) // this.musicInfo.url = await getMusicPlayUrl(targetSong, type)
setAllStatus(window.i18n.t('player__geting_url')) setAllStatus(window.i18n.t('player__geting_url'))
if (appSetting['player.autoSkipOnError']) addLoadTimeout()
// const type = getPlayType(appSetting['player.highQuality'], musicInfo) // const type = getPlayType(appSetting['player.highQuality'], musicInfo)
@ -79,6 +103,8 @@ const getMusicPlayUrl = async(musicInfo: LX.Music.MusicInfo | LX.Download.ListIt
diffCurrentMusicInfo(musicInfo) || diffCurrentMusicInfo(musicInfo) ||
err.message == requestMsg.cancelRequest) return null err.message == requestMsg.cancelRequest) return null
if (err.message == requestMsg.tooManyRequests) return delayRetry(musicInfo, isRefresh)
if (!isRetryed) return getMusicPlayUrl(musicInfo, isRefresh, true) if (!isRetryed) return getMusicPlayUrl(musicInfo, isRefresh, true)
throw err throw err
@ -86,7 +112,9 @@ const getMusicPlayUrl = async(musicInfo: LX.Music.MusicInfo | LX.Download.ListIt
} }
export const setMusicUrl = (musicInfo: LX.Music.MusicInfo | LX.Download.ListItem, isRefresh?: boolean) => { export const setMusicUrl = (musicInfo: LX.Music.MusicInfo | LX.Download.ListItem, isRefresh?: boolean) => {
if (appSetting['player.autoSkipOnError']) addLoadTimeout() // if (appSetting['player.autoSkipOnError']) addLoadTimeout()
if (!diffCurrentMusicInfo(musicInfo)) return
if (cancelDelayRetry) cancelDelayRetry()
gettingUrlId = musicInfo.id gettingUrlId = musicInfo.id
void getMusicPlayUrl(musicInfo, isRefresh).then((url) => { void getMusicPlayUrl(musicInfo, isRefresh).then((url) => {
if (!url) return if (!url) return
@ -152,8 +180,7 @@ const handlePlay = () => {
} }
const musicInfo = playMusicInfo.musicInfo const musicInfo = playMusicInfo.musicInfo
if (!musicInfo || gettingUrlId == musicInfo.id) return if (!musicInfo) return
gettingUrlId &&= ''
setStop() setStop()
window.app_event.pause() window.app_event.pause()

View File

@ -5,4 +5,5 @@ export const requestMsg = {
// unachievable: '哦No😱...接口无法访问了!已帮你切换到临时接口,重试下看能不能播放吧~', // unachievable: '哦No😱...接口无法访问了!已帮你切换到临时接口,重试下看能不能播放吧~',
notConnectNetwork: '无法连接到服务器', notConnectNetwork: '无法连接到服务器',
cancelRequest: '取消http请求', cancelRequest: '取消http请求',
tooManyRequests: '服务器繁忙',
} as const } as const

View File

@ -13,7 +13,11 @@ const api_test = {
family: 4, family: 4,
}) })
requestObj.promise = requestObj.promise.then(({ body }) => { requestObj.promise = requestObj.promise.then(({ body }) => {
return body.code === 0 ? Promise.resolve({ type, url: body.data }) : Promise.reject(new Error(requestMsg.fail)) switch (body.code) {
case 0: return Promise.resolve({ type, url: body.data })
case 429: return Promise.reject(new Error(requestMsg.tooManyRequests))
default: return Promise.reject(new Error(requestMsg.fail))
}
}) })
return requestObj return requestObj
}, },

View File

@ -13,7 +13,11 @@ const api_test = {
family: 4, family: 4,
}) })
requestObj.promise = requestObj.promise.then(({ body }) => { requestObj.promise = requestObj.promise.then(({ body }) => {
return body.code === 0 ? Promise.resolve({ type, url: body.data }) : Promise.reject(new Error(requestMsg.fail)) switch (body.code) {
case 0: return Promise.resolve({ type, url: body.data })
case 429: return Promise.reject(new Error(requestMsg.tooManyRequests))
default: return Promise.reject(new Error(requestMsg.fail))
}
}) })
return requestObj return requestObj
}, },

View File

@ -1,4 +1,5 @@
import { httpFetch } from '../../request' import { httpFetch } from '../../request'
import { requestMsg } from '../../message'
import { headers, timeout } from '../options' import { headers, timeout } from '../options'
import { dnsLookup } from '../utils' import { dnsLookup } from '../utils'
@ -12,7 +13,11 @@ const api_temp = {
family: 4, family: 4,
}) })
requestObj.promise = requestObj.promise.then(({ body }) => { requestObj.promise = requestObj.promise.then(({ body }) => {
return body.code === 0 ? Promise.resolve({ type, url: body.data }) : Promise.reject(new Error(body.msg)) switch (body.code) {
case 0: return Promise.resolve({ type, url: body.data })
case 429: return Promise.reject(new Error(requestMsg.tooManyRequests))
default: return Promise.reject(new Error(body.msg))
}
}) })
return requestObj return requestObj
}, },

View File

@ -24,7 +24,11 @@ const api_test = {
family: 4, family: 4,
}) })
requestObj.promise = requestObj.promise.then(({ body }) => { requestObj.promise = requestObj.promise.then(({ body }) => {
return body.code === 0 ? Promise.resolve({ type, url: body.data }) : Promise.reject(new Error(requestMsg.fail)) switch (body.code) {
case 0: return Promise.resolve({ type, url: body.data })
case 429: return Promise.reject(new Error(requestMsg.tooManyRequests))
default: return Promise.reject(new Error(requestMsg.fail))
}
}) })
return requestObj return requestObj
}, },

View File

@ -13,7 +13,11 @@ const api_test = {
family: 4, family: 4,
}) })
requestObj.promise = requestObj.promise.then(({ body }) => { requestObj.promise = requestObj.promise.then(({ body }) => {
return body.code === 0 ? Promise.resolve({ type, url: body.data }) : Promise.reject(new Error(requestMsg.fail)) switch (body.code) {
case 0: return Promise.resolve({ type, url: body.data })
case 429: return Promise.reject(new Error(requestMsg.tooManyRequests))
default: return Promise.reject(new Error(requestMsg.fail))
}
}) })
return requestObj return requestObj
}, },

View File

@ -13,7 +13,11 @@ const api_messoer = {
family: 4, family: 4,
}) })
requestObj.promise = requestObj.promise.then(({ body }) => { requestObj.promise = requestObj.promise.then(({ body }) => {
return body.code === 0 ? Promise.resolve({ type, url: body.data }) : Promise.reject(new Error(requestMsg.fail)) switch (body.code) {
case 0: return Promise.resolve({ type, url: body.data })
case 429: return Promise.reject(new Error(requestMsg.tooManyRequests))
default: return Promise.reject(new Error(requestMsg.fail))
}
}) })
return requestObj return requestObj
}, },

View File

@ -13,7 +13,11 @@ const api_test = {
family: 4, family: 4,
}) })
requestObj.promise = requestObj.promise.then(({ body }) => { requestObj.promise = requestObj.promise.then(({ body }) => {
return body.code === 0 ? Promise.resolve({ type, url: body.data }) : Promise.reject(new Error(requestMsg.fail)) switch (body.code) {
case 0: return Promise.resolve({ type, url: body.data })
case 429: return Promise.reject(new Error(requestMsg.tooManyRequests))
default: return Promise.reject(new Error(requestMsg.fail))
}
}) })
return requestObj return requestObj
}, },