From f589ca7b6faa8ee0c4d105fb1f5ce60d1db45a97 Mon Sep 17 00:00:00 2001 From: iaacornus Date: Sun, 5 Jun 2022 13:21:02 +0800 Subject: [PATCH] take file as custom background input --- cli.py | 2 -- video_creation/background.py | 12 ++++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cli.py b/cli.py index e0dfcb4..ccaec75 100644 --- a/cli.py +++ b/cli.py @@ -26,8 +26,6 @@ def program_options(): help="Use another sub-reddit.", action="store" ) - # this one accepts link as input, defaults to the minecraft video - # does not accept file or already downloaded background yet. parser.add_argument( "-b", "--background", diff --git a/video_creation/background.py b/video_creation/background.py index 12f5fe8..7dfa22f 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -2,6 +2,7 @@ import re import os 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 @@ -42,12 +43,15 @@ def download_background(background): if background is None: ydl.download("https://www.youtube.com/watch?v=n_Dv4JMiwK8") elif background is not None: - if ( - re.match("https://www.youtube.com/watch?v*", background.strip()) - and background is not None - ): + check_link = re.match( + "https://www.youtube.com/watch?v*", background.strip() + ) + if check_link and background is not None: print_substep(f"Downloading video from: {background}", style="bold") ydl.download(background) + elif background is not None and not check_link: + print_substep(f"Using the given video file: {background}", style="bold") + os.replace(background.strip(), "assets/mp4/background.mp4") else: # if the link is not youtube link raise ValueError except (