adaptations in filePath and toml for audio option

pull/1590/head
Lucas 2 years ago
parent f2d89a10dd
commit ba5e8b8987

@ -49,8 +49,10 @@ def main(POST_ID=None) -> None:
redditid = id(reddit_object) redditid = id(reddit_object)
length, number_of_comments = save_text_to_mp3(reddit_object) length, number_of_comments = save_text_to_mp3(reddit_object)
length = math.ceil(length) length = math.ceil(length)
bg_config = {}
get_screenshots_of_reddit_posts(reddit_object, number_of_comments) get_screenshots_of_reddit_posts(reddit_object, number_of_comments)
bg_config = get_background_config() bg_config["video"] = get_background_config("video")
bg_config["audio"] = get_background_config("audio")
download_background(bg_config) download_background(bg_config)
chop_background_video(bg_config, length, reddit_object) chop_background_video(bg_config, length, reddit_object)
make_final_video(number_of_comments, length, reddit_object, bg_config) make_final_video(number_of_comments, length, reddit_object, bg_config)

@ -0,0 +1,8 @@
{
"__comment": "Supported Backgrounds Audio. Can add/remove background audio here...",
"minecraft": [
"https://www.youtube.com/watch?v=2p3nBYUaJz8",
"minecraft.mp4",
"adriPixs"
]
}

@ -5,27 +5,37 @@ from pathlib import Path
from random import randrange from random import randrange
from typing import Any, Tuple from typing import Any, Tuple
from moviepy.editor import VideoFileClip from moviepy.editor import VideoFileClip,AudioFileClip
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from pytube import YouTube from pytube import YouTube
from pytube.cli import on_progress from pytube.cli import on_progress
from utils import settings from utils import settings
from utils.console import print_step, print_substep from utils.console import print_step, print_substep
# Load background videos def load_background_options():
with open("./utils/backgrounds.json") as json_file: background_options = {}
background_options = json.load(json_file) # Load background videos
with open("./utils/background_videos.json") as json_file:
background_options["video"] = json.load(json_file)
# Remove "__comment" from backgrounds # Load background audios
background_options.pop("__comment", None) with open("./utils/background_audios.json") as json_file:
background_options["audio"] = json.load(json_file)
# Remove "__comment" from backgrounds
background_options["video"].pop("__comment", None)
background_options["audio"].pop("__comment", None)
# Add position lambda function
# (https://zulko.github.io/moviepy/ref/VideoClip/VideoClip.html#moviepy.video.VideoClip.VideoClip.set_position)
for name in list(background_options["video"].keys()):
pos = background_options["video"][name][3]
# Add position lambda function if pos != "center":
# (https://zulko.github.io/moviepy/ref/VideoClip/VideoClip.html#moviepy.video.VideoClip.VideoClip.set_position) background_options["video"][name][3] = lambda t: ("center", pos + t)
for name in list(background_options.keys()):
pos = background_options[name][3] return background_options
if pos != "center":
background_options[name][3] = lambda t: ("center", pos + t)
def get_start_and_end_times(video_length: int, length_of_clip: int) -> Tuple[int, int]: def get_start_and_end_times(video_length: int, length_of_clip: int) -> Tuple[int, int]:
@ -42,11 +52,11 @@ def get_start_and_end_times(video_length: int, length_of_clip: int) -> Tuple[int
return random_time, random_time + video_length return random_time, random_time + video_length
def get_background_config(): def get_background_config(mode: str):
"""Fetch the background/s configuration""" """Fetch the background/s configuration"""
try: try:
choice = str( choice = str(
settings.config["settings"]["background"]["background_choice"] settings.config["settings"]["background"][f"background_{mode}_choice"]
).casefold() ).casefold()
except AttributeError: except AttributeError:
print_substep("No background selected. Picking random background'") print_substep("No background selected. Picking random background'")
@ -54,10 +64,10 @@ def get_background_config():
# Handle default / not supported background using default option. # Handle default / not supported background using default option.
# Default : pick random from supported background. # Default : pick random from supported background.
if not choice or choice not in background_options: if not choice or choice not in background_options[mode]:
choice = random.choice(list(background_options.keys())) choice = random.choice(list(background_options[mode].keys()))
return background_options[choice] return background_options[mode][choice]
def download_background(background_config: Tuple[str, str, str, Any]): def download_background(background_config: Tuple[str, str, str, Any]):
@ -78,6 +88,8 @@ def download_background(background_config: Tuple[str, str, str, Any]):
print_substep("Background video downloaded successfully! 🎉", style="bold green") print_substep("Background video downloaded successfully! 🎉", style="bold green")
def chop_background_video( def chop_background_video(
background_config: Tuple[str, str, str, Any], video_length: int, reddit_object: dict background_config: Tuple[str, str, str, Any], video_length: int, reddit_object: dict
): ):
@ -108,3 +120,6 @@ def chop_background_video(
new.write_videofile(f"assets/temp/{id}/background.mp4") new.write_videofile(f"assets/temp/{id}/background.mp4")
print_substep("Background video chopped successfully!", style="bold green") print_substep("Background video chopped successfully!", style="bold green")
return background_config[2] return background_config[2]
# Create a tuple for downloads background (background_audio_options, background_video_options)
background_options = load_background_options()
Loading…
Cancel
Save