fixed conditions to download youtube link

pull/280/head
iaacornus 3 years ago
parent 8e4d6ac4bf
commit 9230abb8a0
No known key found for this signature in database
GPG Key ID: 281739AE7252598C

@ -1,6 +1,7 @@
import re import re
from random import randrange from random import randrange
from pathlib import Path from pathlib import Path
from turtle import back
from yt_dlp import YoutubeDL from yt_dlp import YoutubeDL
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip 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() background_check = Path("assets/mp4/background.mp4").is_file()
if background is not None or not background_check: if background is not None or not background_check:
if 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: try:
with YoutubeDL(ydl_opts) as ydl: with YoutubeDL(ydl_opts) as ydl:
if background is None: if background is None:
ydl.download("https://www.youtube.com/watch?v=n_Dv4JMiwK8") ydl.download("https://www.youtube.com/watch?v=n_Dv4JMiwK8")
else: elif background is not None:
if ( 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 and background is not None
): ):
print_substep(f"Downloading video from: {background}", style="bold")
ydl.download(background) ydl.download(background)
else: # if the link is not youtube link else: # if the link is not youtube link
raise ValueError raise ValueError
except ( except (
ValueError ValueError
# add more exceptions # add more exceptions

Loading…
Cancel
Save