From 208bae7b3549bd0a6d6c8584bdbb3779d3932136 Mon Sep 17 00:00:00 2001 From: nathom Date: Tue, 13 Apr 2021 21:29:07 -0700 Subject: [PATCH] Make progress bars slightly smoother --- streamrip/utils.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/streamrip/utils.py b/streamrip/utils.py index bd5db9d..93d1fd4 100644 --- a/streamrip/utils.py +++ b/streamrip/utils.py @@ -135,19 +135,18 @@ def tqdm_download(url: str, filepath: str, params: dict = None, desc: str = None raise NonStreamable(url) try: - with std_out_err_redirect_tqdm() as orig_stdout: - with open(filepath, "wb") as file, tqdm( - file=orig_stdout, - total=total, - unit="iB", - unit_scale=True, - unit_divisor=1024, - desc=desc, - dynamic_ncols=True, - ) as bar: - for data in r.iter_content(chunk_size=1024): - size = file.write(data) - bar.update(size) + with open(filepath, "wb") as file, tqdm( + total=total, + unit="iB", + unit_scale=True, + unit_divisor=1024, + desc=desc, + dynamic_ncols=True, + # leave=False, + ) as bar: + for data in r.iter_content(chunk_size=1024): + size = file.write(data) + bar.update(size) except Exception: try: os.remove(filepath)