提交 834e466d 编写于 作者: H Hsury

取消上传时间限制

上级 f8df70af
if: 'tag IS blank' if: 'tag IS blank'
env: env:
global: global:
- TRAVIS_TAG=v1.4 - TRAVIS_TAG=v1.5
jobs: jobs:
include: include:
- -
......
...@@ -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>
......
...@@ -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_chunks(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:.2f} MB)") log(f"上传: {os.path.basename(file_name)} ({os.path.getsize(file_name) / 1024 / 1024:.2f} MB)")
first_4mb_sha1 = calc_sha1(read_in_chunks(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_chunks(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_chunks(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_overwritable(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_chunks(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_overwritable(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):.2f} MB/s") log(f"{os.path.basename(file_name)}下载完毕, 用时{int(time.time() - start_time)}秒, 平均速度{meta_dict['size'] / 1024 / 1024 / (time.time() - start_time):.2f} MB/s")
sha1 = calc_sha1(read_in_chunks(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.
先完成此消息的编辑!
想要评论请 注册