From 410f44297632363b095859b178b6f242cda0c597 Mon Sep 17 00:00:00 2001 From: Kristian Date: Fri, 22 Mar 2024 17:48:14 +0100 Subject: [PATCH] Revert "meme support" This reverts commit b508f2af7353e15070d64bdaa8b9e2aa303bc2ea. --- TTS/engine_wrapper.py | 2 +- main.py | 52 +++---------------------- utils/.config.template.toml | 2 - utils/subreddit.py | 6 +-- video_creation/final_video.py | 45 +++++++++------------ video_creation/screenshot_downloader.py | 8 +--- 6 files changed, 31 insertions(+), 84 deletions(-) diff --git a/TTS/engine_wrapper.py b/TTS/engine_wrapper.py index cf5faa9..6d498d2 100644 --- a/TTS/engine_wrapper.py +++ b/TTS/engine_wrapper.py @@ -75,7 +75,7 @@ class TTSEngine: # processed_text = ##self.reddit_object["thread_post"] != "" idx = 0 - if settings.config["settings"]["storymode"] and not settings.config["settings"]["mememode"]: + if settings.config["settings"]["storymode"]: if settings.config["settings"]["storymodemethod"] == 0: if len(self.reddit_object["thread_post"]) > self.tts_module.max_chars: self.split_post(self.reddit_object["thread_post"], "postaudio") diff --git a/main.py b/main.py index f01fa94..0a401c3 100755 --- a/main.py +++ b/main.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import math import sys -import os from os import name from pathlib import Path from subprocess import Popen @@ -27,8 +26,6 @@ from video_creation.final_video import make_final_video from video_creation.screenshot_downloader import get_screenshots_of_reddit_posts from video_creation.voices import save_text_to_mp3 -from moviepy.editor import VideoFileClip, concatenate_videoclips - __VERSION__ = "3.2.1" print( @@ -66,50 +63,13 @@ def main(POST_ID=None) -> None: def run_many(times) -> None: - if not settings.config["settings"]["mememode"]: - for x in range(1, times + 1): - print_step( - f'on the {x}{("th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th")[x % 10]} iteration of {times}' - ) # correct 1st 2nd 3rd 4th 5th.... - main() - Popen("cls" if name == "nt" else "clear", shell=True).wait() - else: - for x in range(1, times + 1): - print_step( - f'on the {x}{("th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th")[x % 10]} iteration of {times}' - ) # correct 1st 2nd 3rd 4th 5th.... - main() - Popen("cls" if name == "nt" else "clear", shell=True).wait() - - make_meme_video() - -def make_meme_video(): - if not os.path.exists("./clipped"): - os.mkdir("./clipped") - directory = f'./results/{settings.config["reddit"]["thread"]["subreddit"]}' - - print(directory) - - # Get a list of all MP4 files in the directory - mp4_files = [f for f in os.listdir(directory) if f.endswith('.mp4')] - - # Create a list of VideoFileClip objects - clips = [VideoFileClip(os.path.join(directory, f)) for f in mp4_files] - - # Concatenate the clips into a single video - final_clip = concatenate_videoclips(clips) - - # Write the final video to a file - output_file = './clipped/output.mp4' - final_clip.write_videofile(output_file) - - # Close the video clips - for clip in clips: - clip.close() + for x in range(1, times + 1): + print_step( + f'on the {x}{("th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th")[x % 10]} iteration of {times}' + ) # correct 1st 2nd 3rd 4th 5th.... + main() + Popen("cls" if name == "nt" else "clear", shell=True).wait() - # Delete the individual MP4 files - for f in mp4_files: - os.remove(os.path.join(directory, f)) def shutdown() -> NoReturn: if "redditid" in globals(): diff --git a/utils/.config.template.toml b/utils/.config.template.toml index 0f6165e..211cc97 100644 --- a/utils/.config.template.toml +++ b/utils/.config.template.toml @@ -25,8 +25,6 @@ theme = { optional = false, default = "dark", example = "light", options = ["dar times_to_run = { optional = false, default = 1, example = 2, explanation = "Used if you want to run multiple times. Set to an int e.g. 4 or 29 or 1", type = "int", nmin = 1, oob_error = "It's very hard to run something less than once." } opacity = { optional = false, default = 0.9, example = 0.8, explanation = "Sets the opacity of the comments when overlayed over the background", type = "float", nmin = 0, nmax = 1, oob_error = "The opacity HAS to be between 0 and 1", input_error = "The opacity HAS to be a decimal number between 0 and 1" } #transition = { optional = true, default = 0.2, example = 0.2, explanation = "Sets the transition time (in seconds) between the comments. Set to 0 if you want to disable it.", type = "float", nmin = 0, nmax = 2, oob_error = "The transition HAS to be between 0 and 2", input_error = "The opacity HAS to be a decimal number between 0 and 2" } -mememode = { optional = true, type = "bool", default = false, example = false, options = [true, false,], explanation = "Only show post content, and multipile of them (no comments)" } -memes_per_vid = { optional = true, default = 10, example = 10, explanation = "Number of memes per video", type = "int", nmin = 1, oob_error = "It's very hard to run something less than once." } storymode = { optional = true, type = "bool", default = false, example = false, options = [true, false,], explanation = "Only read out title and post content, great for subreddits with stories" } storymodemethod= { optional = true, default = 1, example = 1, explanation = "Style that's used for the storymode. Set to 0 for single picture display in whole video, set to 1 for fancy looking video ", type = "int", nmin = 0, oob_error = "It's very hard to run something less than once.", options = [0, 1] } storymode_max_length = { optional = true, default = 1000, example = 1000, explanation = "Max length of the storymode video in characters. 200 characters are approximately 50 seconds.", type = "int", nmin = 1, oob_error = "It's very hard to make a video under a second." } diff --git a/utils/subreddit.py b/utils/subreddit.py index c5818d2..403b6d3 100644 --- a/utils/subreddit.py +++ b/utils/subreddit.py @@ -50,7 +50,7 @@ def get_subreddit_undone(submissions: list, subreddit, times_checked=0, similari f'This post has under the specified minimum of comments ({settings.config["reddit"]["thread"]["min_comments"]}). Skipping...' ) continue - if settings.config["settings"]["storymode"] and not settings.config["settings"]["mememode"]: + if settings.config["settings"]["storymode"]: if not submission.selftext: print_substep("You are trying to use story mode on post with no post text") continue @@ -63,9 +63,9 @@ def get_subreddit_undone(submissions: list, subreddit, times_checked=0, similari f"Post is too long ({len(submission.selftext)}), try with a different post. ({settings.config['settings']['storymode_max_length']} character limit)" ) continue - elif len(submission.selftext) < 30: + elif len(submission.selftext) < 30: continue - if settings.config["settings"]["storymode"] and not submission.is_self and not settings.config["settings"]["mememode"]: + if settings.config["settings"]["storymode"] and not submission.is_self: continue if similarity_scores is not None: return submission, similarity_scores[i].item() diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 48404eb..5069474 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -99,7 +99,7 @@ def prepare_background(reddit_id: str, W: int, H: int) -> str: .overwrite_output() ) try: - output.run(quiet=False) + output.run(quiet=True) except ffmpeg.Error as e: print(e.stderr.decode("utf8")) exit(1) @@ -166,13 +166,12 @@ def make_final_video( if settings.config["settings"]["storymode"]: if settings.config["settings"]["storymodemethod"] == 0: audio_clips = [ffmpeg.input(f"assets/temp/{reddit_id}/mp3/title.mp3")] - #audio_clips.insert(1, ffmpeg.input(f"assets/temp/{reddit_id}/mp3/postaudio.mp3")) + audio_clips.insert(1, ffmpeg.input(f"assets/temp/{reddit_id}/mp3/postaudio.mp3")) elif settings.config["settings"]["storymodemethod"] == 1: - if not settings.config["settings"]["mememode"]: - audio_clips = [ - ffmpeg.input(f"assets/temp/{reddit_id}/mp3/postaudio-{i}.mp3") - for i in track(range(number_of_clips + 1), "Collecting the audio files...") - ] + audio_clips = [ + ffmpeg.input(f"assets/temp/{reddit_id}/mp3/postaudio-{i}.mp3") + for i in track(range(number_of_clips + 1), "Collecting the audio files...") + ] audio_clips.insert(0, ffmpeg.input(f"assets/temp/{reddit_id}/mp3/title.mp3")) else: @@ -192,7 +191,7 @@ def make_final_video( audio_concat = ffmpeg.concat(*audio_clips, a=1, v=0) ffmpeg.output( audio_concat, f"assets/temp/{reddit_id}/audio.mp3", **{"b:a": "192k"} - ).overwrite_output().run(quiet=False) + ).overwrite_output().run(quiet=True) console.log(f"[bold green] Video Will Be: {length} Seconds Long") @@ -205,20 +204,18 @@ def make_final_video( image_clips.insert( 0, ffmpeg.input(f"assets/temp/{reddit_id}/png/title.png")["v"].filter( - "scale", screenshot_width, -1, + "scale", screenshot_width, -1 ), ) current_time = 0 if settings.config["settings"]["storymode"]: - audio_clips_durations = [] - if not settings.config["settings"]["mememode"]: - audio_clips_durations = [ - float( - ffmpeg.probe(f"assets/temp/{reddit_id}/mp3/postaudio-{i}.mp3")["format"]["duration"] - ) - for i in range(number_of_clips) - ] + audio_clips_durations = [ + float( + ffmpeg.probe(f"assets/temp/{reddit_id}/mp3/postaudio-{i}.mp3")["format"]["duration"] + ) + for i in range(number_of_clips) + ] audio_clips_durations.insert( 0, float(ffmpeg.probe(f"assets/temp/{reddit_id}/mp3/title.mp3")["format"]["duration"]), @@ -230,8 +227,6 @@ def make_final_video( "scale", screenshot_width, -1 ), ) - if settings.config["settings"]["mememode"]: audio_clips_durations[0] += 2 - background_clip = background_clip.overlay( image_clips[0], enable=f"between(t,{current_time},{current_time + audio_clips_durations[0]})", @@ -239,7 +234,7 @@ def make_final_video( y="(main_h-overlay_h)/2", ) current_time += audio_clips_durations[0] - elif settings.config["settings"]["storymodemethod"] == 1 and not settings.config["settings"]["mememode"]: + elif settings.config["settings"]["storymodemethod"] == 1: for i in track(range(0, number_of_clips + 1), "Collecting the image files..."): image_clips.append( ffmpeg.input(f"assets/temp/{reddit_id}/png/img{i}.png")["v"].filter( @@ -253,8 +248,6 @@ def make_final_video( y="(main_h-overlay_h)/2", ) current_time += audio_clips_durations[i] - elif settings.config["settings"]["mememode"]: - pass else: for i in range(0, number_of_clips + 1): image_clips.append( @@ -361,10 +354,10 @@ def make_final_video( "threads": multiprocessing.cpu_count(), }, ).overwrite_output().global_args("-progress", progress.output_file.name).run( - quiet=False, + quiet=True, overwrite_output=True, capture_stdout=False, - capture_stderr=True, + capture_stderr=False, ) except ffmpeg.Error as e: print(e.stderr.decode("utf8")) @@ -391,10 +384,10 @@ def make_final_video( "threads": multiprocessing.cpu_count(), }, ).overwrite_output().global_args("-progress", progress.output_file.name).run( - quiet=False, + quiet=True, overwrite_output=True, capture_stdout=False, - capture_stderr=True, + capture_stderr=False, ) except ffmpeg.Error as e: print(e.stderr.decode("utf8")) diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index e5a83ab..d688caf 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -28,7 +28,6 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): H: Final[int] = int(settings.config["settings"]["resolution_h"]) lang: Final[str] = settings.config["reddit"]["thread"]["post_lang"] storymode: Final[bool] = settings.config["settings"]["storymode"] - mememode: Final[bool] = settings.config["settings"]["mememode"] print_step("Downloading screenshots of reddit posts...") reddit_id = re.sub(r"[^\w\s-]", "", reddit_object["thread_id"]) @@ -169,8 +168,6 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): print_substep("Skipping translation...") postcontentpath = f"assets/temp/{reddit_id}/png/title.png" - - try: if settings.config["settings"]["zoom"] != 1: # store zoom settings @@ -184,7 +181,6 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): page.screenshot(clip=location, path=postcontentpath) else: page.locator('[data-test-id="post-content"]').screenshot(path=postcontentpath) - except Exception as e: print_substep("Something went wrong!", style="red") resp = input( @@ -204,11 +200,11 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): raise e - if storymode and not mememode: + if storymode: page.locator('[data-click-id="text"]').first.screenshot( path=f"assets/temp/{reddit_id}/png/story_content.png" ) - elif not mememode: + else: for idx, comment in enumerate( track( reddit_object["comments"][:screenshot_num],