From e9bc6a572b1991610173fdc8d696e18386a1e952 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Wed, 16 Sep 2026 23:27:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=93=E5=BC=80=E6=9F=90?= =?UTF-8?q?=E4=BA=9B=20kg=20=E6=AD=8C=E5=8D=95=E6=97=B6=E6=AD=8C=E6=9B=B2?= =?UTF-8?q?=E4=B8=A2=E5=A4=B1=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 | 4 ++ src/renderer/utils/musicSdk/kg/songList.js | 69 +++++++++++++++++++--- 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index 1a073c23..2de9e1e6 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -6,3 +6,7 @@ Any Listen 的项目地址为 https://github.com/any-listen/any-listen ### 优化 - 优化 tx 推荐歌单列表 + +### 修复 + +- 修复打开某些 kg 歌单时歌曲丢失的问题 diff --git a/src/renderer/utils/musicSdk/kg/songList.js b/src/renderer/utils/musicSdk/kg/songList.js index 9a6a4a2a..fa3ff1d0 100644 --- a/src/renderer/utils/musicSdk/kg/songList.js +++ b/src/renderer/utils/musicSdk/kg/songList.js @@ -384,8 +384,10 @@ export default { }, }) if (!songInfo.list) { - if (songInfo.global_collection_id) return this.getUserListDetail2(songInfo.global_collection_id) - else return this.getUserListDetail4(songInfo, chain, page).catch(() => this.getUserListDetail5(chain)) + if (songInfo.global_collection_id) { + return this.getListDetailByGcidChain(songInfo.global_collection_id, chain) + .catch(() => this.getUserListDetail2(songInfo.global_collection_id)) + } else return this.getUserListDetail4(songInfo, chain, page).catch(() => this.getUserListDetail5(chain)) } let list = await this.getMusicInfos(songInfo.list) // console.log(info, songInfo) @@ -490,6 +492,53 @@ export default { } return Promise.all(tasks).then(([...datas]) => datas.flat()) }, + async getListDetailByGcidChain(id, chain) { + const params = 'srcappid=2919&clientver=20000&clienttime=1789566751657&mid=1789566751657&uuid=1789566751657&dfid=-&listid=15&type=0&pagesize=50&global_collection_id=' + id + '&page=1&share_type=collect&appid=1058&chain=' + chain + const data = await this.createHttp(`https://m3ws.kugou.com/v2/zlist/list?${params}&signature=${signatureParams(params, 'web')}`, { + headers: { + mid: '1586163263991', + Referer: 'https://m3ws.kugou.com/share/index.php', + 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1', + dfid: '-', + clienttime: '1586163263991', + }, + }) + const info = data.info[0] + if (!info) throw new Error('get list error') + let tasks = [Promise.resolve(data.list.info)] + let page = 1 + let totalPage = Math.ceil(info.count / 50) + while (page < totalPage) { + const limit = 50 + page += 1 + const params = 'srcappid=2919&clientver=20000&clienttime=1789566751657&mid=1789566751657&uuid=1789566751657&dfid=-&listid=15&type=0&pagesize=' + limit + '&global_collection_id=' + id + '&page=' + page + '&share_type=collect&appid=1058&chain=' + chain + tasks.push(this.createHttp(`https://m3ws.kugou.com/v2/zlist/list?${params}&signature=${signatureParams(params, 'web')}`, { + headers: { + mid: '1586163263991', + Referer: 'https://m3ws.kugou.com/share/index.php', + 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1', + dfid: '-', + clienttime: '1586163263991', + }, + }).then(data => data.list.info)) + } + const hashs = await Promise.all(tasks).then(([...datas]) => datas.flat()) + let list = await this.getMusicInfos(hashs) + return { + list, + page: 1, + limit: this.listDetailLimit, + total: info.count, + source: 'kg', + info: { + name: info.name, + img: info.pic && info.pic.replace('{size}', 240), + desc: info.intro, + author: info.list_create_username, + // play_count: formatPlayCount(info.playcount), + }, + } + }, async getUserListDetail2(global_collection_id) { let id = global_collection_id if (id.length > 1000) throw new Error('get list error') @@ -613,7 +662,10 @@ export default { async getUserListDetail(link, page, retryNum = 0) { if (retryNum > 3) return Promise.reject(new Error('link try max num')) if (link.includes('#')) link = link.replace(/#.*$/, '') - if (link.includes('global_collection_id')) return this.getUserListDetail2(link.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1')) + if (link.includes('global_collection_id') && link.includes('chain')) { + return this.getListDetailByGcidChain(link.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1'), link.replace(/^.*?chain=(\w+)(?:&.*$|#.*$|$)/, '$1')) + } + if (link.includes('chain=')) return this.getUserListDetail3(link.replace(/^.*?chain=(\w+)(?:&.*$|#.*$|$)/, '$1'), page) if (link.includes('gcid_')) { let gcid = link.match(/gcid_\w+/)?.[0] if (gcid) { @@ -621,7 +673,6 @@ export default { if (global_collection_id) return this.getUserListDetail2(global_collection_id) } } - if (link.includes('chain=')) return this.getUserListDetail3(link.replace(/^.*?chain=(\w+)(?:&.*$|#.*$|$)/, '$1'), page) if (link.includes('.html')) { if (link.includes('zlist.html')) { link = link.replace(/^(.*)zlist\.html/, 'https://m3ws.kugou.com/zlist/list') @@ -632,6 +683,7 @@ export default { } } else if (!link.includes('song.html')) return this.getUserListDetail3(link.replace(/.+\/(\w+).html(?:\?.*|&.*$|#.*$|$)/, '$1'), page) } + if (link.includes('global_collection_id')) return this.getUserListDetail2(link.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1')) const requestObj_listDetailLink = httpFetch(link, { headers: { @@ -643,16 +695,18 @@ export default { // console.log(body, location) if (statusCode > 400) return this.getUserListDetail(link, page, ++retryNum) if (location) { + if (location.includes('global_collection_id') && location.includes('chain')) { + return this.getListDetailByGcidChain(location.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1'), location.replace(/^.*?chain=(\w+)(?:&.*$|#.*$|$)/, '$1')) + } // console.log(location) - if (location.includes('global_collection_id')) return this.getUserListDetail2(location.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1')) + if (location.includes('chain=')) return this.getUserListDetail3(location.replace(/^.*?chain=(\w+)(?:&.*$|#.*$|$)/, '$1'), page) if (location.includes('gcid_')) { - let gcid = link.match(/gcid_\w+/)?.[0] + let gcid = location.match(/gcid_\w+/)?.[0] if (gcid) { const global_collection_id = await this.decodeGcid(gcid) if (global_collection_id) return this.getUserListDetail2(global_collection_id) } } - if (location.includes('chain=')) return this.getUserListDetail3(location.replace(/^.*?chain=(\w+)(?:&.*$|#.*$|$)/, '$1'), page) if (location.includes('.html')) { if (location.includes('zlist.html')) { let link = location.replace(/^(.*)zlist\.html/, 'https://m3ws.kugou.com/zlist/list') @@ -664,6 +718,7 @@ export default { return this.getUserListDetail(link, page, ++retryNum) } else return this.getUserListDetail3(location.replace(/.+\/(\w+).html(?:\?.*|&.*$|#.*$|$)/, '$1'), page) } + if (location.includes('global_collection_id')) return this.getUserListDetail2(location.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1')) // console.log('location', location) return this.getUserListDetail(location, page, ++retryNum) }