Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
BiliDriveEx
提交
834e466d
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,发现更多精彩内容 >>
提交
834e466d
编写于
11月 30, 2019
作者:
H
Hsury
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
取消上传时间限制
上级
f8df70af
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
15 addition
and
15 deletion
+15
-15
.travis.yml
.travis.yml
+1
-1
README.md
README.md
+1
-1
drive.py
drive.py
+13
-13
未找到文件。
.travis.yml
浏览文件 @
834e466d
if
:
'
tag
IS
blank'
if
:
'
tag
IS
blank'
env
:
env
:
global
:
global
:
-
TRAVIS_TAG=v1.
4
-
TRAVIS_TAG=v1.
5
jobs
:
jobs
:
include
:
include
:
-
-
...
...
README.md
浏览文件 @
834e466d
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
<h4
align=
"center"
>
☁️ 哔哩哔哩云,支持任意文件的全速上传与下载 ☁️
</h4>
<h4
align=
"center"
>
☁️ 哔哩哔哩云,支持任意文件的全速上传与下载 ☁️
</h4>
<p
align=
"center"
>
<p
align=
"center"
>
<img
src=
"https://img.shields.io/badge/version-2019.11.
11
-green.svg?longCache=true&style=for-the-badge"
>
<img
src=
"https://img.shields.io/badge/version-2019.11.
30
-green.svg?longCache=true&style=for-the-badge"
>
<img
src=
"https://img.shields.io/badge/license-SATA-blue.svg?longCache=true&style=for-the-badge"
>
<img
src=
"https://img.shields.io/badge/license-SATA-blue.svg?longCache=true&style=for-the-badge"
>
<img
src=
"https://img.shields.io/travis/com/Hsury/BiliDrive?style=for-the-badge"
>
<img
src=
"https://img.shields.io/travis/com/Hsury/BiliDrive?style=for-the-badge"
>
</p>
</p>
...
...
drive.py
浏览文件 @
834e466d
...
@@ -77,7 +77,7 @@ def image_upload(data, cookies):
...
@@ -77,7 +77,7 @@ def image_upload(data, cookies):
'category'
:
"daily"
,
'category'
:
"daily"
,
}
}
try
:
try
:
response
=
requests
.
post
(
url
,
headers
=
headers
,
cookies
=
cookies
,
files
=
files
,
timeout
=
10
).
json
()
response
=
requests
.
post
(
url
,
headers
=
headers
,
cookies
=
cookies
,
files
=
files
).
json
()
except
:
except
:
response
=
None
response
=
None
return
response
return
response
...
@@ -110,7 +110,7 @@ def read_history():
...
@@ -110,7 +110,7 @@ def read_history():
history
=
{}
history
=
{}
return
history
return
history
def
read_in_chunk
s
(
file_name
,
chunk_size
=
16
*
1024
*
1024
,
chunk_number
=-
1
):
def
read_in_chunk
(
file_name
,
chunk_size
=
16
*
1024
*
1024
,
chunk_number
=-
1
):
chunk_counter
=
0
chunk_counter
=
0
with
open
(
file_name
,
"rb"
)
as
f
:
with
open
(
file_name
,
"rb"
)
as
f
:
while
True
:
while
True
:
...
@@ -157,7 +157,7 @@ def upload_handle(args):
...
@@ -157,7 +157,7 @@ def upload_handle(args):
block_sha1
=
calc_sha1
(
block
,
hexdigest
=
True
)
block_sha1
=
calc_sha1
(
block
,
hexdigest
=
True
)
full_block
=
bmp_header
(
block
)
+
block
full_block
=
bmp_header
(
block
)
+
block
full_block_sha1
=
calc_sha1
(
full_block
,
hexdigest
=
True
)
full_block_sha1
=
calc_sha1
(
full_block
,
hexdigest
=
True
)
url
=
skippable
(
full_block_sha1
)
url
=
is_
skippable
(
full_block_sha1
)
if
url
:
if
url
:
# log(f"分块{index} ({len(block) / 1024 / 1024:.2f} MB) 已存在于服务器")
# log(f"分块{index} ({len(block) / 1024 / 1024:.2f} MB) 已存在于服务器")
block_dict
[
index
]
=
{
block_dict
[
index
]
=
{
...
@@ -194,7 +194,7 @@ def upload_handle(args):
...
@@ -194,7 +194,7 @@ def upload_handle(args):
finally
:
finally
:
done_flag
.
release
()
done_flag
.
release
()
def
skippable
(
sha1
):
def
is_
skippable
(
sha1
):
url
=
default_url
(
sha1
)
url
=
default_url
(
sha1
)
headers
=
{
headers
=
{
'Referer'
:
"http://t.bilibili.com/"
,
'Referer'
:
"http://t.bilibili.com/"
,
...
@@ -224,7 +224,7 @@ def upload_handle(args):
...
@@ -224,7 +224,7 @@ def upload_handle(args):
log
(
"不支持上传文件夹"
)
log
(
"不支持上传文件夹"
)
return
None
return
None
log
(
f
"上传:
{
os
.
path
.
basename
(
file_name
)
}
(
{
os
.
path
.
getsize
(
file_name
)
/
1024
/
1024
:.
2
f
}
MB)"
)
log
(
f
"上传:
{
os
.
path
.
basename
(
file_name
)
}
(
{
os
.
path
.
getsize
(
file_name
)
/
1024
/
1024
:.
2
f
}
MB)"
)
first_4mb_sha1
=
calc_sha1
(
read_in_chunk
s
(
file_name
,
chunk_size
=
4
*
1024
*
1024
,
chunk_number
=
1
),
hexdigest
=
True
)
first_4mb_sha1
=
calc_sha1
(
read_in_chunk
(
file_name
,
chunk_size
=
4
*
1024
*
1024
,
chunk_number
=
1
),
hexdigest
=
True
)
history
=
read_history
()
history
=
read_history
()
if
first_4mb_sha1
in
history
:
if
first_4mb_sha1
in
history
:
url
=
history
[
first_4mb_sha1
][
'url'
]
url
=
history
[
first_4mb_sha1
][
'url'
]
...
@@ -242,7 +242,7 @@ def upload_handle(args):
...
@@ -242,7 +242,7 @@ def upload_handle(args):
terminate_flag
=
threading
.
Event
()
terminate_flag
=
threading
.
Event
()
thread_pool
=
[]
thread_pool
=
[]
block_dict
=
{}
block_dict
=
{}
for
index
,
block
in
enumerate
(
read_in_chunk
s
(
file_name
,
chunk_size
=
args
.
block_size
*
1024
*
1024
)):
for
index
,
block
in
enumerate
(
read_in_chunk
(
file_name
,
chunk_size
=
args
.
block_size
*
1024
*
1024
)):
if
len
(
thread_pool
)
>=
args
.
thread
:
if
len
(
thread_pool
)
>=
args
.
thread
:
done_flag
.
acquire
()
done_flag
.
acquire
()
if
not
terminate_flag
.
is_set
():
if
not
terminate_flag
.
is_set
():
...
@@ -255,7 +255,7 @@ def upload_handle(args):
...
@@ -255,7 +255,7 @@ def upload_handle(args):
thread
.
join
()
thread
.
join
()
if
terminate_flag
.
is_set
():
if
terminate_flag
.
is_set
():
return
None
return
None
sha1
=
calc_sha1
(
read_in_chunk
s
(
file_name
),
hexdigest
=
True
)
sha1
=
calc_sha1
(
read_in_chunk
(
file_name
),
hexdigest
=
True
)
meta_dict
=
{
meta_dict
=
{
'time'
:
int
(
time
.
time
()),
'time'
:
int
(
time
.
time
()),
'filename'
:
os
.
path
.
basename
(
file_name
),
'filename'
:
os
.
path
.
basename
(
file_name
),
...
@@ -310,7 +310,7 @@ def download_handle(args):
...
@@ -310,7 +310,7 @@ def download_handle(args):
def
block_offset
(
index
):
def
block_offset
(
index
):
return
sum
(
meta_dict
[
'block'
][
i
][
'size'
]
for
i
in
range
(
index
))
return
sum
(
meta_dict
[
'block'
][
i
][
'size'
]
for
i
in
range
(
index
))
def
is_overwrite
(
file_name
):
def
is_overwrit
abl
e
(
file_name
):
if
args
.
force
:
if
args
.
force
:
return
True
return
True
else
:
else
:
...
@@ -327,10 +327,10 @@ def download_handle(args):
...
@@ -327,10 +327,10 @@ def download_handle(args):
log
(
f
"线程数:
{
args
.
thread
}
"
)
log
(
f
"线程数:
{
args
.
thread
}
"
)
download_block_list
=
[]
download_block_list
=
[]
if
os
.
path
.
exists
(
file_name
):
if
os
.
path
.
exists
(
file_name
):
if
os
.
path
.
getsize
(
file_name
)
==
meta_dict
[
'size'
]
and
calc_sha1
(
read_in_chunk
s
(
file_name
),
hexdigest
=
True
)
==
meta_dict
[
'sha1'
]:
if
os
.
path
.
getsize
(
file_name
)
==
meta_dict
[
'size'
]
and
calc_sha1
(
read_in_chunk
(
file_name
),
hexdigest
=
True
)
==
meta_dict
[
'sha1'
]:
log
(
f
"
{
os
.
path
.
basename
(
file_name
)
}
已存在于本地, 且与服务器端文件内容一致"
)
log
(
f
"
{
os
.
path
.
basename
(
file_name
)
}
已存在于本地, 且与服务器端文件内容一致"
)
return
file_name
return
file_name
elif
is_overwrite
(
file_name
):
elif
is_overwrit
abl
e
(
file_name
):
with
open
(
file_name
,
"rb"
)
as
f
:
with
open
(
file_name
,
"rb"
)
as
f
:
for
index
,
block_dict
in
enumerate
(
meta_dict
[
'block'
]):
for
index
,
block_dict
in
enumerate
(
meta_dict
[
'block'
]):
f
.
seek
(
block_offset
(
index
))
f
.
seek
(
block_offset
(
index
))
...
@@ -365,7 +365,7 @@ def download_handle(args):
...
@@ -365,7 +365,7 @@ def download_handle(args):
return
None
return
None
f
.
truncate
(
sum
(
block
[
'size'
]
for
block
in
meta_dict
[
'block'
]))
f
.
truncate
(
sum
(
block
[
'size'
]
for
block
in
meta_dict
[
'block'
]))
log
(
f
"
{
os
.
path
.
basename
(
file_name
)
}
下载完毕, 用时
{
int
(
time
.
time
()
-
start_time
)
}
秒, 平均速度
{
meta_dict
[
'size'
]
/
1024
/
1024
/
(
time
.
time
()
-
start_time
):.
2
f
}
MB/s"
)
log
(
f
"
{
os
.
path
.
basename
(
file_name
)
}
下载完毕, 用时
{
int
(
time
.
time
()
-
start_time
)
}
秒, 平均速度
{
meta_dict
[
'size'
]
/
1024
/
1024
/
(
time
.
time
()
-
start_time
):.
2
f
}
MB/s"
)
sha1
=
calc_sha1
(
read_in_chunk
s
(
file_name
),
hexdigest
=
True
)
sha1
=
calc_sha1
(
read_in_chunk
(
file_name
),
hexdigest
=
True
)
if
sha1
==
meta_dict
[
'sha1'
]:
if
sha1
==
meta_dict
[
'sha1'
]:
log
(
f
"
{
os
.
path
.
basename
(
file_name
)
}
校验通过"
)
log
(
f
"
{
os
.
path
.
basename
(
file_name
)
}
校验通过"
)
return
file_name
return
file_name
...
@@ -375,7 +375,7 @@ def download_handle(args):
...
@@ -375,7 +375,7 @@ def download_handle(args):
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
signal
.
signal
(
signal
.
SIGINT
,
lambda
signum
,
frame
:
os
.
kill
(
os
.
getpid
(),
9
))
signal
.
signal
(
signal
.
SIGINT
,
lambda
signum
,
frame
:
os
.
kill
(
os
.
getpid
(),
9
))
parser
=
argparse
.
ArgumentParser
(
description
=
"BiliDrive"
,
epilog
=
"By Hsury, 2019/11/
11
"
)
parser
=
argparse
.
ArgumentParser
(
description
=
"BiliDrive"
,
epilog
=
"By Hsury, 2019/11/
30
"
)
subparsers
=
parser
.
add_subparsers
()
subparsers
=
parser
.
add_subparsers
()
history_parser
=
subparsers
.
add_parser
(
"history"
,
help
=
"view upload history"
)
history_parser
=
subparsers
.
add_parser
(
"history"
,
help
=
"view upload history"
)
history_parser
.
set_defaults
(
func
=
history_handle
)
history_parser
.
set_defaults
(
func
=
history_handle
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录