mirror of
https://gitlab.com/Binaryify/neteasecloudmusicapi.git
synced 2025-05-23 22:37:41 +08:00
修改了下 UA 相关逻辑 .gitignore 弄得好看了点
This commit is contained in:
parent
4afb471d33
commit
9ee30f363a
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,8 +1,5 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
*.log
|
||||
|
||||
.idea/
|
||||
|
||||
|
||||
.idea
|
||||
.vscode
|
@ -6,8 +6,10 @@ const zlib = require('zlib')
|
||||
|
||||
// request.debug = true // 开启可看到更详细信息
|
||||
|
||||
const chooseUserAgent = ua => {
|
||||
const userAgentList = [
|
||||
function 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.',
|
||||
@ -17,9 +19,11 @@ const chooseUserAgent = ua => {
|
||||
// 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 with qq micromsg
|
||||
// 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',
|
||||
@ -28,16 +32,20 @@ const chooseUserAgent = ua => {
|
||||
'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 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]
|
||||
}
|
||||
|
||||
let realUserAgentList = []
|
||||
if (!ua)
|
||||
realUserAgentList = (userAgentList.mobile).concat(userAgentList.pc) // concat 把两个 array 合并
|
||||
else if (ua == 'mobile')
|
||||
realUserAgentList = userAgentList.mobile
|
||||
else if (ua == 'pc')
|
||||
realUserAgentList = userAgentList.pc
|
||||
else
|
||||
return ua // 最后返回自定义的 ua
|
||||
return realUserAgentList[Math.floor(Math.random() * realUserAgentList.length)]
|
||||
}
|
||||
const createRequest = (method, url, data, options) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let headers = { 'User-Agent': chooseUserAgent(options.ua) }
|
||||
|
Loading…
x
Reference in New Issue
Block a user