From 91d8b90b3eb8a167c820824fb32c88156f4a3079 Mon Sep 17 00:00:00 2001 From: final Date: Sat, 16 Jul 2022 13:21:49 -0500 Subject: [PATCH] Allowed for video resolution changes to occur, as per #943 --- .config.template.toml | 4 +++- main.py | 2 ++ utils/settings.py | 2 +- video_creation/final_video.py | 14 ++++++++++---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.config.template.toml b/.config.template.toml index 18f1b00..747b0e4 100644 --- a/.config.template.toml +++ b/.config.template.toml @@ -32,6 +32,8 @@ storymode = { optional = true, type = "bool", default = false, example = false, [settings.background] background_choice = { optional = true, default = "minecraft", example = "minecraft", options = ["minecraft", "gta", "rocket-league", "motor-gta", ""], explanation = "Sets the background for the video" } +width = { optional = true, default = 1080, example = 1080, explanation = "Sets the width resolution for the video", type = "int", nmin = 1, oob_error = "The width HAS to be greater than 1", input_error = "The width HAS to be an integer greater than 1" } +height = { optional = true, default = 1920, example = 1920, explanation = "Sets the height resolution for the video", type = "int", nmin = 1, oob_error = "The height HAS to be greater than 1", input_error = "The height HAS to be an integer greater than 1" } #background_audio = { optional = true, type = "bool", default = false, example = false, options = [true, # false, #], explaination="Sets a audio to play in the background (put a background.mp3 file in the assets/backgrounds directory for it to be used.)" } @@ -42,4 +44,4 @@ background_choice = { optional = true, default = "minecraft", example = "minecra choice = { optional = false, default = "", options = ["streamlabspolly", "tiktok", "googletranslate", "awspolly", ], example = "streamlabspolly", explanation = "The backend used for TTS generation. This can be left blank and you will be prompted to choose at runtime." } aws_polly_voice = { optional = false, default = "Matthew", example = "Matthew", explanation = "The voice used for AWS Polly" } streamlabs_polly_voice = { optional = false, default = "Matthew", example = "Matthew", explanation = "The voice used for Streamlabs Polly" } -tiktok_voice = { optional = false, default = "en_us_006", example = "en_us_006", explanation = "The voice used for TikTok TTS" } +tiktok_voice = { optional = false, default = "en_us_006", example = "en_us_006", explanation = "The voice used for TikTok TTS" } \ No newline at end of file diff --git a/main.py b/main.py index 10ab3c1..81f94fd 100755 --- a/main.py +++ b/main.py @@ -13,6 +13,7 @@ from video_creation.background import ( get_background_config, ) from video_creation.final_video import make_final_video +from video_creation.final_video import change_background_resolution from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts from video_creation.voices import save_text_to_mp3 @@ -38,6 +39,7 @@ print_step(f"You are using v{__VERSION__} of the bot") def main(POST_ID=None): cleanup() + change_background_resolution() reddit_object = get_subreddit_threads(POST_ID) length, number_of_comments = save_text_to_mp3(reddit_object) length = math.ceil(length) diff --git a/utils/settings.py b/utils/settings.py index a36f63e..5b1a8fb 100755 --- a/utils/settings.py +++ b/utils/settings.py @@ -9,7 +9,7 @@ from utils.console import handle_input console = Console() -config = dict # autocomplete +config: dict | None = None # autocomplete def crawl(obj: dict, func=lambda x, y: print(x, y, end="\n"), path=None): diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 8524051..579737d 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -22,6 +22,12 @@ console = Console() W, H = 1080, 1920 +def change_background_resolution(): + global W + global H + W, H = settings.config["settings"]["background"]["width"], settings.config["settings"]["background"]["height"] + + def name_normalize(name: str) -> str: name = re.sub(r'[?\\"%*:|<>]', "", name) name = re.sub(r"( [w,W]\s?\/\s?[o,O,0])", r" without", name) @@ -43,10 +49,10 @@ def name_normalize(name: str) -> str: def make_final_video( - number_of_clips: int, - length: int, - reddit_obj: dict, - background_config: Tuple[str, str, str, Any], + number_of_clips: int, + length: int, + reddit_obj: dict, + background_config: Tuple[str, str, str, Any], ): """Gathers audio clips, gathers all screenshots, stitches them together and saves the final video to assets/temp Args: