From 3bf3760178dc9859c3f0386515328eea4d06acc1 Mon Sep 17 00:00:00 2001 From: Leonard Excoffier Date: Mon, 19 Feb 2024 21:05:50 -0500 Subject: [PATCH] Added a try/except block around progress_bar function. --- main.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index e5b99ef..91a4cae 100644 --- a/main.py +++ b/main.py @@ -10,11 +10,14 @@ def get_video_url(): # Callback function to show the progress bar. def progress_bar(stream, _chunk, bytes_remaining): - current = ((stream.filesize - bytes_remaining)/stream.filesize) - percent = ('{0:.1f}').format(current * 100) - progress = int(50 * current) - status = '█' * progress + '-' * (50 - progress) - print(f'\r|{status}| {percent}%', end='') + try: + current = ((stream.filesize - bytes_remaining)/stream.filesize) + percent = ('{0:.1f}').format(current * 100) + progress = int(50 * current) + status = '█' * progress + '-' * (50 - progress) + print(f'\r|{status}| {percent}%', end='') + except Exception as e: + print(f"An error has occurred: {e}") # Downloads the video. def video_download(video_url):