From d8347e08b9c2a6524823c9b030cce60c27cb06dc Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 24 Apr 2023 23:55:18 -0300 Subject: [PATCH] Fixed issues and improvements related by Jason --- main.py | 7 ++++--- video_creation/background.py | 4 ++-- video_creation/final_video.py | 17 ++++++++++------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 0a17968..2b78629 100755 --- a/main.py +++ b/main.py @@ -51,10 +51,11 @@ 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["video"] = get_background_config("video") - bg_config["audio"] = get_background_config("audio") + bg_config = { + "video": get_background_config("video"), + "audio": get_background_config("audio"), + } download_background_video(bg_config["video"]) download_background_audio(bg_config["audio"]) chop_background(bg_config, length, reddit_object) diff --git a/video_creation/background.py b/video_creation/background.py index d27ee6b..010f15e 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -22,8 +22,8 @@ def load_background_options(): background_options["audio"] = json.load(json_file) # Remove "__comment" from backgrounds - background_options["video"].pop("__comment", None) - background_options["audio"].pop("__comment", None) + del background_options["video"]["__comment"] + del background_options["audio"]["__comment"] # Add position lambda function # (https://zulko.github.io/moviepy/ref/VideoClip/VideoClip.html#moviepy.video.VideoClip.VideoClip.set_position) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 55e0d39..ca801c5 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -285,11 +285,11 @@ def make_final_video( subreddit = settings.config["reddit"]["thread"]["subreddit"] if not exists(f"./results/{subreddit}"): - print_substep("The 'results' folder didn't exist so I made it") + print_substep("The 'results' folder could not be found so it was automatically created.") os.makedirs(f"./results/{subreddit}") if not exists(f"./results/{subreddit}/OnlyTTS") and allowOnlyTTSFolder: - print_substep("The 'OnlyTTS' folder didn't exist so I made it") + print_substep("The 'OnlyTTS' folder could not be found so it was automatically created.") os.makedirs(f"./results/{subreddit}/OnlyTTS") # create a thumbnail for the video @@ -297,7 +297,7 @@ def make_final_video( if settingsbackground["background_thumbnail"]: if not exists(f"./results/{subreddit}/thumbnails"): - print_substep("The results/thumbnails folder didn't exist so I made it") + print_substep("The 'results/thumbnails' folder could not be found so it was automatically created.") os.makedirs(f"./results/{subreddit}/thumbnails") # get the first file with the .png extension from assets/backgrounds and use it as a background for the thumbnail first_image = next( @@ -351,13 +351,14 @@ def make_final_video( old_percentage = pbar.n pbar.update(status - old_percentage) - path = f"results/{subreddit}" - + defaultPath = f"results/{subreddit}" with ProgressFfmpeg(length, on_update_example) as progress: + path = defaultPath + f"/{filename}" + path = path[:251] + ".mp4" #Prevent a error by limiting the path length, do not change this. ffmpeg.output( background_clip, final_audio, - path+f"/{filename}.mp4", + path, f="mp4", **{ "c:v": "h264", @@ -374,12 +375,14 @@ def make_final_video( old_percentage = pbar.n pbar.update(100 - old_percentage) if(allowOnlyTTSFolder): + path = defaultPath + f"/OnlyTTS/{filename}" + path = path[:251] + ".mp4" #Prevent a error by limiting the path length, do not change this. print_step("Rendering the Only TTS Video 🎥") with ProgressFfmpeg(length, on_update_example) as progress: ffmpeg.output( background_clip, audio, - path+f"/OnlyTTS/{filename}.mp4", + path, f="mp4", **{ "c:v": "h264",