From 11de0fd3240aeff30d4e0ccd9a4ef735c20a98d8 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sun, 3 Jul 2022 18:47:35 +0100 Subject: [PATCH] fix: length checker works with new duration code --- TTS/engine_wrapper.py | 7 ++++--- main.py | 3 ++- video_creation/final_video.py | 11 ++--------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/TTS/engine_wrapper.py b/TTS/engine_wrapper.py index 692cfdc..77f6eab 100644 --- a/TTS/engine_wrapper.py +++ b/TTS/engine_wrapper.py @@ -4,9 +4,9 @@ from typing import Tuple import re from os import getenv -import sox -from mutagen import MutagenError -from mutagen.mp3 import MP3, HeaderNotFoundError +# import sox +# from mutagen import MutagenError +# from mutagen.mp3 import MP3, HeaderNotFoundError import translators as ts from rich.progress import track from moviepy.editor import AudioFileClip, CompositeAudioClip, concatenate_audioclips @@ -100,6 +100,7 @@ class TTSEngine: # self.length += sox.file_info.duration(f"{self.path}/{filename}.mp3") clip = AudioFileClip(f"{self.path}/{filename}.mp3") self.length += clip.duration + def process_text(text: str): lang = getenv("POSTLANG", "") new_text = sanitize_text(text) diff --git a/main.py b/main.py index 81bec26..e362aad 100755 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ #!/usr/bin/env python - +import math from subprocess import Popen from os import getenv, name from dotenv import load_dotenv @@ -35,6 +35,7 @@ def main(POST_ID=None): cleanup() reddit_object = get_subreddit_threads(POST_ID) length, number_of_comments = save_text_to_mp3(reddit_object) + length = math.ceil(length) download_screenshots_of_reddit_posts(reddit_object, number_of_comments) download_background() chop_background_video(length) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 852c4b2..418254c 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -3,7 +3,6 @@ import multiprocessing import os import re from os.path import exists - from moviepy.editor import ( VideoFileClip, AudioFileClip, @@ -49,13 +48,7 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict[str]): audio_concat = concatenate_audioclips(audio_clips) audio_composite = CompositeAudioClip([audio_concat]) - # Get sum of all clip lengths - total_length = sum([clip.duration for clip in audio_clips]) - # round total_length to an integer - int_total_length = round(total_length) - # Output Length - - console.log(f"[bold green] Video Will Be: {int_total_length} Seconds Long") + console.log(f"[bold green] Video Will Be: {length} Seconds Long") # add title to video image_clips = [] # Gather all images @@ -127,7 +120,7 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict[str]): threads=multiprocessing.cpu_count(), ) ffmpeg_tools.ffmpeg_extract_subclip( - "assets/temp/temp.mp4", 0, length, targetname=f"results/{subreddit}/{filename}" + "assets/temp/temp.mp4", 0, final.duration, targetname=f"results/{subreddit}/{filename}" ) # os.remove("assets/temp/temp.mp4")