Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
BiliDriveEx
提交
b0d3d837
B
BiliDriveEx
项目概览
OpenDocCN
/
BiliDriveEx
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
BiliDriveEx
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
b0d3d837
编写于
3月 06, 2020
作者:
W
wizardforcel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化登录逻辑
上级
e8368f66
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
22 addition
and
25 deletion
+22
-25
BiliDriveEx/bilibili.py
BiliDriveEx/bilibili.py
+22
-25
未找到文件。
BiliDriveEx/bilibili.py
浏览文件 @
b0d3d837
...
...
@@ -70,31 +70,34 @@ class Bilibili:
'appkey'
:
Bilibili
.
app_key
,
'sign'
:
self
.
calc_sign
(
f
"appkey=
{
Bilibili
.
app_key
}
"
),
}
while
True
:
res
=
request_retry
(
"post"
,
url
,
data
=
payload
).
json
()
if
res
and
res
[
'code'
]
==
0
:
return
{
'key_hash'
:
res
[
'data'
][
'hash'
],
'pub_key'
:
rsa
.
PublicKey
.
load_pkcs1_openssl_pem
(
res
[
'data'
][
'key'
].
encode
()),
}
else
:
time
.
sleep
(
1
)
res
=
request_retry
(
"post"
,
url
,
data
=
payload
,
retry
=
999999
).
json
()
if
res
and
res
[
'code'
]
==
0
:
return
{
'key_hash'
:
res
[
'data'
][
'hash'
],
'pub_key'
:
rsa
.
PublicKey
.
load_pkcs1_openssl_pem
(
res
[
'data'
][
'key'
].
encode
()),
}
def
login_once
(
self
,
username
,
password
,
captcha
=
None
):
key
=
self
.
get_key
()
key_hash
,
pub_key
=
key
[
'key_hash'
],
key
[
'pub_key'
]
username
=
parse
.
quote_plus
(
username
)
password
=
parse
.
quote_plus
(
base64
.
b64encode
(
rsa
.
encrypt
(
f
'
{
key_hash
}{
password
}
'
.
encode
(),
pub_key
)))
url
=
f
"https://passport.bilibili.com/api/v2/oauth2/login"
param
=
f
"appkey=
{
Bilibili
.
app_key
}
"
if
captcha
:
param
+=
f
'&captcha=
{
captcha
}
'
param
+=
f
"&password=
{
password
}
&username=
{
username
}
"
payload
=
f
"
{
param
}
&sign=
{
self
.
calc_sign
(
param
)
}
"
headers
=
{
'Content-type'
:
"application/x-www-form-urlencoded"
}
res
=
self
.
_requests
(
"post"
,
url
,
data
=
payload
,
headers
=
headers
)
return
res
# 登录
def
login
(
self
,
username
,
password
):
self
.
username
=
username
self
.
password
=
password
while
True
:
key
=
self
.
get_key
()
key_hash
,
pub_key
=
key
[
'key_hash'
],
key
[
'pub_key'
]
url
=
f
"https://passport.bilibili.com/api/v2/oauth2/login"
param
=
f
"appkey=
{
Bilibili
.
app_key
}
&password=
{
parse
.
quote_plus
(
base64
.
b64encode
(
rsa
.
encrypt
(
f
'
{
key_hash
}{
self
.
password
}
'.encode(), pub_key)))
}
&username=
{
parse
.
quote_plus
(
self
.
username
)
}
"
payload
=
f
"
{
param
}
&sign=
{
self
.
calc_sign
(
param
)
}
"
headers
=
{
'Content-type'
:
"application/x-www-form-urlencoded"
}
response
=
self
.
_requests
(
"post"
,
url
,
data
=
payload
,
headers
=
headers
)
response
=
self
.
login_once
(
username
,
password
)
while
True
:
if
response
and
response
.
get
(
"code"
)
is
not
None
:
if
response
[
'code'
]
==
-
105
:
...
...
@@ -104,13 +107,7 @@ class Bilibili:
captcha
=
self
.
_solve_captcha
(
response
)
if
captcha
:
log
(
f
"登录验证码识别结果:
{
captcha
}
"
)
key
=
get_key
()
key_hash
,
pub_key
=
key
[
'key_hash'
],
key
[
'pub_key'
]
url
=
f
"https://passport.bilibili.com/api/v2/oauth2/login"
param
=
f
"appkey=
{
Bilibili
.
app_key
}
&captcha=
{
captcha
}
&password=
{
parse
.
quote_plus
(
base64
.
b64encode
(
rsa
.
encrypt
(
f
'
{
key_hash
}{
self
.
password
}
'.encode(), pub_key)))
}
&username=
{
parse
.
quote_plus
(
self
.
username
)
}
"
payload
=
f
"
{
param
}
&sign=
{
self
.
calc_sign
(
param
)
}
"
headers
=
{
'Content-type'
:
"application/x-www-form-urlencoded"
}
response
=
self
.
_requests
(
"post"
,
url
,
data
=
payload
,
headers
=
headers
)
response
=
login_once
(
username
,
password
,
captcha
)
else
:
log
(
f
"登录验证码识别服务暂时不可用, 10秒后重试"
)
time
.
sleep
(
10
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录