Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
BiliDriveEx
提交
9281bf98
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 搜索 >>
提交
9281bf98
编写于
3月 06, 2020
作者:
W
wizardforcel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化代码结构
上级
b0d3d837
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
23 deletion
+27
-23
BiliDriveEx/__main__.py
BiliDriveEx/__main__.py
+2
-1
BiliDriveEx/bilibili.py
BiliDriveEx/bilibili.py
+25
-22
未找到文件。
BiliDriveEx/__main__.py
浏览文件 @
9281bf98
...
@@ -312,7 +312,8 @@ def main():
...
@@ -312,7 +312,8 @@ def main():
try
:
try
:
args
.
func
(
args
)
args
.
func
(
args
)
break
break
except
AttributeError
:
except
AttributeError
as
ex
:
traceback
.
print_exc
(
file
=
sys
.
stdout
)
shell
=
True
shell
=
True
subparsers
.
add_parser
(
"help"
,
help
=
"show this help message"
).
set_defaults
(
func
=
lambda
_
:
parser
.
parse_args
([
"--help"
]).
func
())
subparsers
.
add_parser
(
"help"
,
help
=
"show this help message"
).
set_defaults
(
func
=
lambda
_
:
parser
.
parse_args
([
"--help"
]).
func
())
subparsers
.
add_parser
(
"version"
,
help
=
"show program's version number"
).
set_defaults
(
func
=
lambda
_
:
parser
.
parse_args
([
"--version"
]).
func
())
subparsers
.
add_parser
(
"version"
,
help
=
"show program's version number"
).
set_defaults
(
func
=
lambda
_
:
parser
.
parse_args
([
"--version"
]).
func
())
...
...
BiliDriveEx/bilibili.py
浏览文件 @
9281bf98
...
@@ -14,6 +14,7 @@ from BiliDriveEx.util import *
...
@@ -14,6 +14,7 @@ from BiliDriveEx.util import *
class
Bilibili
:
class
Bilibili
:
app_key
=
"1d8b6e7d45233436"
app_key
=
"1d8b6e7d45233436"
default_hdrs
=
{
'User-Agent'
:
"Mozilla/5.0 BiliDroid/5.51.1 (bbcallen@gmail.com)"
}
default_url
=
lambda
self
,
sha1
:
f
"http://i0.hdslb.com/bfs/album/
{
sha1
}
.png"
default_url
=
lambda
self
,
sha1
:
f
"http://i0.hdslb.com/bfs/album/
{
sha1
}
.png"
meta_string
=
lambda
self
,
url
:
(
"bdex://"
+
re
.
findall
(
r
"[a-fA-F0-9]{40}"
,
url
)[
0
])
if
re
.
match
(
r
"^http(s?)://i0.hdslb.com/bfs/album/[a-fA-F0-9]{40}.png$"
,
url
)
else
url
meta_string
=
lambda
self
,
url
:
(
"bdex://"
+
re
.
findall
(
r
"[a-fA-F0-9]{40}"
,
url
)[
0
])
if
re
.
match
(
r
"^http(s?)://i0.hdslb.com/bfs/album/[a-fA-F0-9]{40}.png$"
,
url
)
else
url
...
@@ -22,10 +23,9 @@ class Bilibili:
...
@@ -22,10 +23,9 @@ class Bilibili:
get_uid
=
lambda
self
:
self
.
get_cookies
().
get
(
"DedeUserID"
,
""
)
get_uid
=
lambda
self
:
self
.
get_cookies
().
get
(
"DedeUserID"
,
""
)
def
__init__
(
self
):
def
__init__
(
self
):
self
.
cookie
=
{}
self
.
_session
=
requests
.
Session
()
self
.
_session
=
requests
.
Session
()
self
.
_session
.
headers
.
update
({
'User-Agent'
:
"Mozilla/5.0 BiliDroid/5.51.1 (bbcallen@gmail.com)"
})
self
.
_session
.
headers
.
update
({
'User-Agent'
:
"Mozilla/5.0 BiliDroid/5.51.1 (bbcallen@gmail.com)"
})
self
.
username
=
""
self
.
password
=
""
self
.
info
=
{
self
.
info
=
{
'ban'
:
False
,
'ban'
:
False
,
'coins'
:
0
,
'coins'
:
0
,
...
@@ -40,20 +40,18 @@ class Bilibili:
...
@@ -40,20 +40,18 @@ class Bilibili:
def
_requests
(
self
,
method
,
url
,
decode_level
=
2
,
retry
=
0
,
timeout
=
10
,
**
kwargs
):
def
_requests
(
self
,
method
,
url
,
decode_level
=
0
,
retry
=
0
,
timeout
=
10
,
**
kwargs
):
if
method
in
[
"get"
,
"post"
]:
for
_
in
range
(
retry
+
1
):
for
_
in
range
(
retry
+
1
):
try
:
try
:
response
=
getattr
(
self
.
_session
,
method
.
lower
())(
url
,
timeout
=
timeout
,
**
kwargs
)
response
=
getattr
(
self
.
_session
,
method
)(
url
,
timeout
=
timeout
,
**
kwargs
)
return
response
.
json
()
if
decode_level
==
2
else
response
.
content
if
decode_level
==
1
else
response
return
response
.
json
()
if
decode_level
==
2
else
response
.
content
if
decode_level
==
1
else
response
except
:
except
:
pass
pass
return
None
def
_solve_captcha
(
self
,
image
):
def
_solve_captcha
(
self
,
image
):
url
=
"https://bili.dev:2233/captcha"
url
=
"https://bili.dev:2233/captcha"
payload
=
{
'image'
:
base64
.
b64encode
(
image
).
decode
(
"utf-8"
)}
payload
=
{
'image'
:
base64
.
b64encode
(
image
).
decode
(
"utf-8"
)}
response
=
self
.
_requests
(
"post"
,
url
,
json
=
payload
)
response
=
self
.
_requests
(
"post"
,
url
,
json
=
payload
)
.
json
()
return
response
[
'message'
]
if
response
and
response
.
get
(
"code"
)
==
0
else
None
return
response
[
'message'
]
if
response
and
response
.
get
(
"code"
)
==
0
else
None
@
staticmethod
@
staticmethod
...
@@ -70,7 +68,7 @@ class Bilibili:
...
@@ -70,7 +68,7 @@ class Bilibili:
'appkey'
:
Bilibili
.
app_key
,
'appkey'
:
Bilibili
.
app_key
,
'sign'
:
self
.
calc_sign
(
f
"appkey=
{
Bilibili
.
app_key
}
"
),
'sign'
:
self
.
calc_sign
(
f
"appkey=
{
Bilibili
.
app_key
}
"
),
}
}
res
=
request_retry
(
"post"
,
url
,
data
=
payload
,
retry
=
999999
).
json
()
res
=
self
.
_requests
(
"post"
,
url
,
data
=
payload
,
retry
=
999999
).
json
()
if
res
and
res
[
'code'
]
==
0
:
if
res
and
res
[
'code'
]
==
0
:
return
{
return
{
'key_hash'
:
res
[
'data'
][
'hash'
],
'key_hash'
:
res
[
'data'
][
'hash'
],
...
@@ -79,6 +77,7 @@ class Bilibili:
...
@@ -79,6 +77,7 @@ class Bilibili:
def
login_once
(
self
,
username
,
password
,
captcha
=
None
):
def
login_once
(
self
,
username
,
password
,
captcha
=
None
):
key
=
self
.
get_key
()
key
=
self
.
get_key
()
print
(
'key: '
,
key
)
key_hash
,
pub_key
=
key
[
'key_hash'
],
key
[
'pub_key'
]
key_hash
,
pub_key
=
key
[
'key_hash'
],
key
[
'pub_key'
]
username
=
parse
.
quote_plus
(
username
)
username
=
parse
.
quote_plus
(
username
)
password
=
parse
.
quote_plus
(
base64
.
b64encode
(
rsa
.
encrypt
(
f
'
{
key_hash
}{
password
}
'
.
encode
(),
pub_key
)))
password
=
parse
.
quote_plus
(
base64
.
b64encode
(
rsa
.
encrypt
(
f
'
{
key_hash
}{
password
}
'
.
encode
(),
pub_key
)))
...
@@ -88,34 +87,38 @@ class Bilibili:
...
@@ -88,34 +87,38 @@ class Bilibili:
param
+=
f
"&password=
{
password
}
&username=
{
username
}
"
param
+=
f
"&password=
{
password
}
&username=
{
username
}
"
payload
=
f
"
{
param
}
&sign=
{
self
.
calc_sign
(
param
)
}
"
payload
=
f
"
{
param
}
&sign=
{
self
.
calc_sign
(
param
)
}
"
headers
=
{
'Content-type'
:
"application/x-www-form-urlencoded"
}
headers
=
{
'Content-type'
:
"application/x-www-form-urlencoded"
}
res
=
self
.
_requests
(
"post"
,
url
,
data
=
payload
,
headers
=
headers
)
res
=
self
.
_requests
(
"POST"
,
url
,
data
=
payload
,
headers
=
headers
).
json
()
return
res
def
get_captcha
(
self
):
url
=
f
"https://passport.bilibili.com/captcha"
headers
=
{
'Host'
:
"passport.bilibili.com"
}
res
=
self
.
_requests
(
'GET'
,
url
,
headers
=
headers
).
content
return
res
return
res
# 登录
# 登录
def
login
(
self
,
username
,
password
):
def
login
(
self
,
username
,
password
):
self
.
username
=
username
self
.
password
=
password
while
True
:
while
True
:
response
=
self
.
login_once
(
username
,
password
)
response
=
self
.
login_once
(
username
,
password
)
print
(
response
)
while
True
:
while
True
:
if
response
and
response
.
get
(
"code"
)
is
not
None
:
if
response
and
response
.
get
(
"code"
)
is
not
None
:
if
response
[
'code'
]
==
-
105
:
if
response
[
'code'
]
==
-
105
:
url
=
f
"https://passport.bilibili.com/captcha"
response
=
self
.
get_captcha
()
headers
=
{
'Host'
:
"passport.bilibili.com"
}
response
=
self
.
_requests
(
"get"
,
url
,
headers
=
headers
,
decode_level
=
1
)
captcha
=
self
.
_solve_captcha
(
response
)
captcha
=
self
.
_solve_captcha
(
response
)
if
captcha
:
if
captcha
:
log
(
f
"登录验证码识别结果:
{
captcha
}
"
)
log
(
f
"登录验证码识别结果:
{
captcha
}
"
)
response
=
login_once
(
username
,
password
,
captcha
)
response
=
self
.
login_once
(
username
,
password
,
captcha
)
else
:
else
:
log
(
f
"登录验证码识别服务暂时不可用, 10秒后重试"
)
log
(
f
"登录验证码识别服务暂时不可用, 10秒后重试"
)
time
.
sleep
(
10
)
time
.
sleep
(
10
)
break
break
elif
response
[
'code'
]
==
-
449
:
elif
response
[
'code'
]
==
-
449
:
time
.
sleep
(
1
)
time
.
sleep
(
1
)
response
=
self
.
_requests
(
"post"
,
url
,
data
=
payload
,
headers
=
headers
)
response
=
self
.
login_once
(
username
,
password
)
elif
response
[
'code'
]
==
0
and
response
[
'data'
][
'status'
]
==
0
:
elif
response
[
'code'
]
==
0
and
response
[
'data'
][
'status'
]
==
0
:
print
(
response
)
for
cookie
in
response
[
'data'
][
'cookie_info'
][
'cookies'
]:
for
cookie
in
response
[
'data'
][
'cookie_info'
][
'cookies'
]:
self
.
_session
.
cookies
.
set
(
cookie
[
'name'
],
cookie
[
'value'
],
domain
=
".bilibili.com"
)
self
.
_session
.
cookies
.
set
(
cookie
[
'name'
],
cookie
[
'value'
],
domain
=
".bilibili.com"
)
log
(
"登录成功"
)
log
(
"登录成功"
)
...
@@ -135,7 +138,7 @@ class Bilibili:
...
@@ -135,7 +138,7 @@ class Bilibili:
'Host'
:
"api.bilibili.com"
,
'Host'
:
"api.bilibili.com"
,
'Referer'
:
f
"https://space.bilibili.com/
{
self
.
get_uid
()
}
/"
,
'Referer'
:
f
"https://space.bilibili.com/
{
self
.
get_uid
()
}
/"
,
}
}
response
=
self
.
_requests
(
"get"
,
url
,
headers
=
headers
)
response
=
self
.
_requests
(
"get"
,
url
,
headers
=
headers
)
.
json
()
if
response
and
response
.
get
(
"code"
)
==
0
:
if
response
and
response
.
get
(
"code"
)
==
0
:
self
.
info
[
'ban'
]
=
bool
(
response
[
'data'
][
'silence'
])
self
.
info
[
'ban'
]
=
bool
(
response
[
'data'
][
'silence'
])
self
.
info
[
'coins'
]
=
response
[
'data'
][
'coins'
]
self
.
info
[
'coins'
]
=
response
[
'data'
][
'coins'
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录