From 809fccec56d1f394c10e81fecdef3f9b93382763 Mon Sep 17 00:00:00 2001 From: Folltoshe Date: Sun, 16 Apr 2023 21:11:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=AF=BC=E5=85=A5kg=E6=A6=82?= =?UTF-8?q?=E5=BF=B5=E7=89=88=E6=AD=8C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/utils/musicSdk/kg/songList.js | 92 ++++++---------------- 1 file changed, 26 insertions(+), 66 deletions(-) diff --git a/src/renderer/utils/musicSdk/kg/songList.js b/src/renderer/utils/musicSdk/kg/songList.js index 0dbc893f..4b965e77 100644 --- a/src/renderer/utils/musicSdk/kg/songList.js +++ b/src/renderer/utils/musicSdk/kg/songList.js @@ -58,65 +58,22 @@ export default { 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; HLK-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Mobile Safari/537.36 EdgA/104.0.1293.70', }, }).promise.then(({ body }) => { - // console.log(body) - if (!body.data.global_specialid) Promise.reject(new Error('Failed to get global collection id.')) + if (!body.data.global_specialid) return Promise.reject(new Error('Failed to get global collection id.')) return body.data.global_specialid }) }, - // async getListInfoBySpecialId(special_id, retry = 0) { - // if (++retry > 2) throw new Error('failed') - // return httpFetch(`https://m.kugou.com/plist/list/${special_id}/?json=true`, { - // headers: { - // 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; HLK-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Mobile Safari/537.36 EdgA/104.0.1293.70', - // }, - // follow_max: 2, - // }).promise.then(({ body }) => { - // // console.log(body) - // if (!body.info.list) return this.getListInfoBySpecialId(special_id, retry) - // let listinfo = body.info.list - // return { - // listInfo: { - // name: listinfo.specialname, - // image: listinfo.imgurl.replace('{size}', '150'), - // intro: listinfo.intro, - // author: listinfo.nickname, - // playcount: listinfo.playcount, - // total: listinfo.songcount, - // }, - // globalSpecialId: listinfo.global_specialid, - // } - // }) - // }, - // async getSongListDetailByGlobalSpecialId(id, page, limit = 100, retry = 0) { - // if (++retry > 2) throw new Error('failed') - // console.log(id) - // const params = `specialid=0&need_sort=1&module=CloudMusic&clientver=11409&pagesize=${limit}&global_collection_id=${id}&userid=0&page=${page}&type=1&area_code=1&appid=1005` - // return httpFetch(`http://pubsongscdn.tx.kugou.com/v2/get_other_list_file?${params}&signature=${signatureParams(params)}`).promise.then(({ body }) => { - // // console.log(body) - // if (body.data?.info == null) return this.getSongListDetailByGlobalSpecialId(id, page, limit, retry) - // return body.data.info - // }) - // }, - async getListDetailBySpecialId(id) { - const globalSpecialId = await this.getGlobalSpecialId(id) - // const limit = 100 - // const listData = await this.getSongListDetailByGlobalSpecialId(globalSpecialId, page, limit) - // if (!Array.isArray(listData)) - return this.getUserListDetail2(globalSpecialId) - // return { - // list: this.filterDatav9(listData), - // page, - // limit, - // total: listInfo.total, - // source: 'kg', - // info: { - // name: listInfo.name, - // img: listInfo.image, - // desc: listInfo.intro, - // author: listInfo.author, - // play_count: this.formatPlayCount(listInfo.playcount), - // }, - // } + async getLiteGlobalCollectionId(url) { + return httpFetch(url, { + headers: { + 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; HLK-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Mobile Safari/537.36 EdgA/104.0.1293.70', + }, + follow_max: 0, + }).promise.then(({ headers }) => { + if (!headers.location) return Promise.reject(new Error('Failed to get lite global collection id.')) + const gid = headers.location.replace(/^.*?global_specialid=(\w+)(?:&.*$|#.*$|$)/, '$1') + if (!gid) return Promise.reject(new Error('Failed to get lite global collection id.')) + return gid + }) }, getInfoUrl(tagId) { return tagId @@ -127,9 +84,6 @@ export default { if (tagId == null) tagId = '' return `http://www2.kugou.kugou.com/yueku/v9/special/getSpecial?is_ajax=1&cdn=cdn&t=${sortId}&c=${tagId}&p=${page}` }, - // getSongListDetailUrl(id) { - // return `http://www2.kugou.kugou.com/yueku/v9/special/single/${id}-5-9999.html` - // }, /** * 格式化播放数量 @@ -299,7 +253,7 @@ export default { default: break } - if (info.global_collection_id) return this.getUserListDetail2(info.global_collection_id) + if (info.global_collection_id) return this.getUserListDetailByGid(info.global_collection_id) if (info.userid != null) { songList = await this.createHttp('http://www2.kugou.kugou.com/apps/kucodeAndShare/app/', { method: 'POST', @@ -336,7 +290,7 @@ export default { }, }) if (!songInfo.list) { - if (songInfo.global_collection_id) return this.getUserListDetail2(songInfo.global_collection_id) + if (songInfo.global_collection_id) return this.getUserListDetailByGid(songInfo.global_collection_id) else return this.getUserListDetail4(songInfo, chain, page).catch(() => this.getUserListDetail5(chain)) } let result = await Promise.all(this.createTask(songInfo.list.map(item => ({ hash: item.hash })))).then(([...datas]) => datas.flat()) @@ -420,7 +374,7 @@ export default { } return Promise.all(tasks).then(([...datas]) => datas.flat()) }, - async getUserListDetail2(global_collection_id) { + async getUserListDetailByGid(global_collection_id) { let id = global_collection_id if (id.length > 1000) throw new Error('get list error') const params = 'appid=1058&specialid=0&global_specialid=' + id + '&format=jsonp&srcappid=2919&clientver=20000&clienttime=1586163242519&mid=1586163242519&uuid=1586163242519&dfid=-' @@ -543,7 +497,7 @@ 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')) return this.getUserListDetailByGid(link.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1')) if (link.includes('chain=')) return this.getUserListDetail3(link.replace(/^.*?chain=(\w+)(?:&.*$|#.*$|$)/, '$1'), page) if (link.includes('.html')) { if (link.includes('zlist.html')) { @@ -567,7 +521,7 @@ export default { if (statusCode > 400) return this.getUserListDetail(link, page, ++retryNum) if (location) { // console.log(location) - if (location.includes('global_collection_id')) return this.getUserListDetail2(location.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1')) + if (location.includes('global_collection_id')) return this.getUserListDetailByGid(location.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1')) if (location.includes('chain=')) return this.getUserListDetail3(location.replace(/^.*?chain=(\w+)(?:&.*$|#.*$|$)/, '$1'), page) if (location.includes('.html')) { if (location.includes('zlist.html')) { @@ -583,16 +537,22 @@ export default { // console.log('location', location) return this.getUserListDetail(location, page, ++retryNum) } - if (typeof body == 'string') return this.getUserListDetail2(body.replace(/^[\s\S]+?"global_collection_id":"(\w+)"[\s\S]+?$/, '$1')) + if (typeof body == 'string') return this.getUserListDetailByGid(body.replace(/^[\s\S]+?"global_collection_id":"(\w+)"[\s\S]+?$/, '$1')) if (body.errcode !== 0) return this.getUserListDetail(link, page, ++retryNum) return this.getUserListDetailByLink(body, link) }, + async getLiteListDetail(url) { + const id = await this.getLiteGlobalCollectionId(url) + return this.getUserListDetailByGid(id) + }, async getListDetail(id, page) { // 获取歌曲列表内的音乐 id = id.toString() if (id.includes('special/single/')) { id = id.replace(this.regExps.listDetailLink, '$1') } else if (/https?:/.test(id)) { + // 酷狗概念版 https://t1.kugou.com/gfX9973BaV2 + if (id.includes('t1.kugou.com')) return this.getLiteListDetail(id) // fix https://www.kugou.com/songlist/xxx/?uid=xxx&chl=qq_client&cover=http%3A%2F%2Fimge.kugou.com%xxx.jpg&iszlist=1 return this.getUserListDetail(id.replace(/^.*?http/, 'http'), page) } else if (/^\d+$/.test(id)) { @@ -602,7 +562,7 @@ export default { } // if ((/[?&:/]/.test(id))) id = id.replace(this.regExps.listDetailLink, '$1') - return this.getListDetailBySpecialId(id, page) + return this.getListDetailBySpecialId(id) }, filterData(rawList) { // console.log(rawList)