From a363c5525b2b2608059ac6db7d87f8aa40beb0df Mon Sep 17 00:00:00 2001 From: lyswhut Date: Fri, 11 Mar 2022 12:02:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BD=BF=E7=94=A8=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E5=AF=BC=E5=85=A5=E7=9A=84=E6=AD=8C=E5=8D=95=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=9C=A8=E6=88=91=E7=9A=84=E5=88=97=E8=A1=A8=E6=89=93?= =?UTF-8?q?=E5=BC=80=E5=8E=9F=E6=AD=8C=E5=8D=95=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 1 + src/renderer/utils/music/kg/songList.js | 5 +++- src/renderer/utils/music/kw/songList.js | 3 ++- src/renderer/utils/music/mg/songList.js | 5 ++++ src/renderer/utils/music/tx/songList.js | 18 ++++++++----- src/renderer/utils/music/wy/songList.js | 26 +++++++++++++------ .../views/list/components/MyLists.vue | 6 ++--- 7 files changed, 45 insertions(+), 19 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index 15431e8d..a98a5103 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -16,6 +16,7 @@ - 修复桌面歌词没有处理停止播放状态的问题 - 修复AppImage包无法运行的问题 - 修复Windows任务栏缩略图工具栏控制按钮的歌曲收藏按钮状态更新问题 +- 修复使用链接导入的歌单无法在我的列表打开原歌单详情页的问题 ### 文档 diff --git a/src/renderer/utils/music/kg/songList.js b/src/renderer/utils/music/kg/songList.js index f4c008b4..53f8d8e7 100644 --- a/src/renderer/utils/music/kg/songList.js +++ b/src/renderer/utils/music/kg/songList.js @@ -720,7 +720,10 @@ export default { }, getDetailPageUrl(id) { - if (typeof id == 'string') id = id.replace('id_', '') + if (typeof id == 'string') { + if (/^https?:\/\//.test(id)) return id + id = id.replace('id_', '') + } return `https://www.kugou.com/yy/special/single/${id}.html` }, } diff --git a/src/renderer/utils/music/kw/songList.js b/src/renderer/utils/music/kw/songList.js index e15e0cd4..3bd144dc 100644 --- a/src/renderer/utils/music/kw/songList.js +++ b/src/renderer/utils/music/kw/songList.js @@ -308,7 +308,8 @@ export default { return Promise.all([this.getTag(), this.getHotTag()]).then(([tags, hotTag]) => ({ tags, hotTag, source: 'kw' })) }, getDetailPageUrl(id) { - if (/^digest-/.test(id)) { + if ((/[?&:/]/.test(id))) id = id.replace(this.regExps.listDetailLink, '$1') + else if (/^digest-/.test(id)) { let result = id.split('__') id = result[1] } diff --git a/src/renderer/utils/music/mg/songList.js b/src/renderer/utils/music/mg/songList.js index 72ac1d09..63b5271a 100644 --- a/src/renderer/utils/music/mg/songList.js +++ b/src/renderer/utils/music/mg/songList.js @@ -357,6 +357,11 @@ export default { }, getDetailPageUrl(id) { + if (/playlist\/index\.html\?/.test(id)) { + id = id.replace(/.*(?:\?|&)id=(\d+)(?:&.*|$)/, '$1') + } else if (this.regExps.listDetailLink.test(id)) { + id = id.replace(this.regExps.listDetailLink, '$1') + } return `https://music.migu.cn/v3/music/playlist/${id}` }, } diff --git a/src/renderer/utils/music/tx/songList.js b/src/renderer/utils/music/tx/songList.js index abebf341..9fe888c0 100644 --- a/src/renderer/utils/music/tx/songList.js +++ b/src/renderer/utils/music/tx/songList.js @@ -185,11 +185,7 @@ export default { return location == null ? link : location }, - // 获取歌曲列表内的音乐 - async getListDetail(id, tryNum = 0) { - if (this._requestObj_listDetail) this._requestObj_listDetail.cancelHttp() - if (tryNum > 2) return Promise.reject(new Error('try max num')) - + async getListId(id) { if ((/[?&:/]/.test(id))) { let regx = /\/\/i\.y\.qq\.com/.test(id) ? this.regExps.listDetailLink1 : this.regExps.listDetailLink2 if (!regx.test(id)) { @@ -200,6 +196,14 @@ export default { id = id.replace(regx, '$1') // console.log(id) } + return id + }, + // 获取歌曲列表内的音乐 + async getListDetail(id, tryNum = 0) { + if (this._requestObj_listDetail) this._requestObj_listDetail.cancelHttp() + if (tryNum > 2) return Promise.reject(new Error('try max num')) + + id = await this.getListId(id) this._requestObj_listDetail = httpFetch(this.getListDetailUrl(id), { headers: { @@ -293,7 +297,9 @@ export default { return Promise.all([this.getTag(), this.getHotTag()]).then(([tags, hotTag]) => ({ tags, hotTag, source: 'tx' })) }, - getDetailPageUrl(id) { + async getDetailPageUrl(id) { + id = await this.getListId(id) + return `https://y.qq.com/n/ryqq/playlist/${id}` }, } diff --git a/src/renderer/utils/music/wy/songList.js b/src/renderer/utils/music/wy/songList.js index b8b3c051..50bf137e 100644 --- a/src/renderer/utils/music/wy/songList.js +++ b/src/renderer/utils/music/wy/songList.js @@ -51,23 +51,24 @@ export default { async handleParseId(link, retryNum = 0) { if (this._requestObj_listDetailLink) this._requestObj_listDetailLink.cancelHttp() - if (retryNum > 2) return Promise.reject(new Error('link try max num')) + if (retryNum > 2) throw new Error('link try max num') this._requestObj_listDetailLink = httpFetch(link) const { headers: { location }, statusCode } = await this._requestObj_listDetailLink.promise // console.log(headers) if (statusCode > 400) return this.handleParseId(link, ++retryNum) - return location == null ? link : location + const url = location == null ? link : location + return this.regExps.listDetailLink.test(url) + ? url.replace(this.regExps.listDetailLink, '$1') + : url.replace(this.regExps.listDetailLink2, '$1') }, - async getListDetail(id, page, tryNum = 0) { // 获取歌曲列表内的音乐 - if (this._requestObj_listDetail) this._requestObj_listDetail.cancelHttp() - if (tryNum > 2) return Promise.reject(new Error('try max num')) - + async getListId(id) { + let cookie if (/###/.test(id)) { const [url, token] = id.split('###') id = url - this.cookie = `MUSIC_U=${token}` + cookie = `MUSIC_U=${token}` } if ((/[?&:/]/.test(id))) { if (this.regExps.listDetailLink.test(id)) { @@ -79,6 +80,14 @@ export default { } // console.log(id) } + return { id, cookie } + }, + async getListDetail(rawId, page, tryNum = 0) { // 获取歌曲列表内的音乐 + if (this._requestObj_listDetail) this._requestObj_listDetail.cancelHttp() + if (tryNum > 2) return Promise.reject(new Error('try max num')) + + const { id, cookie } = await this.getListId(rawId) + if (cookie) this.cookie = cookie this._requestObj_listDetail = httpFetch('https://music.163.com/api/linux/forward', { method: 'post', @@ -290,7 +299,8 @@ export default { return Promise.all([this.getTag(), this.getHotTag()]).then(([tags, hotTag]) => ({ tags, hotTag, source: 'wy' })) }, - getDetailPageUrl(id) { + async getDetailPageUrl(rawId) { + const { id } = await this.getListId(rawId) return `https://music.163.com/#/playlist?id=${id}` }, } diff --git a/src/renderer/views/list/components/MyLists.vue b/src/renderer/views/list/components/MyLists.vue index 733ec502..8cfdf80f 100644 --- a/src/renderer/views/list/components/MyLists.vue +++ b/src/renderer/views/list/components/MyLists.vue @@ -406,15 +406,15 @@ export default { } return false }, - openSourceDetailPage(index) { + async openSourceDetailPage(index) { const { source, sourceListId } = this.userLists[index] if (!sourceListId) return let url if (/board__/.test(sourceListId)) { const id = sourceListId.replace(/board__/, '') url = musicSdk[source].leaderboard.getDetailPageUrl(id) - } else { - url = musicSdk[source].songList.getDetailPageUrl(sourceListId) + } else if (musicSdk[source].songList?.getDetailPageUrl) { + url = await musicSdk[source].songList.getDetailPageUrl(sourceListId) } if (!url) return openUrl(url)