Skip to content

Commit 3541ffe

Browse files
committed
更新[网易云音乐]: 增加自动重试及等级显示 (BoxJs 可调整重试次数及间隔)
1 parent 6ce0d77 commit 3541ffe

10 files changed

Lines changed: 265 additions & 257 deletions

QuantumultX_AppStore_Local_Cookie.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ hostname = apiwz.midukanshu.com, api.1sapp.com, frodo.douban.com, luckman.suning
2929
^https:\/\/www\.flyertea\.com\/source\/plugin\/mobile\/mobile\.php\?module=getdata&.* url script-request-header chavyleung/flyertea/flyertea.cookie.js
3030

3131
# 网易云音乐
32-
^https:\/\/music\.163\.com\/m\/?.? url script-request-header chavyleung/neteasemusic/quanx/neteasemusic.cookie.js
32+
^https:\/\/music.163.com\/weapi\/user\/level url script-request-header chavyleung/neteasemusic/quanx/neteasemusic.cookie.js
3333

3434
# 网易新闻
3535
^https:\/\/user\.m\.163.com\/api\/v1\/commons\/fav\/topic\/allList url script-request-header chavyleung/neteasenews/neteasenews.cookie.js

QuantumultX_Local_Cookie.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ hostname = apiwz.midukanshu.com, api.1sapp.com, frodo.douban.com, luckman.suning
2929
^https:\/\/www\.flyertea\.com\/source\/plugin\/mobile\/mobile\.php\?module=getdata&.* url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/flyertea/flyertea.cookie.js
3030

3131
# 网易云音乐
32-
^https:\/\/music\.163\.com\/m\/?.? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/neteasemusic/quanx/neteasemusic.cookie.js
32+
^https:\/\/music.163.com\/weapi\/user\/level url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/neteasemusic/quanx/neteasemusic.cookie.js
3333

3434
# 网易新闻
3535
^https:\/\/(.*?)c\.m\.163\.com\/uc\/api\/sign\/v3\/commit url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/neteasenews/neteasenews.cookie.js

chavy.box.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,18 @@ function getSystemApps() {
156156
repo: 'https://github.com/chavyleung/scripts/tree/master/v2ex',
157157
icon: 'https://raw.githubusercontent.com/Orz-3/mini/master/v2ex.png'
158158
},
159+
{
160+
id: 'NeteaseMusic',
161+
name: '网易云音乐',
162+
keys: ['chavy_cookie_neteasemusic'],
163+
settings: [
164+
{ id: 'CFG_neteasemusic_retryCnt', name: '重试次数', val: 10, type: 'text', desc: '一直尝试签到直至出现“重复签到”标识!' },
165+
{ id: 'CFG_neteasemusic_retryInterval', name: '重试间隔 (毫秒)', val: 1000, type: 'text', desc: '每次重试间隔时间 (毫秒)!' }
166+
],
167+
author: '@chavyleung',
168+
repo: 'https://github.com/chavyleung/scripts/tree/master/neteasemusic',
169+
icon: 'https://is3-ssl.mzstatic.com/image/thumb/Purple113/v4/ef/e3/f4/efe3f4fa-288f-65fc-fc59-eacf6c1cea01/AppIcon-0-0-1x_U007emarketing-0-0-0-6-0-0-sRGB-0-0-0-GLES2_U002c0-512MB-85-220-0-0.png/460x0w.png'
170+
},
159171
{
160172
id: 'WPS',
161173
name: 'WPS',
@@ -251,12 +263,6 @@ function handleApi() {
251263
})
252264
$.subt = `保存会话: ${isAllSaveSuc ? '成功' : '失败'} (${app.name})`
253265
$.msg($.name, $.subt, '')
254-
// sessions.push(session)
255-
// const savesuc = $.setdata(JSON.stringify(sessions), $.KEY_sessions)
256-
// $.subt = `保存会话: ${savesuc ? '成功' : '失败'} (${session.appName})`
257-
// $.desc = []
258-
// $.desc.push(`会话名称: ${session.name}`, `应用名称: ${session.appName}`, `会话编号: ${session.id}`, `应用编号: ${session.appId}`, `数据: ${JSON.stringify(session)}`)
259-
// $.msg($.name, $.subt, $.desc.join('\n'))
260266
}
261267
}
262268
// 保存设置

neteasemusic/README.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
# 网易云音乐
22

