improved the conditions and allow file as an input

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

@ -21,10 +21,7 @@ def download_background(background):
Shoutout to: bbswitzer (https://www.youtube.com/watch?v=n_Dv4JMiwK8) Shoutout to: bbswitzer (https://www.youtube.com/watch?v=n_Dv4JMiwK8)
""" """
print_step( # removed minecraft, since the background can be changed according to user input. print_step("Downloading the background video.")
"Downloading the background video."
)
ydl_opts = { ydl_opts = {
"outtmpl": "assets/mp4/background.mp4", "outtmpl": "assets/mp4/background.mp4",
"merge_output_format": "mp4", "merge_output_format": "mp4",
@ -47,17 +44,20 @@ def download_background(background):
elif background is not None: elif background is not None:
check_link = re.match( check_link = re.match(
"https://www.youtube.com/watch?v*", background.strip() "https://www.youtube.com/watch?v*", background.strip()
) or re.match(
"https://youtu.be/*", background.strip()
) )
if check_link and background is not None:
if check_link:
print_substep(f"Downloading video from: {background}", style="bold") print_substep(f"Downloading video from: {background}", style="bold")
ydl.download(background) ydl.download(background)
elif background is not None and not check_link: elif re.match(background[-4], "mp4"):
print_substep(f"Using the given video file: {background}", style="bold") print_substep(f"Using the given video file: {background}", style="bold")
os.replace(background.strip(), "assets/mp4/background.mp4") os.replace(background.strip(), "assets/mp4/background.mp4")
else: # if the link is not youtube link else: # if the link is not youtube link or a file
raise ValueError raise ValueError
except ValueError: except ValueError:
print_substep("The given link is not accepted!", style="bold red") print_substep("Invalid input!", style="bold red")
except ConnectionError: except ConnectionError:
print_substep("There is a connection error!", style="bold red") print_substep("There is a connection error!", style="bold red")
except DownloadError: except DownloadError:

Loading…
Cancel
Save