diff --git a/.gitignore b/.gitignore index 4a4d9a93dec..f284b532d73 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,5 @@ .DS_Store node_modules *.log - -.idea/ - - +.idea .vscode \ No newline at end of file diff --git a/README.MD b/README.MD index 957fc00ccd6..95b5731d687 100644 --- a/README.MD +++ b/README.MD @@ -192,7 +192,7 @@ ## 安装 ```shell -$ git clone git@github.com:Binaryify/NeteaseCloudMusicApi.git +$ git clone https://github.com/Binaryify/NeteaseCloudMusicApi.git $ npm install ``` diff --git a/public/avatar_update.html b/public/avatar_update.html index cc3caa299f8..45c2b8284c8 100644 --- a/public/avatar_update.html +++ b/public/avatar_update.html @@ -1,80 +1,82 @@ - - - - - 更新头像 - - - - - - - - + } + }) + } + + + + \ No newline at end of file diff --git a/public/index.html b/public/index.html index 42c1788bfc0..c3bbc3b9111 100644 --- a/public/index.html +++ b/public/index.html @@ -1,11 +1,13 @@ - + + 网易云音乐 API +

网易云音乐 API

当你看到这个页面时,这个服务已经成功跑起来了~ @@ -17,32 +19,40 @@

例子:

  • 3. 电台节目
  • + \ No newline at end of file diff --git a/public/playlist_cover_update.html b/public/playlist_cover_update.html index dde976bba1f..e6b1bd7b2e2 100644 --- a/public/playlist_cover_update.html +++ b/public/playlist_cover_update.html @@ -1,86 +1,88 @@ - - - - - 歌单封面上传 - - - - - - - - - + } + }) + } + + + + \ No newline at end of file diff --git a/public/test.html b/public/test.html index 804bd929f15..d0e87681a18 100644 --- a/public/test.html +++ b/public/test.html @@ -1,62 +1,63 @@ - - - - - - test - + - -

    请在控制台看结果

    - - - - - + +

    请在控制台看结果

    + + + + + + \ No newline at end of file diff --git a/util/request.js b/util/request.js index b0d3b473c3f..fcf75bec0db 100644 --- a/util/request.js +++ b/util/request.js @@ -6,32 +6,38 @@ const zlib = require('zlib') // request.debug = true // 开启可看到更详细信息 -const chooseUserAgent = ua => { - const userAgentList = [ - 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1', - 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1', - 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36', - 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36', - 'Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36', - 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_2 like Mac OS X) AppleWebKit/603.2.4 (KHTML, like Gecko) Mobile/14F89;GameHelper', - 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A300 Safari/602.1', - 'Mozilla/5.0 (iPad; CPU OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A300 Safari/602.1', - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:46.0) Gecko/20100101 Firefox/46.0', - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36', - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4', - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:46.0) Gecko/20100101 Firefox/46.0', - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36', - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/13.10586' - ] - let index = 0 - if (typeof ua == 'undefined') - index = Math.floor(Math.random() * userAgentList.length) - else if (ua === 'mobile') index = Math.floor(Math.random() * 7) - else if (ua === 'pc') index = Math.floor(Math.random() * 5) + 8 - else return ua - return userAgentList[index] +const chooseUserAgent = (ua = false) => { + // UA 列表要经常更新啊 + const userAgentList = { + mobile: [ + // iOS 13.5.1 14.0 beta with safari + 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Mobile/15E148 Safari/604.1', + 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.', + // iOS with qq micromsg + 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/602.1.50 (KHTML like Gecko) Mobile/14A456 QQ/6.5.7.408 V1_IPH_SQ_6.5.7_1_APP_A Pixel/750 Core/UIWebView NetType/4G Mem/103', + 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.15(0x17000f27) NetType/WIFI Language/zh', + // Android -> Huawei Xiaomi + 'Mozilla/5.0 (Linux; Android 9; PCT-AL10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.64 HuaweiBrowser/10.0.3.311 Mobile Safari/537.36', + 'Mozilla/5.0 (Linux; U; Android 9; zh-cn; Redmi Note 8 Build/PKQ1.190616.001) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.141 Mobile Safari/537.36 XiaoMi/MiuiBrowser/12.5.22', + // Android + qq micromsg + 'Mozilla/5.0 (Linux; Android 10; YAL-AL00 Build/HUAWEIYAL-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.62 XWEB/2581 MMWEBSDK/200801 Mobile Safari/537.36 MMWEBID/3027 MicroMessenger/7.0.18.1740(0x27001235) Process/toolsmp WeChat/arm64 NetType/WIFI Language/zh_CN ABI/arm64', + 'Mozilla/5.0 (Linux; U; Android 8.1.0; zh-cn; BKK-AL10 Build/HONORBKK-AL10) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/10.6 Mobile Safari/537.36', + ], + pc: [ + // macOS 10.15.6 Firefox / Chrome / Safari + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:80.0) Gecko/20100101 Firefox/80.0', + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.30 Safari/537.36', + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15', + // Windows 10 Firefox / Chrome / Edge + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0', + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.30 Safari/537.36', + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/13.10586' + // Linux 就算了 + ] + } + let realUserAgentList = userAgentList[ua] || (userAgentList.mobile).concat(userAgentList.pc) + return (['mobile', 'pc', false].indexOf(ua) > -1) ? realUserAgentList[Math.floor(Math.random() * realUserAgentList.length)] : ua } - const createRequest = (method, url, data, options) => { return new Promise((resolve, reject) => { let headers = { 'User-Agent': chooseUserAgent(options.ua) } @@ -52,7 +58,7 @@ const createRequest = (method, url, data, options) => { ) .join('; ') else if (options.cookie) headers['Cookie'] = options.cookie - + if (!headers['Cookie']) { headers['Cookie'] = options.token || '' } @@ -134,10 +140,10 @@ const createRequest = (method, url, data, options) => { zlib.unzip(body, function (err, buffer) { const _buffer = err ? body : buffer try { - try{ + try { answer.body = JSON.parse(encrypt.decrypt(_buffer).toString()) answer.status = answer.body.code || res.statusCode - } catch(e){ + } catch (e) { answer.body = JSON.parse(_buffer.toString()) answer.status = res.statusCode } @@ -156,7 +162,7 @@ const createRequest = (method, url, data, options) => { answer.body = JSON.parse(body) answer.status = answer.body.code || res.statusCode - if(answer.body.code === 502){ + if (answer.body.code === 502) { answer.status = 200 } }