[F] Fix downloader
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -17,10 +18,18 @@ def download_file(url: str, file: str | Path):
|
|||||||
return file
|
return file
|
||||||
|
|
||||||
chunk_size = 1024
|
chunk_size = 1024
|
||||||
|
|
||||||
|
try:
|
||||||
|
term_len = os.get_terminal_size().columns
|
||||||
|
bar_len = int(term_len * 0.4)
|
||||||
|
except Exception:
|
||||||
|
bar_len = 20
|
||||||
|
|
||||||
r = requests.get(url, stream=True)
|
r = requests.get(url, stream=True)
|
||||||
with open(file, 'wb') as f:
|
with open(file, 'wb') as f:
|
||||||
pbar = tqdm.tqdm(unit=" MB", total=int(r.headers['Content-Length']) / 1024 / 1024,
|
pbar = tqdm.tqdm(unit=" MB", total=int(r.headers['Content-Length']) / 1024 / 1024,
|
||||||
bar_format='{desc} {rate_fmt} {remaining} [{bar}] {percentage:.0f}%', ascii=' #', desc=file.name[:bar_len].ljust(bar_len))
|
bar_format='{desc} {rate_fmt} {remaining} [{bar}] {percentage:.0f}%', ascii=' #',
|
||||||
|
desc=file.name[:bar_len].ljust(bar_len))
|
||||||
for chunk in r.iter_content(chunk_size=chunk_size):
|
for chunk in r.iter_content(chunk_size=chunk_size):
|
||||||
if chunk:
|
if chunk:
|
||||||
pbar.update(len(chunk) / 1024 / 1024)
|
pbar.update(len(chunk) / 1024 / 1024)
|
||||||
|
|||||||
Reference in New Issue
Block a user