add custom background

pull/323/head
alperen cantez 3 years ago
parent 4185ce2a28
commit f5db385758

@ -6,22 +6,16 @@ from pathlib import Path
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from moviepy.editor import VideoFileClip from moviepy.editor import VideoFileClip
from utils.console import print_step, print_substep from utils.console import print_step, print_substep
import requests
def get_start_and_end_times(video_length, length_of_clip): 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 choose_bg(bg_video_path):
"""Downloads the background video from youtube.
Shoutout to: bbswitzer (https://www.youtube.com/watch?v=n_Dv4JMiwK8)
"""
if not Path("assets/mp4/background.mp4").is_file():
print_step( print_step(
"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 is fairly large but it's only done once."
) )
print_substep("Downloading the background video... please be patient.") print_substep("Downloading the background video... please be patient.")
@ -32,10 +26,30 @@ def download_background():
} }
with YoutubeDL(ydl_opts) as ydl: with YoutubeDL(ydl_opts) as ydl:
ydl.download("https://www.youtube.com/watch?v=n_Dv4JMiwK8") ydl.download(bg_video_path)
# check if the link is reachable
request = requests.get(bg_video_path, allow_redirects=False)
if request.status_code >= 200:
print_substep("Background video downloaded successfully!", style="bold green") print_substep("Background video downloaded successfully!", style="bold green")
else:
print_substep("The link you've given might be broken or private, make sure the video can be accessed publicly")
def download_background():
"""Downloads the background video from youtube.
Shoutout to: bbswitzer (https://www.youtube.com/watch?v=n_Dv4JMiwK8)
"""
get_bg_preference = input("The default background video is a Minecraft parkour, do you want to provide a custom video? (y/n)").lower()
if not Path("assets/mp4/background.mp4").is_file() and get_bg_preference == "y":
choose_bg(input("Please insert the YouTube link to your video: "))
elif get_bg_preference == "n":
print_substep("Downloading default Minecraft background! 👾")
choose_bg("https://www.youtube.com/watch?v=n_Dv4JMiwK8")
else:
print_substep("Invalid input or you already have a background video downloaded, if so please delete the video before a retry", style="red")
def chop_background_video(video_length): def chop_background_video(video_length):
print_step("Finding a spot in the background video to chop...") print_step("Finding a spot in the background video to chop...")

Loading…
Cancel
Save