takes link as an input

pull/280/head
iaacornus 3 years ago
parent 558d9bd531
commit 2afc687d98
No known key found for this signature in database
GPG Key ID: 281739AE7252598C

@ -1,3 +1,4 @@
import re
from random import randrange from random import randrange
from pathlib import Path from pathlib import Path
@ -12,15 +13,17 @@ def get_start_and_end_times(video_length, length_of_clip):
random_time = randrange(180, int(length_of_clip) - int(video_length)) random_time = randrange(180, int(length_of_clip) - int(video_length))
return random_time, random_time + video_length return random_time, random_time + video_length
def download_background():
def download_background(background):
"""Downloads the background video from youtube. """Downloads the background video from youtube.
Shoutout to: bbswitzer (https://www.youtube.com/watch?v=n_Dv4JMiwK8) Shoutout to: bbswitzer (https://www.youtube.com/watch?v=n_Dv4JMiwK8)
""" """
if not Path("assets/mp4/background.mp4").is_file(): if not Path("assets/mp4/background.mp4").is_file():
print_step( print_step( # removed minecraft, since the background can be changed according to user input.
"We need to download the Minecraft background video. This is fairly large but it's only done once." "We need to download the background video. This may be"
+ " large, depending on the input but it's only done once."
) )
print_substep("Downloading the background video... please be patient.") print_substep("Downloading the background video... please be patient.")
@ -30,9 +33,25 @@ def download_background():
"merge_output_format": "mp4", "merge_output_format": "mp4",
} }
try:
with YoutubeDL(ydl_opts) as ydl: with YoutubeDL(ydl_opts) as ydl:
if background is None:
ydl.download("https://www.youtube.com/watch?v=n_Dv4JMiwK8") ydl.download("https://www.youtube.com/watch?v=n_Dv4JMiwK8")
if (
re.match("https://*youtube.com*", background) and background is not None
):
ydl.download(background)
else: # if the link is not youtube link
raise ValueError
except (
ConnectionError,
FileNotFoundError,
ValueError
# add more exceptions
):
print_substep("The given link is not accepted!", style="bold red")
else:
print_substep("Background video downloaded successfully!", style="bold green") print_substep("Background video downloaded successfully!", style="bold green")

Loading…
Cancel
Save