Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
BiliDriveEx
提交
11173ff2
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 搜索 >>
提交
11173ff2
编写于
3月 06, 2020
作者:
W
wizardforcel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化程序结构
上级
bb9d5d4f
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
35 addition
and
30 deletion
+35
-30
BiliDriveEx/__main__.py
BiliDriveEx/__main__.py
+2
-28
BiliDriveEx/bilibili.py
BiliDriveEx/bilibili.py
+26
-1
BiliDriveEx/util.py
BiliDriveEx/util.py
+7
-1
未找到文件。
BiliDriveEx/__main__.py
浏览文件 @
11173ff2
...
...
@@ -41,25 +41,6 @@ def fetch_meta(s):
except
:
return
None
def
image_upload
(
data
,
cookies
):
url
=
"https://api.vc.bilibili.com/api/v1/drawImage/upload"
headers
=
{
'Origin'
:
"https://t.bilibili.com"
,
'Referer'
:
"https://t.bilibili.com/"
,
'User-Agent'
:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36"
,
}
files
=
{
'file_up'
:
(
f
"
{
int
(
time
.
time
()
*
1000
)
}
.png"
,
data
),
}
data
=
{
'biz'
:
"draw"
,
'category'
:
"daily"
,
}
try
:
response
=
requests
.
post
(
url
,
data
=
data
,
headers
=
headers
,
cookies
=
cookies
,
files
=
files
,
timeout
=
300
).
json
()
except
:
response
=
None
return
response
def
login_handle
(
args
):
if
api
.
login
(
username
=
args
.
username
,
password
=
args
.
password
):
...
...
@@ -86,7 +67,7 @@ def upload_handle(args):
for
_
in
range
(
10
):
if
terminate_flag
.
is_set
():
return
response
=
image_upload
(
full_block
,
cookies
)
response
=
api
.
image_upload
(
full_block
,
cookies
)
if
response
:
if
response
[
'code'
]
==
0
:
url
=
response
[
'data'
][
'image_url'
]
...
...
@@ -110,13 +91,6 @@ def upload_handle(args):
finally
:
done_flag
.
release
()
def
write_history
(
first_4mb_sha1
,
meta_dict
,
url
):
history
=
read_history
()
history
[
first_4mb_sha1
]
=
meta_dict
history
[
first_4mb_sha1
][
'url'
]
=
url
with
open
(
os
.
path
.
join
(
bundle_dir
,
"history.json"
),
"w"
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
json
.
dumps
(
history
,
ensure_ascii
=
False
,
indent
=
2
))
start_time
=
time
.
time
()
file_name
=
args
.
file
if
not
os
.
path
.
exists
(
file_name
):
...
...
@@ -169,7 +143,7 @@ def upload_handle(args):
meta
=
json
.
dumps
(
meta_dict
,
ensure_ascii
=
False
).
encode
(
"utf-8"
)
full_meta
=
encoder
.
encode
(
meta
)
for
_
in
range
(
10
):
response
=
image_upload
(
full_meta
,
cookies
)
response
=
api
.
image_upload
(
full_meta
,
cookies
)
if
response
and
response
[
'code'
]
==
0
:
url
=
response
[
'data'
][
'image_url'
]
log
(
"元数据上传完毕"
)
...
...
BiliDriveEx/bilibili.py
浏览文件 @
11173ff2
...
...
@@ -163,3 +163,28 @@ class Bilibili:
except
:
pass
return
None
def
image_upload
(
self
,
data
,
cookies
):
sha1
=
calc_sha1
(
data
)
url
=
self
.
exist
(
sha1
)
if
url
:
return
{
'code'
:
0
,
'data'
:
{
'image_url'
:
url
}}
url
=
"https://api.vc.bilibili.com/api/v1/drawImage/upload"
headers
=
{
'Origin'
:
"https://t.bilibili.com"
,
'Referer'
:
"https://t.bilibili.com/"
,
'User-Agent'
:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36"
,
}
files
=
{
'file_up'
:
(
f
"
{
int
(
time
.
time
()
*
1000
)
}
.png"
,
data
),
}
data
=
{
'biz'
:
"draw"
,
'category'
:
"daily"
,
}
try
:
response
=
requests
.
post
(
url
,
data
=
data
,
headers
=
headers
,
cookies
=
cookies
,
files
=
files
,
timeout
=
300
).
json
()
except
:
response
=
None
return
response
\ No newline at end of file
BiliDriveEx/util.py
浏览文件 @
11173ff2
...
...
@@ -51,6 +51,12 @@ def read_history():
history
=
{}
return
history
def
write_history
(
first_4mb_sha1
,
meta_dict
,
url
):
history
=
read_history
()
history
[
first_4mb_sha1
]
=
meta_dict
history
[
first_4mb_sha1
][
'url'
]
=
url
with
open
(
os
.
path
.
join
(
bundle_dir
,
"history.json"
),
"w"
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
json
.
dumps
(
history
,
ensure_ascii
=
False
,
indent
=
2
))
def
read_in_chunk
(
fname
,
size
=
4
*
1024
*
1024
,
cnt
=-
1
):
with
open
(
fname
,
"rb"
)
as
f
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录