diff --git a/main.py b/main.py index 9242e58..726e772 100755 --- a/main.py +++ b/main.py @@ -26,8 +26,7 @@ from video_creation.background import ( 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 +from video_creation.memes import make_meme_video __VERSION__ = "3.2.1" @@ -75,34 +74,6 @@ def run_many(times) -> None: if settings.config["settings"]["mememode"]: 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() - - # Delete the individual MP4 files - for f in mp4_files: - os.remove(os.path.join(directory, f)) - def shutdown() -> NoReturn: if "redditid" in globals(): print_markdown("## Clearing temp files") diff --git a/video_creation/memes.py b/video_creation/memes.py new file mode 100644 index 0000000..0dd621d --- /dev/null +++ b/video_creation/memes.py @@ -0,0 +1,31 @@ +from utils import settings + +from moviepy.editor import VideoFileClip, concatenate_videoclips + +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() + + # Delete the individual MP4 files + for f in mp4_files: + os.remove(os.path.join(directory, f)) \ No newline at end of file