Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
BiliDriveEx
提交
afcaad60
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 搜索 >>
提交
afcaad60
编写于
3月 07, 2020
作者:
W
wizardforcel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化验证码识别逻辑
上级
650993d3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
43 deletion
+36
-43
BiliDriveEx/__main__.py
BiliDriveEx/__main__.py
+9
-6
BiliDriveEx/bilibili.py
BiliDriveEx/bilibili.py
+27
-37
未找到文件。
BiliDriveEx/__main__.py
浏览文件 @
afcaad60
...
...
@@ -43,10 +43,13 @@ def fetch_meta(s):
def
login_handle
(
args
):
if
api
.
login
(
username
=
args
.
username
,
password
=
args
.
password
):
info
=
api
.
get_user_info
()
if
info
:
log
(
info
)
else
:
log
(
"用户信息获取失败"
)
r
=
api
.
login
(
args
.
username
,
args
.
password
)
if
r
[
'code'
]
!=
0
:
log
(
f
"登录失败:
{
r
[
'message'
]
}
"
)
return
info
=
api
.
get_user_info
()
if
info
:
log
(
info
)
else
:
log
(
"用户信息获取失败"
)
def
cookies_handle
(
args
):
api
.
set_cookies
(
args
.
cookies
)
...
...
@@ -184,10 +187,10 @@ def download_handle(args):
return
else
:
log
(
f
"分块
{
index
+
1
}
/
{
len
(
meta_dict
[
'block'
])
}
校验未通过"
)
terminate_flag
.
set
()
else
:
log
(
f
"分块
{
index
+
1
}
/
{
len
(
meta_dict
[
'block'
])
}
第
{
_
+
1
}
次下载失败"
)
else
:
terminate_flag
.
set
()
terminate_flag
.
set
()
except
:
terminate_flag
.
set
()
traceback
.
print_exc
()
...
...
BiliDriveEx/bilibili.py
浏览文件 @
afcaad60
...
...
@@ -33,8 +33,9 @@ class Bilibili:
self
.
cookies
[
kv
[
0
]]
=
kv
[
1
]
self
.
save_cookies
()
def
_solve_captcha
(
self
,
image
):
# 识别验证码
def
solve_captcha
(
self
,
image
):
url
=
"https://bili.dev:2233/captcha"
payload
=
{
'image'
:
base64
.
b64encode
(
image
).
decode
(
"utf-8"
)}
try
:
...
...
@@ -77,7 +78,8 @@ class Bilibili:
else
:
return
None
def
_login_once
(
self
,
username
,
password
,
captcha
=
None
):
# 登录一次
def
login_once
(
self
,
username
,
password
,
captcha
=
None
):
key
=
self
.
_get_key
()
if
not
key
:
return
{
'code'
:
114514
,
'message'
:
'key 获取失败'
}
key_hash
,
pub_key
=
key
[
'key_hash'
],
key
[
'pub_key'
]
...
...
@@ -100,9 +102,17 @@ class Bilibili:
).
json
()
except
Exception
as
ex
:
return
{
'code'
:
114514
,
'message'
:
str
(
ex
)}
if
j
[
'code'
]
==
0
and
j
[
'data'
][
'status'
]
==
0
:
self
.
cookies
=
{}
for
cookie
in
j
[
'data'
][
'cookie_info'
][
'cookies'
]:
self
.
cookies
[
cookie
[
'name'
]]
=
cookie
[
'value'
]
self
.
save_cookies
()
return
j
def
_get_captcha
(
self
):
# 获取验证码
def
get_captcha
(
self
):
url
=
f
"https://passport.bilibili.com/captcha"
try
:
img
=
request_retry
(
'GET'
,
url
,
...
...
@@ -114,46 +124,25 @@ class Bilibili:
return
img
# 登录
def
login
(
self
,
username
,
password
):
def
login
(
self
,
username
,
password
,
retry
=
5
):
captcha
=
None
while
True
:
j
=
self
.
_login_once
(
username
,
password
,
captcha
)
if
'code'
not
in
j
:
log
(
f
"当前IP登录过于频繁, 1分钟后重试"
)
time
.
sleep
(
60
)
continue
for
_
in
range
(
retry
):
j
=
self
.
login_once
(
username
,
password
,
captcha
)
if
j
[
'code'
]
==
-
105
:
img
=
self
.
_
get_captcha
()
img
=
self
.
get_captcha
()
if
not
img
:
log
(
f
"验证码获取失败"
)
time
.
sleep
(
1
)
continue
captcha
=
self
.
_solve_captcha
(
img
)
if
captcha
:
log
(
f
"登录验证码识别结果:
{
captcha
}
"
)
else
:
log
(
f
"登录验证码识别服务暂时不可用, 10秒后重试"
)
time
.
sleep
(
10
)
continue
if
j
[
'code'
]
==
-
449
:
time
.
sleep
(
1
)
captcha
=
self
.
solve_captcha
(
img
)
if
not
captcha
:
time
.
sleep
(
1
)
continue
if
j
[
'code'
]
==
0
and
j
[
'data'
][
'status'
]
==
0
:
self
.
cookies
=
{}
for
cookie
in
j
[
'data'
][
'cookie_info'
][
'cookies'
]:
self
.
cookies
[
cookie
[
'name'
]]
=
cookie
[
'value'
]
log
(
"登录成功"
)
self
.
save_cookies
()
return
True
return
j
log
(
f
"登录失败
{
j
[
'message'
]
}
"
)
return
False
return
j
# 获取用户信息
def
get_user_info
(
self
,
fmt
=
True
):
...
...
@@ -209,7 +198,8 @@ class Bilibili:
self
.
cookies
=
json
.
loads
(
f
.
read
())
except
:
pass
# 图片是否已存在
def
exist
(
self
,
sha1
):
url
=
self
.
default_url
(
sha1
)
try
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录