Skip to content

Commit 2e2feab

Browse files
committed
更新[腾讯视频]签到: 增加网页版获取Cookie方式
1 parent 86b8630 commit 2e2feab

5 files changed

Lines changed: 147 additions & 76 deletions

File tree

videoqq/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
# 腾讯视频
2-
3-
**2020.1.6** **~~从 网页 获取 Cookie 只有 2 小时有效期,使用意义不大,先弃坑~~**
4-
5-
**2020.1.7 从 APP 获取 Cookie,目测有效期能撑一段时间 (需要观察)**
1+
# 腾讯视频 (APP)
62

73
> 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可
84
95
> 需要 VIP 会员才能签到 (需要 VIP!需要 VIP!需要 VIP!)
106
117
> 2020.1.11 QuanX 在`190`版本开始, 获取 Cookie 方式需要从`script-response-body`改为`script-request-header`
128
9+
> 2020.2.5 如果你从 APP 中获取的 Cookie 容易失效 [请点这里](https://github.com/chavyleung/scripts/blob/master/videoqq/README.web.md)
10+
1311
## 配置 (Surge)
1412

1513
```properties

videoqq/README.web.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# 腾讯视频 (网页)
2+
3+
> 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可
4+
5+
## 配置 (Surge)
6+
7+
```properties
8+
[MITM]
9+
*.video.qq.com
10+
11+
[Script]
12+
http-request ^https:\/\/access.video.qq.com\/user\/auth_refresh script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/videoqq/videoqq.cookie.js
13+
cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/videoqq/videoqq.js
14+
```
15+
16+
## 配置 (QuanX)
17+
18+
```properties
19+
[MITM]
20+
*.video.qq.com
21+
22+
[rewrite_local]
23+
# 189及以前版本
24+
^https:\/\/access.video.qq.com\/user\/auth_refresh url script-response-body videoqq.cookie.js
25+
# 190及以后版本
26+
^https:\/\/access.video.qq.com\/user\/auth_refresh url script-request-header videoqq.cookie.js
27+
28+
[task_local]
29+
1 0 * * * videoqq.js
30+
```
31+
32+
## 说明
33+
34+
1. 先把`*.video.qq.com`加到`[MITM]`
35+
2. 再配置重写规则:
36+
- Surge: 把两条远程脚本放到`[Script]`
37+
- QuanX: 把`videoqq.cookie.js``videoqq.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关)
38+
3. 获取 Cookie:
39+
- 手机浏览器访问: https://film.qq.com/
40+
- 随便选 1 部电影观看
41+
4. 系统提示: `获取Cookie: 成功` (如果不提示获取成功, 点自己头像退出登录, 重新登录下应该就能获取)
42+
5. 最后就可以把第 1 条脚本注释掉了
43+
44+
> 第 1 条脚本是用来获取 cookie 的, 用浏览器访问一次获取 cookie 成功后就可以删掉或注释掉了, 但请确保在`登录成功`后再获取 cookie.
45+
46+
> 第 2 条脚本是签到脚本, 每天`00:00:10`执行一次.
47+
48+
## 常见问题
49+
50+
1. 无法写入 Cookie
51+
52+
- 检查 Surge 系统通知权限放开了没
53+
- 如果你用的是 Safari, 请尝试在浏览地址栏`手动输入网址`(不要用复制粘贴)
54+
55+
2. 写入 Cookie 成功, 但签到不成功
56+
57+
- 看看是不是在登录前就写入 Cookie 了
58+
- 如果是,请确保在登录成功后,再尝试写入 Cookie
59+
60+
3. 为什么有时成功有时失败
61+
62+
- 很正常,网络问题,哪怕你是手工签到也可能失败(凌晨签到容易拥堵就容易失败)
63+
- 暂时不考虑代码级的重试机制,但咱有配置级的(暴力美学):
64+
65+
- `Surge`配置:
66+
67+
```properties
68+
# 没有什么是一顿饭解决不了的:
69+
cron "10 0 0 * * *" script-path=xxx.js # 每天00:00:10执行一次
70+
# 如果有,那就两顿:
71+
cron "20 0 0 * * *" script-path=xxx.js # 每天00:00:20执行一次
72+
# 实在不行,三顿也能接受:
73+
cron "30 0 0 * * *" script-path=xxx.js # 每天00:00:30执行一次
74+
75+
# 再粗暴点,直接:
76+
cron "* */60 * * * *" script-path=xxx.js # 每60分执行一次
77+
```
78+
79+
- `QuanX`配置:
80+
81+
```properties
82+
[task_local]
83+
1 0 * * * xxx.js # 每天00:01执行一次
84+
2 0 * * * xxx.js # 每天00:02执行一次
85+
3 0 * * * xxx.js # 每天00:03执行一次
86+
87+
*/60 * * * * xxx.js # 每60分执行一次
88+
```
89+
90+
## 感谢
91+
92+
[@NobyDa](https://github.com/NobyDa)
93+
94+
[@lhie1](https://github.com/lhie1)
95+
96+
[@ConnersHua](https://github.com/ConnersHua)

videoqq/videoqq.cookie.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
11
const cookieName = '腾讯视频'
22
const cookieKey = 'chavy_cookie_videoqq'
3+
const authUrlKey = 'chavy_auth_url_videoqq'
4+
const authHeaderKey = 'chavy_auth_header_videoqq'
35
const chavy = init()
6+
47
const cookieVal = $request.headers['Cookie']
58
if (cookieVal) {
6-
if (chavy.setdata(cookieVal, cookieKey)) {
9+
if ($request.url.indexOf('auth_refresh') > 0) {
10+
const authurl = $request.url
11+
const authHeader = JSON.stringify($request.headers)
12+
if (cookieVal) chavy.setdata(cookieVal, cookieKey)
13+
if (authurl) chavy.setdata(authurl, authUrlKey)
14+
if (authHeader) chavy.setdata(authHeader, authHeaderKey)
715
chavy.msg(`${cookieName}`, '获取Cookie: 成功', '')
8-
chavy.log(`[${cookieName}] 获取Cookie: 成功, cookie: ${cookieVal}`)
16+
chavy.log(`[${cookieName}] 获取Cookie: 成功, Cookie: ${cookieVal}`)
17+
chavy.log(`[${cookieName}] 获取Cookie: 成功, AuthUrl: ${authurl}`)
18+
chavy.log(`[${cookieName}] 获取Cookie: 成功, AuthHeader: ${authHeader}`)
19+
} else {
20+
chavy.setdata(cookieVal, cookieKey)
21+
chavy.setdata(``, authUrlKey)
22+
chavy.setdata(``, authHeaderKey)
23+
chavy.msg(`${cookieName}`, '获取Cookie: 成功', '')
24+
chavy.log(`[${cookieName}] 获取Cookie: 成功, Cookie: ${cookieVal}`)
925
}
1026
}
27+
1128
function init() {
1229
isSurge = () => {
1330
return undefined === this.$httpClient ? false : true

videoqq/videoqq.cookie.keeper.js

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

videoqq/videoqq.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,40 @@
11
const cookieName = '腾讯视频'
22
const cookieKey = 'chavy_cookie_videoqq'
3+
const authUrlKey = 'chavy_auth_url_videoqq'
4+
const authHeaderKey = 'chavy_auth_header_videoqq'
35
const chavy = init()
4-
const cookieVal = chavy.getdata(cookieKey)
6+
let cookieVal = chavy.getdata(cookieKey)
7+
const authUrlVal = chavy.getdata(authUrlKey)
8+
const authHeaderVal = chavy.getdata(authHeaderKey)
59

610
sign()
711

812
function sign() {
9-
const timestamp = Date.parse(new Date())
13+
if (authUrlVal && authHeaderVal) {
14+
const url = { url: authUrlVal, headers: JSON.parse(authHeaderVal) }
15+
chavy.get(url, (error, response, data) => {
16+
chavy.log(`${cookieName}, auth_refresh - data: ${data}`)
17+
chavy.log(`${cookieName}, auth_refresh - oldCookie: ${cookieVal}`)
18+
let result = JSON.parse(data.match(/\(([^\)]*)\)/)[1])
19+
if (result.errcode == 0) {
20+
if (result.vuserid) cookieVal = cookieVal.replace(/vuserid=[^;]*/, `vuserid=${result.vuserid}`)
21+
if (result.vusession) cookieVal = cookieVal.replace(/vusession=[^;]*/, `vusession=${result.vusession}`)
22+
if (result.next_refresh_time) cookieVal = cookieVal.replace(/next_refresh_time=[^;]*/, `next_refresh_time=${result.next_refresh_time}`)
23+
if (result.access_token) cookieVal = cookieVal.replace(/access_token=[^;]*/, `access_token=${result.access_token}`)
24+
chavy.log(`${cookieName}, auth_refresh - newCookie: ${cookieVal}`)
25+
chavy.setdata(cookieVal, cookieKey)
26+
signapp()
27+
}
28+
})
29+
} else {
30+
signapp()
31+
}
32+
}
33+
34+
function signapp() {
35+
const timestamp = Math.round(new Date().getTime() / 1000).toString()
1036
let url = { url: `https://vip.video.qq.com/fcgi-bin/comm_cgi?name=hierarchical_task_system&cmd=2&_=${timestamp}`, headers: { Cookie: cookieVal } }
1137
url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15'
12-
1338
chavy.get(url, (error, response, data) => {
1439
chavy.log(`${cookieName}, data: ${data}`)
1540
let result = JSON.parse(data.match(/QZOutputJson=\(([^\)]*)\)/)[1])
@@ -36,7 +61,7 @@ function sign() {
3661
}
3762

3863
function getexp(signresult) {
39-
const timestamp = Date.parse(new Date())
64+
const timestamp = Math.round(new Date().getTime() / 1000).toString()
4065
let url = { url: `https://vip.video.qq.com/fcgi-bin/comm_cgi?name=spp_PropertyNum&cmd=1&growth_value=1&otype=json&_=${timestamp}`, headers: { Cookie: cookieVal } }
4166
url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15'
4267
chavy.get(url, (error, response, data) => {

0 commit comments

Comments
 (0)