From d78b0a0c1cfc7af3495f7f6631a243567d896bb4 Mon Sep 17 00:00:00 2001 From: iaacornus Date: Mon, 6 Jun 2022 20:41:35 +0800 Subject: [PATCH] handled downloaderror as reported in #322 although this commit does not address it directly, instead of proceeding further, this would discontinue other processes by raising systemexit --- video_creation/background.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/video_creation/background.py b/video_creation/background.py index 11469aa..2bfca61 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -3,6 +3,7 @@ import os from random import randrange from yt_dlp import YoutubeDL +from yt_dlp.utils import DownloadError from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip from moviepy.editor import VideoFileClip @@ -27,6 +28,7 @@ def download_background(background): ydl_opts = { "outtmpl": "assets/mp4/background.mp4", "merge_output_format": "mp4", + "retries": 3, } background_check = os.path.isfile("assets/mp4/background.mp4") @@ -37,6 +39,7 @@ def download_background(background): ) os.remove("assets/mp4/background.mp4") + cancel = True try: with YoutubeDL(ydl_opts) as ydl: if background is None: @@ -57,8 +60,15 @@ def download_background(background): print_substep("The given link is not accepted!", style="bold red") except ConnectionError: print_substep("There is a connection error!", style="bold red") + except DownloadError: + print_substep("There is a download error!", style="bold red") else: print_substep("Background video downloaded successfully!", style="bold green") + cancel = False + + if cancel: + # to prevent further error and processes from happening + raise SystemExit() def chop_background_video(video_length):