Skip to content

Commit

Permalink
更新[腾讯视频]签到: 增加网页版获取Cookie方式
Browse files Browse the repository at this point in the history
  • Loading branch information
chavyleung committed Feb 5, 2020
1 parent 86b8630 commit 2e2feab
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 76 deletions.
8 changes: 3 additions & 5 deletions videoqq/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# 腾讯视频

**2020.1.6** **~~从 网页 获取 Cookie 只有 2 小时有效期,使用意义不大,先弃坑~~**

**2020.1.7 从 APP 获取 Cookie,目测有效期能撑一段时间 (需要观察)**
# 腾讯视频 (APP)

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

```properties
Expand Down
96 changes: 96 additions & 0 deletions videoqq/README.web.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# 腾讯视频 (网页)

> 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可
## 配置 (Surge)

```properties
[MITM]
*.video.qq.com

[Script]
http-request ^https:\/\/access.video.qq.com\/user\/auth_refresh script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/videoqq/videoqq.cookie.js
cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/videoqq/videoqq.js
```

## 配置 (QuanX)

```properties
[MITM]
*.video.qq.com

[rewrite_local]
# 189及以前版本
^https:\/\/access.video.qq.com\/user\/auth_refresh url script-response-body videoqq.cookie.js
# 190及以后版本
^https:\/\/access.video.qq.com\/user\/auth_refresh url script-request-header videoqq.cookie.js

[task_local]
1 0 * * * videoqq.js
```

## 说明

1. 先把`*.video.qq.com`加到`[MITM]`
2. 再配置重写规则:
- Surge: 把两条远程脚本放到`[Script]`
- QuanX: 把`videoqq.cookie.js``videoqq.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关)
3. 获取 Cookie:
- 手机浏览器访问: https://film.qq.com/
- 随便选 1 部电影观看
4. 系统提示: `获取Cookie: 成功` (如果不提示获取成功, 点自己头像退出登录, 重新登录下应该就能获取)
5. 最后就可以把第 1 条脚本注释掉了

> 第 1 条脚本是用来获取 cookie 的, 用浏览器访问一次获取 cookie 成功后就可以删掉或注释掉了, 但请确保在`登录成功`后再获取 cookie.
> 第 2 条脚本是签到脚本, 每天`00:00:10`执行一次.
## 常见问题

1. 无法写入 Cookie

- 检查 Surge 系统通知权限放开了没
- 如果你用的是 Safari, 请尝试在浏览地址栏`手动输入网址`(不要用复制粘贴)

2. 写入 Cookie 成功, 但签到不成功

- 看看是不是在登录前就写入 Cookie 了
- 如果是,请确保在登录成功后,再尝试写入 Cookie

3. 为什么有时成功有时失败

- 很正常,网络问题,哪怕你是手工签到也可能失败(凌晨签到容易拥堵就容易失败)
- 暂时不考虑代码级的重试机制,但咱有配置级的(暴力美学):

- `Surge`配置:

```properties
# 没有什么是一顿饭解决不了的:
cron "10 0 0 * * *" script-path=xxx.js # 每天00:00:10执行一次
# 如果有,那就两顿:
cron "20 0 0 * * *" script-path=xxx.js # 每天00:00:20执行一次
# 实在不行,三顿也能接受:
cron "30 0 0 * * *" script-path=xxx.js # 每天00:00:30执行一次

# 再粗暴点,直接:
cron "* */60 * * * *" script-path=xxx.js # 每60分执行一次
```

- `QuanX`配置:

```properties
[task_local]
1 0 * * * xxx.js # 每天00:01执行一次
2 0 * * * xxx.js # 每天00:02执行一次
3 0 * * * xxx.js # 每天00:03执行一次

*/60 * * * * xxx.js # 每60分执行一次
```

## 感谢

