优化download()获取文件大小逻辑

This commit is contained in:
g1879 2020-09-18 16:36:02 +08:00
parent 265c997efc
commit 7ae5ec6541

View File

@ -324,7 +324,8 @@ class SessionPage(object):
# -------------------开始下载------------------- # -------------------开始下载-------------------
# 获取远程文件大小 # 获取远程文件大小
file_size = int(r.headers['Content-Length']) if 'Content-Length' in r.headers else None content_length = tuple(x for x in r.headers if x.lower() == 'content-length')
file_size = int(r.headers[content_length]) if content_length else None
downloaded_size, download_status = 0, False # 已下载文件大小和下载状态 downloaded_size, download_status = 0, False # 已下载文件大小和下载状态
try: try:
with open(str(full_path), 'wb') as tmpFile: with open(str(full_path), 'wb') as tmpFile: