From 9230abb8a0d7b90efa682d2589dabc59980b2961 Mon Sep 17 00:00:00 2001 From: iaacornus Date: Sun, 5 Jun 2022 11:59:34 +0800 Subject: [PATCH] fixed conditions to download youtube link --- video_creation/background.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/video_creation/background.py b/video_creation/background.py index 317e878..a1897c6 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -1,6 +1,7 @@ import re from random import randrange from pathlib import Path +from turtle import back from yt_dlp import YoutubeDL from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip @@ -31,20 +32,23 @@ def download_background(background): background_check = Path("assets/mp4/background.mp4").is_file() if background is not None or not background_check: if background_check: - print_substep("Background video is already downloaded! Replacing ...") + print_substep( + "Background video is already downloaded! Replacing ...", style="bold red" + ) try: with YoutubeDL(ydl_opts) as ydl: if background is None: ydl.download("https://www.youtube.com/watch?v=n_Dv4JMiwK8") - else: + elif background is not None: if ( - re.match("https://www.youtube.com/watch?v*", background) + re.match("https://www.youtube.com/watch?v*", background.strip()) and background is not None ): + print_substep(f"Downloading video from: {background}", style="bold") ydl.download(background) - else: # if the link is not youtube link - raise ValueError + else: # if the link is not youtube link + raise ValueError except ( ValueError # add more exceptions