[@NobyDa](https://github.com/NobyDa)

[@lhie1](https://github.com/lhie1)

[@ConnersHua](https://github.com/ConnersHua)
21 changes: 19 additions & 2 deletions videoqq/videoqq.cookie.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
const cookieName = '腾讯视频'
const cookieKey = 'chavy_cookie_videoqq'
const authUrlKey = 'chavy_auth_url_videoqq'
const authHeaderKey = 'chavy_auth_header_videoqq'
const chavy = init()

const cookieVal = $request.headers['Cookie']
if (cookieVal) {
if (chavy.setdata(cookieVal, cookieKey)) {
if ($request.url.indexOf('auth_refresh') > 0) {
const authurl = $request.url
const authHeader = JSON.stringify($request.headers)
if (cookieVal) chavy.setdata(cookieVal, cookieKey)
if (authurl) chavy.setdata(authurl, authUrlKey)
if (authHeader) chavy.setdata(authHeader, authHeaderKey)
chavy.msg(`${cookieName}`, '获取Cookie: 成功', '')
chavy.log(`[${cookieName}] 获取Cookie: 成功, cookie: ${cookieVal}`)
chavy.log(`[${cookieName}] 获取Cookie: 成功, Cookie: ${cookieVal}`)
chavy.log(`[${cookieName}] 获取Cookie: 成功, AuthUrl: ${authurl}`)
chavy.log(`[${cookieName}] 获取Cookie: 成功, AuthHeader: ${authHeader}`)
} else {
chavy.setdata(cookieVal, cookieKey)
chavy.setdata(``, authUrlKey)
chavy.setdata(``, authHeaderKey)
chavy.msg(`${cookieName}`, '获取Cookie: 成功', '')
chavy.log(`[${cookieName}] 获取Cookie: 成功, Cookie: ${cookieVal}`)
}
}

function init() {
isSurge = () => {
return undefined === this.$httpClient ? false : true
Expand Down
65 changes: 0 additions & 65 deletions videoqq/videoqq.cookie.keeper.js

This file was deleted.

33 changes: 29 additions & 4 deletions videoqq/videoqq.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
const cookieName = '腾讯视频'
const cookieKey = 'chavy_cookie_videoqq'
const authUrlKey = 'chavy_auth_url_videoqq'
const authHeaderKey = 'chavy_auth_header_videoqq'
const chavy = init()
const cookieVal = chavy.getdata(cookieKey)
let cookieVal = chavy.getdata(cookieKey)
const authUrlVal = chavy.getdata(authUrlKey)
const authHeaderVal = chavy.getdata(authHeaderKey)

sign()

function sign() {
const timestamp = Date.parse(new Date())
if (authUrlVal && authHeaderVal) {
const url = { url: authUrlVal, headers: JSON.parse(authHeaderVal) }
chavy.get(url, (error, response, data) => {
chavy.log(`${cookieName}, auth_refresh - data: ${data}`)
chavy.log(`${cookieName}, auth_refresh - oldCookie: ${cookieVal}`)
let result = JSON.parse(data.match(/\(([^\)]*)\)/)[1])
if (result.errcode == 0) {
if (result.vuserid) cookieVal = cookieVal.replace(/vuserid=[^;]*/, `vuserid=${result.vuserid}`)
if (result.vusession) cookieVal = cookieVal.replace(/vusession=[^;]*/, `vusession=${result.vusession}`)
if (result.next_refresh_time) cookieVal = cookieVal.replace(/next_refresh_time=[^;]*/, `next_refresh_time=${result.next_refresh_time}`)
if (result.access_token) cookieVal = cookieVal.replace(/access_token=[^;]*/, `access_token=${result.access_token}`)
chavy.log(`${cookieName}, auth_refresh - newCookie: ${cookieVal}`)
chavy.setdata(cookieVal, cookieKey)
signapp()
}
})
} else {
signapp()
}
}

function signapp() {
const timestamp = Math.round(new Date().getTime() / 1000).toString()
let url = { url: `https://vip.video.qq.com/fcgi-bin/comm_cgi?name=hierarchical_task_system&cmd=2&_=${timestamp}`, headers: { Cookie: cookieVal } }
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'

chavy.get(url, (error, response, data) => {
chavy.log(`${cookieName}, data: ${data}`)
let result = JSON.parse(data.match(/QZOutputJson=\(([^\)]*)\)/)[1])
Expand All @@ -36,7 +61,7 @@ function sign() {
}

function getexp(signresult) {
const timestamp = Date.parse(new Date())
const timestamp = Math.round(new Date().getTime() / 1000).toString()
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 } }
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'
chavy.get(url, (error, response, data) => {
Expand Down

0 comments on commit 2e2feab

Please sign in to comment.