adaptations in filePath and toml for audio option
This commit is contained in:
1 parent
f2d89a10dd
commit
ba5e8b8987
4 files changed
+43
-18
No files matched your search
@@ -49,8 +49,10 @@ def main(POST_ID=None) -> None:
|
||||
redditid = id(reddit_object)
|
||||
length, number_of_comments = save_text_to_mp3(reddit_object)
|
||||
length = math.ceil(length)
|
||||
bg_config = {}
|
||||
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)
|
||||
chop_background_video(bg_config, length, reddit_object)
|
||||
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"
|
||||
]
|
||||
}
|
||||
File renamed without changes.
@@ -5,27 +5,37 @@ from pathlib import Path
|
||||
from random import randrange
|
||||
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 pytube import YouTube
|
||||
from pytube.cli import on_progress
|
||||
from utils import settings
|
||||
from utils.console import print_step, print_substep
|
||||
|
||||
# Load background videos
|
||||
with open("./utils/backgrounds.json") as json_file:
|
||||
background_options = json.load(json_file)
|
||||
def load_background_options():
|
||||
background_options = {}
|
||||
# Load background videos
|
||||
with open("./utils/background_videos.json") as json_file:
|
||||
background_options["video"] = json.load(json_file)
|
||||
|
||||
# Remove "__comment" from backgrounds
|
||||
background_options.pop("__comment", None)
|
||||
# Load background audios
|
||||
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
|
||||
# (https://zulko.github.io/moviepy/ref/VideoClip/VideoClip.html#moviepy.video.VideoClip.VideoClip.set_position)
|
||||
for name in list(background_options.keys()):
|
||||
pos = background_options[name][3]
|
||||
if pos != "center":
|
||||
background_options["video"][name][3] = lambda t: ("center", pos + t)
|
||||
|
||||
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]:
|
||||
@@ -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
|
||||
|
||||
|
||||
def get_background_config():
|
||||
def get_background_config(mode: str):
|
||||
"""Fetch the background/s configuration"""
|
||||
try:
|
||||
choice = str(
|
||||
settings.config["settings"]["background"]["background_choice"]
|
||||
settings.config["settings"]["background"][f"background_{mode}_choice"]
|
||||
).casefold()
|
||||
except AttributeError:
|
||||
print_substep("No background selected. Picking random background'")
|
||||
@@ -54,10 +64,10 @@ def get_background_config():
|
||||
|
||||
# Handle default / not supported background using default option.
|
||||
# Default : pick random from supported background.
|
||||
if not choice or choice not in background_options:
|
||||
choice = random.choice(list(background_options.keys()))
|
||||
if not choice or choice not in background_options[mode]:
|
||||
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]):
|
||||
@@ -78,6 +88,8 @@ def download_background(background_config: Tuple[str, str, str, Any]):
|
||||
print_substep("Background video downloaded successfully! 🎉", style="bold green")
|
||||
|
||||
|
||||
|
||||
|
||||
def chop_background_video(
|
||||
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")
|
||||
print_substep("Background video chopped successfully!", style="bold green")
|
||||
return background_config[2]
|
||||
|
||||
# Create a tuple for downloads background (background_audio_options, background_video_options)
|
||||
background_options = load_background_options()
|
||||
Reference in new issue
Block a user