加了点东西
This commit is contained in:
parent
87685a9410
commit
e1361af959
@ -281,7 +281,12 @@ class Downloader:
|
||||
)
|
||||
|
||||
# 获取文件大小
|
||||
content_length = int(head_resp.headers.get("Content-Length", 0))
|
||||
content_length = 0
|
||||
if "Content-Length" in head_resp.headers:
|
||||
try:
|
||||
content_length = int(head_resp.headers["Content-Length"])
|
||||
except ValueError:
|
||||
content_length = 0
|
||||
|
||||
# 如果服务器不支持断点续传,但本地有部分文件,则重新下载
|
||||
if not accept_ranges and initial_size > 0:
|
||||
@ -290,7 +295,11 @@ class Downloader:
|
||||
# 重新获取文件大小
|
||||
head_resp = await client.head(url)
|
||||
head_resp.raise_for_status()
|
||||
content_length = int(head_resp.headers.get("Content-Length", 0))
|
||||
if "Content-Length" in head_resp.headers:
|
||||
try:
|
||||
content_length = int(head_resp.headers["Content-Length"])
|
||||
except ValueError:
|
||||
content_length = 0
|
||||
|
||||
# 计算总文件大小
|
||||
total_size = initial_size + content_length
|
||||
@ -303,16 +312,16 @@ class Downloader:
|
||||
)
|
||||
|
||||
# 更新进度条总大小 - 确保总大小不为0
|
||||
if progress_bar and total_size > 0:
|
||||
progress_bar.reset(total=total_size)
|
||||
progress_bar.update(initial_size)
|
||||
elif progress_bar:
|
||||
# 如果总大小为0,设置为未知大小模式
|
||||
progress_bar.reset(total=None)
|
||||
progress_bar.update(initial_size)
|
||||
|
||||
# 更新描述信息
|
||||
if progress_bar:
|
||||
if total_size > 0:
|
||||
progress_bar.reset(total=total_size)
|
||||
progress_bar.update(initial_size)
|
||||
else:
|
||||
# 如果总大小为0,设置为未知大小模式
|
||||
progress_bar.reset(total=None)
|
||||
progress_bar.update(initial_size)
|
||||
|
||||
# 更新描述信息
|
||||
desc = file_path.name[:20] + (file_path.name[20:] and "...")
|
||||
if use_multithread:
|
||||
desc += f" [多线程:{self.threads}]"
|
||||
@ -332,7 +341,7 @@ class Downloader:
|
||||
)
|
||||
else:
|
||||
await self._singlethread_download(
|
||||
client, url, file_path, headers, progress_bar, initial_size
|
||||
client, url, file_path, headers, progress_bar, initial_size, total_size
|
||||
)
|
||||
|
||||
# 关闭进度条
|
||||
@ -476,21 +485,24 @@ class Downloader:
|
||||
headers: Dict,
|
||||
progress_bar: Optional[tqdm],
|
||||
initial_size: int,
|
||||
total_size: int
|
||||
):
|
||||
"""单线程下载实现"""
|
||||
last_update = time.time()
|
||||
async with client.stream("GET", url, headers=headers) as response:
|
||||
response.raise_for_status()
|
||||
|
||||
# 获取文件大小(如果响应头中有)
|
||||
total_size = initial_size
|
||||
if "Content-Length" in response.headers:
|
||||
total_size += int(response.headers["Content-Length"])
|
||||
|
||||
# 更新进度条总大小
|
||||
if progress_bar and total_size > initial_size:
|
||||
progress_bar.reset(total=total_size)
|
||||
progress_bar.update(initial_size)
|
||||
# 如果之前没有获取到文件大小,尝试从响应头获取
|
||||
if progress_bar and total_size <= 0:
|
||||
if "Content-Length" in response.headers:
|
||||
try:
|
||||
content_length = int(response.headers["Content-Length"])
|
||||
new_total_size = initial_size + content_length
|
||||
progress_bar.reset(total=new_total_size)
|
||||
progress_bar.update(initial_size)
|
||||
total_size = new_total_size
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# 打开文件进行写入
|
||||
mode = "ab" if initial_size > 0 else "wb"
|
||||
|
||||
BIN
opt/A005.zip
Normal file
BIN
opt/A005.zip
Normal file
Binary file not shown.
BIN
opt/A006.zip
Normal file
BIN
opt/A006.zip
Normal file
Binary file not shown.
BIN
opt/A007.zip
Normal file
BIN
opt/A007.zip
Normal file
Binary file not shown.
BIN
opt/SDGB_A005_20250603074349_0.opt
Normal file
BIN
opt/SDGB_A005_20250603074349_0.opt
Normal file
Binary file not shown.
BIN
opt/SDGB_A006_20250612160242_0.opt
Normal file
BIN
opt/SDGB_A006_20250612160242_0.opt
Normal file
Binary file not shown.
BIN
opt/SDGB_A007_20250619173010_0.opt
Normal file
BIN
opt/SDGB_A007_20250619173010_0.opt
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user