diff --git a/publish/changeLog.md b/publish/changeLog.md index f308c879..a1408a96 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -14,6 +14,7 @@ - 修复修改列表名时无法使用`Ctrl`键的问题 - 修复wy源某些歌曲获取歌词翻译的问题处理 - 修复下载功能的歌词换源时会进入死循环的问题 +- 修复某些歌曲无法下载的问题 ### 其他 diff --git a/src/renderer/store/modules/download.js b/src/renderer/store/modules/download.js index 3d0a8fb4..00c64d3f 100644 --- a/src/renderer/store/modules/download.js +++ b/src/renderer/store/modules/download.js @@ -439,6 +439,14 @@ const actions = { dispatch('startTask') return } + if (err.message?.startsWith('Resume failed')) { + fs.unlink(downloadInfo.metadata.filePath, err => { + if (err) return commit('onError', { downloadInfo, errorMsg: '删除不匹配的文件失败:' + err.message }) + dls[downloadInfo.key].start() + commit('setStatusText', { downloadInfo, text: '正在重试' }) + }) + return + } if (err.code == 'ENOTFOUND') { commit('onError', { downloadInfo, errorMsg: '链接失效' }) refreshUrl.call(_this, commit, downloadInfo, rootState.setting.download.isUseOtherSource) @@ -562,6 +570,7 @@ const actions = { filePath: path.join(rootState.setting.download.savePath, downloadInfo.metadata.fileName), }) dl.updateSaveInfo(rootState.setting.download.savePath, downloadInfo.metadata.fileName) + if (tryNum[downloadInfo.key]) tryNum[downloadInfo.key] = 0 try { await dl.start() } catch (error) { diff --git a/src/renderer/utils/download/Downloader.js b/src/renderer/utils/download/Downloader.js index 1dc2e7fb..414f23fa 100644 --- a/src/renderer/utils/download/Downloader.js +++ b/src/renderer/utils/download/Downloader.js @@ -153,7 +153,7 @@ class Task extends EventEmitter { __initDownload(response) { this.progress.total = parseInt(response.headers['content-length'] || 0) let options = {} - let isResumable = this.options.forceResume || response.headers['accept-ranges'] !== 'none' + let isResumable = this.options.forceResume || response.headers['accept-ranges'] !== 'none' || (typeof response.headers['accept-ranges'] == 'string' && parseInt(response.headers['accept-ranges'].replace(/^bytes=(\d+)/, '$1')) > 0) if (isResumable) { options.flags = 'a' if (this.progress.downloaded) this.progress.total -= 10 @@ -227,8 +227,9 @@ class Task extends EventEmitter { if (this.resumeLastChunk) { chunk = this.__handleDiffChunk(chunk) if (!chunk) { - this.__handleError(new Error('Resume failed, response chunk does not match.')) - this.stop() + this.__handleStop().finally(() => { + this.__handleError(new Error('Resume failed, response chunk does not match.')) + }) return } }