diff --git a/process/threads.py b/process/threads.py index dc792b1..e8232c2 100644 --- a/process/threads.py +++ b/process/threads.py @@ -32,10 +32,10 @@ def download_video(args) -> dict: if total_bytes > 0: percent = (downloaded_bytes / total_bytes) * 100 bar.update(int(np.round(percent - bar.n))) # If the progress bar doesn't end at 100% then round to 1 decimal place - bar.set_postfix({ - 'speed': d['_speed_str'], - 'size': f"{d['_downloaded_bytes_str'].strip()}/{d['_total_bytes_str'].strip()}", - }) + bar.set_postfix({ + 'speed': d['_speed_str'], + 'size': f"{d['_downloaded_bytes_str'].strip()}/{d['_total_bytes_str'].strip()}", + }) video = args[0] kwargs = args[1] @@ -54,11 +54,10 @@ def download_video(args) -> dict: bar_lock = item[1] break ydl_opts['progress_hooks'] = [progress_hook] + desc_with = int(np.round(os.get_terminal_size()[0] * (1 / 4))) + bar = tqdm(total=100, position=(offset if locked else None), desc=video['title'].ljust(desc_with)[:desc_with], bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}{postfix}]', leave=False, disable=not len(bars)) yt_dlp = ydl.YDL(ydl_opts) - - desc_with = int(np.round(os.get_terminal_size()[0] * (1 / 4))) - bar = tqdm(total=100, position=(offset if locked else None), desc=video['title'].ljust(desc_with)[:desc_with], bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}{postfix}]', leave=False, disable=not len(bars)) output_dict = {'downloaded_video_id': None, 'blacklist_video_id': None, 'video_error_logger_msg': [], 'status_msg': [], 'logger_msg': []} # empty object start_time = time.time() @@ -74,7 +73,7 @@ def download_video(args) -> dict: output_dict['video_error_logger_msg'].append(m) except Exception as e: output_dict['video_error_logger_msg'].append(f"{video['id']} {video['title']} -> {e}") - bar.close() if locked: + bar.close() bar_lock.release() return output_dict