From 254b82cc602d7ea56f5b33cd3bc78888fa455432 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Thu, 7 Oct 2021 20:01:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dkg=E6=BA=90=E7=9A=84=E6=AD=8C?= =?UTF-8?q?=E5=8D=95=E9=93=BE=E6=8E=A5=E6=97=A0=E6=B3=95=E6=89=93=E5=BC=80?= =?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 --- .eslintrc | 3 +- publish/changeLog.md | 4 + src/renderer/utils/music/kg/songList.js | 102 +++++++++++++++++- .../utils/music/kg/vendors/infSign.min.js | 2 + 4 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 src/renderer/utils/music/kg/vendors/infSign.min.js diff --git a/.eslintrc b/.eslintrc index 1e8ebba0..c4483315 100644 --- a/.eslintrc +++ b/.eslintrc @@ -22,5 +22,6 @@ }, "settings": { "html/html-extensions": [".html", ".vue"] - } + }, + "ignorePatterns": ["vendors", "*.min.js"] } diff --git a/publish/changeLog.md b/publish/changeLog.md index e3967bd7..5a2e19fa 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -5,3 +5,7 @@ ### 优化 - 优化列表同步代码逻辑 + +### 修复 + +- 修复kg源的歌单链接无法打开的问题 diff --git a/src/renderer/utils/music/kg/songList.js b/src/renderer/utils/music/kg/songList.js index fc20d4aa..825e4527 100644 --- a/src/renderer/utils/music/kg/songList.js +++ b/src/renderer/utils/music/kg/songList.js @@ -1,6 +1,17 @@ import { httpFetch } from '../../request' import { decodeName, formatPlayTime, sizeFormate } from '../../index' import { toMD5 } from '../utils' +import infSign from './vendors/infSign.min' + +const handleSignature = (id, page, limit) => new Promise((resolve, reject) => { + infSign({ appid: 1058, type: 0, module: 'playlist', page, pagesize: limit, specialid: id }, null, { + useH5: !0, + isCDN: !0, + callback(i) { + resolve(i.signature) + }, + }) +}) export default { _requestObj_tags: null, @@ -35,6 +46,7 @@ export default { id: '8', }, ], + cache: new Map(), regExps: { listData: /global\.data = (\[.+\]);/, listInfo: /global = {[\s\S]+?name: "(.+)"[\s\S]+?pic: "(.+)"[\s\S]+?};/, @@ -249,7 +261,7 @@ export default { }) if (!songInfo.list) { if (songInfo.global_collection_id) return this.getUserListDetail2(songInfo.global_collection_id) - else throw new Error('fail') + 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()) // console.log(info, songInfo) @@ -362,6 +374,94 @@ export default { } }, + async getListInfoByChain(chain) { + if (this.cache.has(chain)) return this.cache.get(chain) + const { body } = await httpFetch(`https://m.kugou.com/share/?chain=${chain}&id=${chain}`, { + headers: { + 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1', + }, + }).promise + let result = body.match(/var\sphpParam\s=\s({.+?});/) + if (result) result = JSON.parse(result[1]) + this.cache.set(chain, result) + return result + }, + + async getUserListDetailByPcChain(chain) { + let key = `${chain}_pc_list` + if (this.cache.has(key)) return this.cache.get(key) + const { body } = await httpFetch(`http://www.kugou.com/share/${chain}.html`, { + headers: { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36', + }, + }).promise + let result = body.match(/var\sdataFromSmarty\s=\s(\[.+?\])/) + if (result) result = JSON.parse(result[1]) + this.cache.set(chain, result) + result = await Promise.all(this.createTask(result.map(item => ({ hash: item.hash })))).then(([...datas]) => datas.flat()) + // console.log(info, songInfo) + return this.filterData2(result) + }, + + async getUserListDetail4(songInfo, chain, page) { + const limit = 100 + const [listInfo, list] = await Promise.all([ + this.getListInfoByChain(chain), + this.getUserListDetailById(songInfo.id, page, limit), + ]) + return { + list: list || [], + page, + limit, + total: listInfo.songcount, + source: 'kg', + info: { + name: listInfo.specialname, + img: listInfo.imgurl && listInfo.imgurl.replace('{size}', 240), + // desc: body.result.info.list_desc, + author: listInfo.nickname, + // play_count: this.formatPlayCount(info.count), + }, + } + }, + + async getUserListDetail5(chain) { + const [listInfo, list] = await Promise.all([ + this.getListInfoByChain(chain), + this.getUserListDetailByPcChain(chain), + ]) + return { + list: list || [], + page: 1, + limit: this.listDetailLimit, + total: listInfo.songcount, + source: 'kg', + info: { + name: listInfo.specialname, + img: listInfo.imgurl && listInfo.imgurl.replace('{size}', 240), + // desc: body.result.info.list_desc, + author: listInfo.nickname, + // play_count: this.formatPlayCount(info.count), + }, + } + }, + + async getUserListDetailById(id, page, limit) { + const signature = await handleSignature(id, page, limit) + let info = await this.createHttp(`https://pubsongscdn.kugou.com/v2/get_other_list_file?srcappid=2919&clientver=20000&appid=1058&type=0&module=playlist&page=${page}&pagesize=${limit}&specialid=${id}&signature=${signature}`, { + headers: { + 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: '-', + }, + }) + + // console.log(info) + let result = await Promise.all(this.createTask(info.info.map(item => ({ hash: item.hash })))).then(([...datas]) => datas.flat()) + // console.log(info, songInfo) + return this.filterData2(result) + }, + async getUserListDetail(link, page, retryNum = 0) { if (retryNum > 3) return Promise.reject(new Error('link try max num')) if (link.includes('#')) link = link.replace(/#.*$/, '') diff --git a/src/renderer/utils/music/kg/vendors/infSign.min.js b/src/renderer/utils/music/kg/vendors/infSign.min.js new file mode 100644 index 00000000..7b817758 --- /dev/null +++ b/src/renderer/utils/music/kg/vendors/infSign.min.js @@ -0,0 +1,2 @@ +!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t=t||self,t.infSign=n())}(this,function(){"use strict";function t(t,n,r){return n in t?Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[n]=r,t}function n(t,n){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(t);n&&(e=e.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),r.push.apply(r,e)}return r}function r(r){for(var e=1;e0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=!1,c=!1,a="json",l=r({},n),u=s.isInClient();"function"==typeof o?t=o:(t=o.callback,i=o.useH5||!1,a=o.postType||"json",c=o.isCDN||!1),e&&("[object Object]"!=Object.prototype.toString.call(e)?u=!1:"urlencoded"==a&&(u=!1));var f=function(){var n=(new Date).getTime(),i=[],s=[],u="NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt",f={srcappid:"2919",clientver:"20000",clienttime:n,mid:n,uuid:n,dfid:"-"};c&&(delete f.clienttime,delete f.mid,delete f.uuid,delete f.dfid),l=r({},f,{},l);for(var g in l)i.push(g);if(i.sort(),i.forEach(function(t){s.push(t+"="+l[t])}),e)if("[object Object]"==Object.prototype.toString.call(e))if("json"==a)s.push(JSON.stringify(e));else{var b=[];for(var g in e)b.push(g+"="+e[g]);s.push(b.join("&"))}else s.push(e);s.unshift(u),s.push(u),l.signature=d(s.join("")),o.log&&(console.log("H5签名前参数",s),console.log("H5签名后返回",l)),e?t&&t(l,"[object Object]"==Object.prototype.toString.call(e)&&"json"==a?JSON.stringify(e):e):t&&t(l)};if(u&&!i){var g=!1;s.mobileCall(764,{get:l,post:e},function(n){return!g&&(g=!0,n&&n.status?(delete n.status,o.log&&(console.log("客户端签名前参数",{get:l,post:e}),console.log("客户端签名后返回",r({},l,{},n))),l=r({},l,{},n),e?t&&t(l,"[object Object]"==Object.prototype.toString.call(e)&&"json"==a?JSON.stringify(e):e):t&&t(l),!1):(u=!1,void f()))})}else u=!1,f()}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var s=e(function(t,n){!function(n,r){t.exports=function(){var t={str2Json:function(t){var n={};if("[object String]"===Object.prototype.toString.call(t))try{n=JSON.parse(t)}catch(t){n={}}return n},json2Str:function(t){var n=t;if("string"!=typeof t)try{n=JSON.stringify(t)}catch(t){n=""}return n},_extend:function(t,n){if(n)for(var r in t)n.hasOwnProperty(r)||(n[r]=t[r]);return n},formatURL:{browser:"",url:""},formatSong:{filename:"",filesize:"",hash:"",bitrate:"",extname:"",duration:"",mvhash:"",m4afilesize:"","320hash":"","320filesize":"",sqhash:"",sqfilesize:0,feetype:0,isfirst:0},formatMV:{filename:"",singername:"",hash:"",imgurl:""},formatShare:{shareName:"",topicName:"",hash:"",listID:"",type:"",suid:"",slid:"",imgUrl:"",filename:"",duration:"",shareData:{linkUrl:"",picUrl:"",content:"",title:""}},cbNum:0,isIOS:!!navigator.userAgent.match(/KGBrowser/gi),isKugouAndroid:!!navigator.userAgent.match(/kugouandroid/gi),isAndroid:"undefined"!=typeof external&&void 0!==external.superCall,loadUrl:function(t){var n=document.createElement("iframe");n.setAttribute("src",t),n.setAttribute("style","display:none;"),n.setAttribute("height","0px"),n.setAttribute("width","0px"),n.setAttribute("frameborder","0"),document.body.appendChild(n),n.parentNode.removeChild(n),n=null},callCmd:function(n){var r=t;if(r.isKugouAndroid){var e={},o="";if(n.cmd&&(e.cmd=n.cmd),n.jsonStr&&(e.jsonStr=n.jsonStr),n.callback&&(o="kgandroidmobilecall"+ ++r.cbNum+Math.random().toString().substr(2,9),e.callback=o,window[o]=function(t,e){void 0!==t&&("[object String]"===Object.prototype.toString.call(t)?(t="#"===e?decodeURIComponent(t):decodeURIComponent(decodeURIComponent(t)),n.callback(r.str2Json(t))):n.callback(t))}),n.AndroidCallback){var i=r.str2Json(n.jsonStr);i.AndroidCallback=o,n.jsonStr=r.json2Str(i),n.jsonStr&&(e.jsonStr=n.jsonStr)}var c=encodeURIComponent(JSON.stringify(e)),s="kugoujsbridge://start.kugou_jsbridge/?".concat(c);r.loadUrl(s)}else if(r.isAndroid){var a="",l="";if(n.jsonStr){if(n.callback&&""!==n.callback&&!0===n.AndroidCallback){l="kgmobilecall"+ ++r.cbNum+Math.random().toString().substr(2,9),window[l]=function(t,e){void 0!==t&&("[object String]"===Object.prototype.toString.call(t)?(t="#"===e?decodeURIComponent(t):decodeURIComponent(decodeURIComponent(t)),n.callback(r.str2Json(t))):n.callback(t))};var u=r.str2Json(n.jsonStr);u.AndroidCallback=l,n.jsonStr=r.json2Str(u)}try{a=external.superCall(n.cmd,n.jsonStr)}catch(t){}}else try{a=external.superCall(n.cmd)}catch(t){}n.callback&&""!==n.callback&&"AndroidCallback"!=a&&(a=r.str2Json(a),n.callback(a))}else{var f="",d="";n.callback&&(d="kgmobilecall"+ ++r.cbNum+Math.random().toString().substr(2,9),window[d]=function(t){void 0!==t&&n.callback&&("[object String]"===Object.prototype.toString.call(t)?n.callback(r.str2Json(t)):n.callback(t))}),d&&""!=d&&n.jsonStr&&(f='kugouurl://start.music/?{"cmd":'+n.cmd+', "jsonStr":'+n.jsonStr+', "callback":"'+d+'"}'),d&&""!=d&&!n.jsonStr&&(f='kugouurl://start.music/?{"cmd":'+n.cmd+', "callback":"'+d+'"}'),""==d&&n.jsonStr&&(f='kugouurl://start.music/?{"cmd":'+n.cmd+', "jsonStr":'+n.jsonStr+"}"),""!=d||n.jsonStr||(f='kugouurl://start.music/?{"cmd":'+n.cmd+"}"),r.loadUrl(f)}},formartData:function(n,r){n&&123==n&&r&&(r=t._extend(t.formatURL,r)),n&&123==n&&r&&(r=t._extend(t.formatURL,r))}};return{isIOS:t.isIOS,isKugouAndroid:t.isKugouAndroid,isAndroid:t.isAndroid,isInClient:function(){return!(!t.isAndroid&&!t.isKugouAndroid&&!t.isIOS)},mobileCall:function(n,r,e){var o="";if(r&&(o=t.json2Str(r)),!n)return console.error("请输入命令号!"),!1;var i={};n&&(i.cmd=n),""!=o&&(i.jsonStr=o),e&&(i.callback=e),n&&186==n&&e&&(i.AndroidCallback=!0),t.callCmd(i)},KgWebMobileCall:function(t,n){if(t)try{var r=t.split(".");r.reduce(function(e,o){if(e[o]){if(o===r[r.length-1]){var i=e[o];return"function"==typeof i?(e[o]=function(t){i&&i(t),n&&n(t)},e[o]):(console.error("请检查,当前环境变量已注册了对象:"+t+",且该对象不是方法"),null)}return e[o]}return o===r[r.length-1]?e[o]=function(t){n&&n(t)}:e[o]=new Object,e[o]},window)}catch(t){}}}}()}()}),a=e(function(t){!function(){var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r={rotl:function(t,n){return t<>>32-n},rotr:function(t,n){return t<<32-n|t>>>n},endian:function(t){if(t.constructor==Number)return 16711935&r.rotl(t,8)|4278255360&r.rotl(t,24);for(var n=0;n0;t--)n.push(Math.floor(256*Math.random()));return n},bytesToWords:function(t){for(var n=[],r=0,e=0;r>>5]|=t[r]<<24-e%32;return n},wordsToBytes:function(t){for(var n=[],r=0;r<32*t.length;r+=8)n.push(t[r>>>5]>>>24-r%32&255);return n},bytesToHex:function(t){for(var n=[],r=0;r>>4).toString(16)),n.push((15&t[r]).toString(16));return n.join("")},hexToBytes:function(t){for(var n=[],r=0;r>>6*(3-i)&63)):r.push("=");return r.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/gi,"");for(var r=[],e=0,o=0;e>>6-2*o);return r}};t.exports=r}()}),l={utf8:{stringToBytes:function(t){return l.bin.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(l.bin.bytesToString(t)))}},bin:{stringToBytes:function(t){for(var n=[],r=0;r>>24)|4278255360&(s[g]<<24|s[g]>>>8);s[a>>>5]|=128<>>9<<4)]=a;for(var b=i._ff,p=i._gg,h=i._hh,m=i._ii,g=0;g>>0,u=u+j>>>0,f=f+S>>>0,d=d+v>>>0}return n.endian([l,u,f,d])};i._ff=function(t,n,r,e,o,i,c){var s=t+(n&r|~n&e)+(o>>>0)+c;return(s<>>32-i)+n},i._gg=function(t,n,r,e,o,i,c){var s=t+(n&e|r&~e)+(o>>>0)+c;return(s<>>32-i)+n},i._hh=function(t,n,r,e,o,i,c){var s=t+(n^r^e)+(o>>>0)+c;return(s<>>32-i)+n},i._ii=function(t,n,r,e,o,i,c){var s=t+(r^(n|~e))+(o>>>0)+c;return(s<>>32-i)+n},i._blocksize=16,i._digestsize=16,t.exports=function(t,r){if(void 0===t||null===t)throw new Error("Illegal argument "+t);var e=n.wordsToBytes(i(t,r));return r&&r.asBytes?e:r&&r.asString?o.bytesToString(e):n.bytesToHex(e)}}()});return c}); +//# sourceMappingURL=infSign.min.js.map