From 6e00fbf8be39ba009e87d3cc5a388307858ad5b6 Mon Sep 17 00:00:00 2001 From: Kentaro Wada Date: Sun, 12 May 2024 14:34:07 +0900 Subject: [PATCH] Show resume progress bar from the middle --- gdown/download.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gdown/download.py b/gdown/download.py index 560f8ea3..548922ef 100644 --- a/gdown/download.py +++ b/gdown/download.py @@ -314,8 +314,11 @@ def download( f = output if tmp_file is not None and f.tell() != 0: - headers = {"Range": "bytes={}-".format(f.tell())} + start_size = f.tell() + headers = {"Range": "bytes={}-".format(start_size)} res = sess.get(url, headers=headers, stream=True, verify=verify) + else: + start_size = 0 if not quiet: print(log_messages.get("start", "Downloading...\n"), file=sys.stderr, end="") @@ -337,9 +340,9 @@ def download( try: total = res.headers.get("Content-Length") if total is not None: - total = int(total) + total = int(total) + start_size if not quiet: - pbar = tqdm.tqdm(total=total, unit="B", unit_scale=True) + pbar = tqdm.tqdm(total=total, unit="B", initial=start_size, unit_scale=True) t_start = time.time() for chunk in res.iter_content(chunk_size=CHUNK_SIZE): f.write(chunk)