3-
## 配置
3+
> 2020.6.15
4+
>
5+
> 1. 增加自动重试机制 (BoxJs 可调整次数及间隔)
6+
> 2. 增加等级显示 (需按新方式获取会话)
7+
8+
## 配置 (Surge & Loon)
9+
10+
```properties
11+
[MITM]
12+
music.163.com
13+
14+
[rewrite_local]
15+
^https:\/\/music.163.com\/weapi\/user\/level url script-request-header neteasemusic.cookie.js
16+
17+
[task_local]
18+
1 0 * * * neteasemusic.js
19+
```
20+
21+
## 配置 (QuanX)
422

523
```properties
624
[MITM]
@@ -13,12 +31,9 @@ cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scr
1331

1432
## 说明
1533

16-
1. 先把`music.163.com`加到`[MITM]`
17-
2. 再把两条远程脚本放到`[Script]`
18-
3. 浏览器访问并登录: https://music.163.com/m/login
19-
4. 登录成功后再用浏览器访问一下: https://music.163.com/
20-
5. `Surge`提示: `Cookie [网易云音乐] 写入成功`
21-
6. 最后就可以把第 1 条脚本注释掉了
34+
1. 先登录: <https://music.163.com/m/login>
35+
2. 再访问: <https://music.163.com/#/user/level>
36+
3. 提示: `获取会话: 成功!`
2237

2338
> 第 1 条脚本是用来获取 cookie 的, 用浏览器访问一次获取 cookie 成功后就可以删掉或注释掉了, 但请确保在`登录成功`后再获取 cookie.
2439
Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
1-
const cookieName = '网易云音乐'
2-
const cookieKey = 'chavy_cookie_neteasemusic'
3-
const cookieVal = $request.headers['Cookie']
1+
const $ = new Env('网易云音乐')
42

5-
if (cookieVal) {
6-
let cookie = $persistentStore.write(cookieVal, cookieKey)
7-
if (cookie) {
8-
let msg = `${cookieName}`
9-
$notification.post(msg, 'Cookie写入成功', '详见日志')
10-
console.log(msg)
11-
console.log(cookieVal)
3+
!(async () => {
4+
$.log('', `🔔 ${$.name}, 获取会话: 开始!`, '')
5+
const session = {}
6+
session.url = $request.url
7+
session.body = $request.body
8+
session.headers = $request.headers
9+
delete session.headers['Content-Length']
10+
$.log('', `url: ${session.url}`, `body: ${session.body}`, `headers: ${JSON.stringify(session.headers)}`)
11+
if ($.setdata(JSON.stringify(session), 'chavy_cookie_neteasemusic')) {
12+
$.subt = '获取会话: 成功!'
13+
} else {
14+
$.subt = '获取会话: 失败!'
1215
}
13-
}
16+
})()
17+
.catch((e) => {
18+
$.subt = '获取会话: 失败!'
19+
$.desc = `原因: ${e}`
20+
$.log(`❌ ${$.name}, 获取会话: 失败! 原因: ${e}!`)
21+
})
22+
.finally(() => {
23+
$.msg($.name, $.subt, $.desc), $.log('', `🔔 ${$.name}, 获取会话: 结束!`, ''), $.done()
24+
})
1425

15-
$done({})
26+
// prettier-ignore
27+
function Env(t){this.name=t,this.logs=[],this.isSurge=(()=>"undefined"!=typeof $httpClient),this.isQuanX=(()=>"undefined"!=typeof $task),this.log=((...t)=>{this.logs=[...this.logs,...t],t?console.log(t.join("\n")):console.log(this.logs.join("\n"))}),this.msg=((t=this.name,s="",i="")=>{this.isSurge()&&$notification.post(t,s,i),this.isQuanX()&&$notify(t,s,i);const e=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t&&e.push(t),s&&e.push(s),i&&e.push(i),console.log(e.join("\n"))}),this.getdata=(t=>this.isSurge()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):void 0),this.setdata=((t,s)=>this.isSurge()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):void 0),this.get=((t,s)=>this.send(t,"GET",s)),this.wait=((t,s=t)=>i=>setTimeout(()=>i(),Math.floor(Math.random()*(s-t+1)+t))),this.post=((t,s)=>this.send(t,"POST",s)),this.send=((t,s,i)=>{if(this.isSurge()){const e="POST"==s?$httpClient.post:$httpClient.get;e(t,(t,s,e)=>{s&&(s.body=e,s.statusCode=s.status),i(t,s,e)})}this.isQuanX()&&(t.method=s,$task.fetch(t).then(t=>{t.status=t.statusCode,i(null,t,t.body)},t=>i(t.error,t,t)))}),this.done=((t={})=>$done(t))}

neteasemusic/neteasemusic.js

Lines changed: 90 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,101 @@
1-
const cookieName = '网易云音乐'
2-
const cookieKey = 'chavy_cookie_neteasemusic'
3-
const cookieVal = $persistentStore.read(cookieKey)
1+
const $ = new Env('网易云音乐')
2+
$.VAL_session = $.getdata('chavy_cookie_neteasemusic')
3+
$.CFG_retryCnt = ($.getdata('CFG_neteasemusic_retryCnt') || '10') * 1
4+
$.CFG_retryInterval = ($.getdata('CFG_neteasemusic_retryInterval') || '500') * 1
45

5-
const pc = `http://music.163.com/api/point/dailyTask?type=1`
6-
const mobile = `http://music.163.com/api/point/dailyTask?type=0`
7-
8-
function sign() {
9-
let url = {
10-
url: null,
11-
headers: {
12-
Cookie: cookieVal
13-
}
14-
}
15-
16-
let signinfo = {}
17-
18-
url.url = pc
19-
$httpClient.post(url, (error, response, data) => {
20-
let result = JSON.parse(data)
21-
signinfo.pc = {
22-
title: `网易云音乐(PC)`,
23-
success: result.code == 200 || result.code == -2 ? true : false,
24-
skiped: result.code == -2 ? true : false,
25-
resultCode: result.code,
26-
resultMsg: result.msg
27-
}
28-
console.log(`开始签到: ${signinfo.pc.title}, 编码: ${result.code}, 原因: ${result.msg}`)
6+
!(async () => {
7+
$.log('', `🔔 ${$.name}, 开始!`, '')
8+
init()
9+
await signweb()
10+
await signapp()
11+
await getInfo()
12+
await showmsg()
13+
})()
14+
.catch((e) => {
15+
$.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '')
2916
})
30-
31-
url.url = mobile
32-
$httpClient.post(url, (error, response, data) => {
33-
let result = JSON.parse(data)
34-
signinfo.app = {
35-
title: `网易云音乐(APP)`,
36-
success: result.code == 200 || result.code == -2 ? true : false,
37-
skiped: result.code == -2 ? true : false,
38-
resultCode: result.code,
39-
resultMsg: result.msg
40-
}
41-
console.log(`开始签到: ${signinfo.app.title}, 编码: ${result.code}, 原因: ${result.msg}`)
17+
.finally(() => {
18+
$.msg($.name, $.subt, $.desc), $.log('', `🔔 ${$.name}, 结束!`, ''), $.done()
4219
})
43-
check(signinfo)
20+
21+
function init() {
22+
$.isNewCookie = /https:\/\/music.163.com\/weapi\/user\/level/.test($.VAL_session)
23+
$.Cookie = $.isNewCookie ? JSON.parse($.VAL_session).headers.Cookie : $.VAL_session
4424
}
4525

46-
function check(signinfo, checkms = 0) {
47-
if (signinfo.pc && signinfo.app) {
48-
log(signinfo)
49-
$done({})
50-
} else {
51-
if (checkms > 5000) {
52-
$done({})
53-
} else {
54-
setTimeout(() => check(signinfo, checkms + 100), 100)
55-
}
26+
async function signweb() {
27+
for (let signIdx = 0; signIdx < $.CFG_retryCnt; signIdx++) {
28+
await new Promise((resove) => {
29+
const url = { url: `http://music.163.com/api/point/dailyTask?type=1`, headers: {} }
30+
url.headers['Cookie'] = $.Cookie
31+
url.headers['Host'] = 'music.163.com'
32+
url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15'
33+
$.get(url, (error, response, data) => {
34+
try {
35+
$.isWebSuc = JSON.parse(data).code === -2
36+
$.log(`[Web] 第 ${signIdx + 1} 次: ${data}`)
37+
} catch (e) {
38+
$.isWebSuc = false
39+
$.log(`❗️ ${$.name}, 执行失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, '')
40+
} finally {
41+
resove()
42+
}
43+
})
44+
})
45+
await new Promise($.wait($.CFG_retryInterval))
46+
if ($.isWebSuc) break
5647
}
5748
}
5849

59-
function log(signinfo) {
60-
let title = `${cookieName}`
61-
let subTitle = ``
62-
let detail = `今日共签: ${signinfo.signedCnt}, 本次成功: ${signinfo.successCnt}, 本次失败: ${signinfo.failedCnt}`
63-
64-
if (signinfo.pc.success && signinfo.app.success) {
65-
subTitle = `签到结果: 全部成功`
66-
detail = `PC: ${signinfo.pc.success ? '成功' : '失败'}, APP: ${signinfo.app.success ? '成功' : '失败'}`
67-
} else if (!signinfo.pc.success && !signinfo.app.success) {
68-
subTitle = `签到结果: 全部失败`
69-
detail = `PC: ${signinfo.pc.success ? '成功' : '失败'}, APP: ${signinfo.app.success ? '成功' : '失败'}, 详见日志!`
70-
} else {
71-
subTitle = ``
72-
detail = `PC: ${signinfo.pc.success ? '成功' : '失败'}, APP: ${signinfo.app.success ? '成功' : '失败'}, 详见日志!`
50+
async function signapp() {
51+
for (let signIdx = 0; signIdx < $.CFG_retryCnt; signIdx++) {
52+
await new Promise((resove) => {
53+
const url = { url: `http://music.163.com/api/point/dailyTask?type=0`, headers: {} }
54+
url.headers['Cookie'] = $.Cookie
55+
url.headers['Host'] = 'music.163.com'
56+
url.headers['User-Agent'] = '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'
57+
$.get(url, (error, response, data) => {
58+
try {
59+
$.isAppSuc = JSON.parse(data).code === -2
60+
$.log(`[App] 第 ${signIdx + 1} 次: ${data}`)
61+
} catch (e) {
62+
$.isAppSuc = false
63+
$.log(`❗️ ${$.name}, 执行失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, '')
64+
} finally {
65+
resove()
66+
}
67+
})
68+
})
69+
await new Promise($.wait($.CFG_retryInterval))
70+
if ($.isAppSuc) break
7371
}
74-
$notification.post(title, subTitle, detail)
7572
}
7673

77-
sign()
74+
function getInfo() {
75+
if (!$.isNewCookie) return
76+
return new Promise((resove) => {
77+
$.post(JSON.parse($.VAL_session), (error, response, data) => {
78+
try {
79+
$.userInfo = JSON.parse(data)
80+
} catch (e) {
81+
$.log(`❗️ ${$.name}, 执行失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, '')
82+
} finally {
83+
resove()
84+
}
85+
})
86+
})
87+
}
88+
89+
function showmsg() {
90+
return new Promise((resove) => {
91+
$.subt = $.isWebSuc ? 'PC: 成功' : 'PC: 失败'
92+
$.subt += $.isAppSuc ? ', APP: 成功' : ', APP: 失败'
93+
if ($.isNewCookie && $.userInfo) {
94+
$.desc = `等级: ${$.userInfo.data.level}, 听歌: ${$.userInfo.data.nowPlayCount} => ${$.userInfo.data.nextPlayCount} 升级 (首)`
95+
}
96+
resove()
97+
})
98+
}
99+
100+
// prettier-ignore
101+
function Env(t){this.name=t,this.logs=[],this.isSurge=(()=>"undefined"!=typeof $httpClient),this.isQuanX=(()=>"undefined"!=typeof $task),this.log=((...t)=>{this.logs=[...this.logs,...t],t?console.log(t.join("\n")):console.log(this.logs.join("\n"))}),this.msg=((t=this.name,s="",i="")=>{this.isSurge()&&$notification.post(t,s,i),this.isQuanX()&&$notify(t,s,i);const e=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t&&e.push(t),s&&e.push(s),i&&e.push(i),console.log(e.join("\n"))}),this.getdata=(t=>this.isSurge()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):void 0),this.setdata=((t,s)=>this.isSurge()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):void 0),this.get=((t,s)=>this.send(t,"GET",s)),this.wait=((t,s=t)=>i=>setTimeout(()=>i(),Math.floor(Math.random()*(s-t+1)+t))),this.post=((t,s)=>this.send(t,"POST",s)),this.send=((t,s,i)=>{if(this.isSurge()){const e="POST"==s?$httpClient.post:$httpClient.get;e(t,(t,s,e)=>{s&&(s.body=e,s.statusCode=s.status),i(t,s,e)})}this.isQuanX()&&(t.method=s,$task.fetch(t).then(t=>{t.status=t.statusCode,i(null,t,t.body)},t=>i(t.error,t,t)))}),this.done=((t={})=>$done(t))}

neteasemusic/quanx/README.md

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)