From 7461ddb811b56f44bff3b66e42ed9763783875d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Mustafa=20Ak=C5=9Fam?= Date: Mon, 11 Jul 2022 20:26:34 +0300 Subject: [PATCH 01/21] Create index.html Created index.html file for quick access to video via another device. --- index.html | 281 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 281 insertions(+) create mode 100644 index.html diff --git a/index.html b/index.html new file mode 100644 index 0000000..46ae793 --- /dev/null +++ b/index.html @@ -0,0 +1,281 @@ + + + + + + RedditVideoMakerBot + + + + + + + + + +
+ +
+ +
+
+
+ +
+
+ +
+
+ +
+ +
+
+
+
+ + + + + + + + + + + + \ No newline at end of file From c412155720d3cb6544608e0fed87e364b0a6fa37 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 8 Jul 2022 00:50:15 -0400 Subject: [PATCH 02/21] background audio implementation --- .config.template.toml | 5 ++ TTS/engine_wrapper.py | 15 +++-- TTS/streamlabs_polly.py | 4 +- main.py | 2 +- reddit/subreddit.py | 10 ++-- utils/voice.py | 2 +- video_creation/background.py | 2 +- video_creation/final_video.py | 110 +++++++++++----------------------- video_creation/voices.py | 2 +- 9 files changed, 62 insertions(+), 90 deletions(-) diff --git a/.config.template.toml b/.config.template.toml index ddfa293..16a6436 100644 --- a/.config.template.toml +++ b/.config.template.toml @@ -29,10 +29,15 @@ opacity = { optional = false, default = 0.9, example = 0.8, explanation = "Sets storymode = { optional = true, type = "bool", default = false, example = false, options = [true, false, ], explanation = "not yet implemented" } + +[settings.background] background_choice = { optional = true, default = "minecraft", example = "minecraft", options = ["minecraft", "gta", "rocket-league", "motor-gta", ""], explanation = "Sets the background for the video" } 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.)" } +background_audio_volume = { optional = true, type = "float", default = 0.3, example = 0.1, explanation="Sets the volume of the background audio. only used if the background_audio is also set to true" } + + [settings.tts] 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" } diff --git a/TTS/engine_wrapper.py b/TTS/engine_wrapper.py index df90569..4f3cf1c 100644 --- a/TTS/engine_wrapper.py +++ b/TTS/engine_wrapper.py @@ -47,7 +47,7 @@ class TTSEngine: Path(self.path).mkdir(parents=True, exist_ok=True) - # This file needs to be removed in case this post does not use post text, so that it wont appear in the final video + # This file needs to be removed in case this post does not use post text, so that it won't appear in the final video try: Path(f"{self.path}/posttext.mp3").unlink() except OSError: @@ -67,10 +67,12 @@ class TTSEngine: # ! Stop creating mp3 files if the length is greater than max length. if self.length > self.max_length: break - if not self.tts_module.max_chars: + if ( + len(comment["comment_body"]) > self.tts_module.max_chars + ): # Split the comment if it is too long + self.split_post(comment["comment_body"], idx) # Split the comment + else: # If the comment is not too long, just call the tts engine self.call_tts(f"{idx}", comment["comment_body"]) - else: - self.split_post(comment["comment_body"], idx) print_substep("Saved Text to MP3 files successfully.", style="bold green") return self.length, idx @@ -84,9 +86,12 @@ class TTSEngine: ) ] - idy = None for idy, text_cut in enumerate(split_text): # print(f"{idx}-{idy}: {text_cut}\n") + if text_cut == "": + print("Empty text cut: tell the devs about this") + continue + self.call_tts(f"{idx}-{idy}.part", text_cut) split_files.append(AudioFileClip(f"{self.path}/{idx}-{idy}.part.mp3")) CompositeAudioClip([concatenate_audioclips(split_files)]).write_audiofile( diff --git a/TTS/streamlabs_polly.py b/TTS/streamlabs_polly.py index b7365ab..a5fda6a 100644 --- a/TTS/streamlabs_polly.py +++ b/TTS/streamlabs_polly.py @@ -48,10 +48,12 @@ class StreamlabsPolly: else: try: + print(body) + print(response.json()) voice_data = requests.get(response.json()["speak_url"]) with open(filepath, "wb") as f: f.write(voice_data.content) - except (KeyError, JSONDecodeError): + except (KeyError, JSONDecodeError) as e: try: if response.json()["error"] == "No text specified!": raise ValueError("Please specify a text to convert to speech.") diff --git a/main.py b/main.py index 8ce8725..63e4e84 100755 --- a/main.py +++ b/main.py @@ -32,7 +32,7 @@ print( print_markdown( "### Thanks for using this tool! [Feel free to contribute to this project on GitHub!](https://lewismenelaws.com) If you have any questions, feel free to reach out to me on Twitter or submit a GitHub issue. You can find solutions to many common problems in the [Documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/)" ) -print_step(f"You are using V{VERSION} of the bot") +print_step(f"You are using v{VERSION} of the bot") def main(POST_ID=None): diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 829a3a8..716a7fa 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -18,7 +18,7 @@ def get_subreddit_threads(POST_ID: str): print_substep("Logging into Reddit.") content = {} - if settings.config["reddit"]["creds"]["2fa"] == True: + if settings.config["reddit"]["creds"]["2fa"]: print("\nEnter your two-factor authentication code from your authenticator app.\n") code = input("> ") print() @@ -27,7 +27,7 @@ def get_subreddit_threads(POST_ID: str): else: passkey = settings.config["reddit"]["creds"]["password"] username = settings.config["reddit"]["creds"]["username"] - if username.casefold().startswith("u/"): + if str(username).casefold().startswith("u/"): username = username[2:] reddit = praw.Reddit( client_id=settings.config["reddit"]["creds"]["client_id"], @@ -55,7 +55,7 @@ def get_subreddit_threads(POST_ID: str): sub = settings.config["reddit"]["thread"]["subreddit"] print_substep(f"Using subreddit: r/{sub} from TOML config") subreddit_choice = sub - if subreddit_choice.casefold().startswith("r/"): # removes the r/ from the input + if str(subreddit_choice).casefold().startswith("r/"): # removes the r/ from the input subreddit_choice = subreddit_choice[2:] subreddit = reddit.subreddit( subreddit_choice @@ -65,11 +65,10 @@ def get_subreddit_threads(POST_ID: str): submission = reddit.submission(id=POST_ID) elif ( settings.config["reddit"]["thread"]["post_id"] - and len(settings.config["reddit"]["thread"]["post_id"].split("+")) == 1 + and len(str(settings.config["reddit"]["thread"]["post_id"]).split("+")) == 1 ): submission = reddit.submission(id=settings.config["reddit"]["thread"]["post_id"]) else: - threads = subreddit.hot(limit=25) submission = get_subreddit_undone(threads, subreddit) submission = check_done(submission) # double-checking @@ -104,6 +103,7 @@ def get_subreddit_threads(POST_ID: str): ): if ( top_level_comment.author is not None + and sanitize_text(top_level_comment.body) is not None ): # if errors occur with this change to if not. content["comments"].append( { diff --git a/utils/voice.py b/utils/voice.py index 4a77833..a0709fa 100644 --- a/utils/voice.py +++ b/utils/voice.py @@ -36,7 +36,7 @@ def sleep_until(time): # Convert datetime to unix timestamp and adjust for locality if isinstance(time, datetime): - # If we're on Python 3 and the user specified a timezone, convert to UTC and get tje timestamp. + # If we're on Python 3 and the user specified a timezone, convert to UTC and get the timestamp. if sys.version_info[0] >= 3 and time.tzinfo: end = time.astimezone(timezone.utc).timestamp() else: diff --git a/video_creation/background.py b/video_creation/background.py index 7ef4321..a6efc8b 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -64,7 +64,7 @@ def get_start_and_end_times(video_length: int, length_of_clip: int) -> Tuple[int def get_background_config(): """Fetch the background/s configuration""" try: - choice = str(settings.config["settings"]["background_choice"]).casefold() + choice = str(settings.config["settings"]["background"]["background_choice"]).casefold() except AttributeError: print_substep("No background selected. Picking random background'") choice = None diff --git a/video_creation/final_video.py b/video_creation/final_video.py index f1e1f96..bccbd0a 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -3,30 +3,22 @@ import multiprocessing import os import re from os.path import exists -from typing import Dict, Tuple, Any - +from typing import Tuple, Any import translators as ts -from moviepy.editor import ( - VideoFileClip, - AudioFileClip, - ImageClip, - concatenate_videoclips, - concatenate_audioclips, - CompositeAudioClip, - CompositeVideoClip, -) +from moviepy.editor import (VideoFileClip, AudioFileClip, ImageClip, concatenate_videoclips, concatenate_audioclips, + CompositeAudioClip, CompositeVideoClip, ) from moviepy.video.io.ffmpeg_tools import ffmpeg_merge_video_audio, ffmpeg_extract_subclip from rich.console import Console +import moviepy.editor as mpe from utils.cleanup import cleanup from utils.console import print_step, print_substep from utils.videos import save_data from utils import settings - console = Console() - +VOLUME_MULTIPLIER = settings.config["settings"]['background']["background_audio_volume"] W, H = 1080, 1920 @@ -48,9 +40,7 @@ def name_normalize(name: str) -> str: return name -def make_final_video( - number_of_clips: int, length: int, reddit_obj: dict, background_config: Tuple[str, str, str, Any] -): +def make_final_video(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: number_of_clips (int): Index to end at when going through the screenshots' @@ -63,11 +53,8 @@ def make_final_video( VideoFileClip.reH = lambda clip: clip.resize(width=H) opacity = settings.config["settings"]["opacity"] background_clip = ( - VideoFileClip("assets/temp/background.mp4") - .without_audio() - .resize(height=H) - .crop(x1=1166.6, y1=0, x2=2246.6, y2=1920) - ) + VideoFileClip("assets/temp/background.mp4").without_audio().resize(height=H).crop(x1=1166.6, y1=0, x2=2246.6, + y2=1920)) # Gather all audio clips audio_clips = [AudioFileClip(f"assets/temp/mp3/{i}.mp3") for i in range(number_of_clips)] @@ -80,21 +67,13 @@ def make_final_video( image_clips = [] # Gather all images new_opacity = 1 if opacity is None or float(opacity) >= 1 else float(opacity) - image_clips.insert( - 0, - ImageClip("assets/temp/png/title.png") - .set_duration(audio_clips[0].duration) - .resize(width=W - 100) - .set_opacity(new_opacity), - ) + image_clips.insert(0, ImageClip("assets/temp/png/title.png").set_duration(audio_clips[0].duration).resize( + width=W - 100).set_opacity(new_opacity), ) for i in range(0, number_of_clips): image_clips.append( - ImageClip(f"assets/temp/png/comment_{i}.png") - .set_duration(audio_clips[i + 1].duration) - .resize(width=W - 100) - .set_opacity(new_opacity) - ) + ImageClip(f"assets/temp/png/comment_{i}.png").set_duration(audio_clips[i + 1].duration).resize( + width=W - 100).set_opacity(new_opacity)) # if os.path.exists("assets/mp3/posttext.mp3"): # image_clips.insert( @@ -122,51 +101,32 @@ def make_final_video( print_substep("The results folder didn't exist so I made it") os.makedirs(f"./results/{subreddit}") - final.write_videofile( - "assets/temp/temp.mp4", - fps=30, - audio_codec="aac", - audio_bitrate="192k", - verbose=False, - threads=multiprocessing.cpu_count(), - ) - if settings.config["settings"]["background_audio"]: - print("[bold green] Merging background audio with video") - if not exists(f"assets/backgrounds/background.mp3"): - print_substep( - "Cannot find assets/backgrounds/background.mp3 audio file didn't so skipping." - ) - ffmpeg_extract_subclip( - "assets/temp/temp.mp4", - 0, - final.duration, - targetname=f"results/{subreddit}/{filename}", - ) - else: - ffmpeg_merge_video_audio( - "assets/temp/temp.mp4", - "assets/backgrounds/background.mp3", - "assets/temp/temp_audio.mp4", - ) - ffmpeg_extract_subclip( # check if this gets run - "assets/temp/temp_audio.mp4", - 0, - final.duration, - targetname=f"results/{subreddit}/{filename}", - ) + final.write_videofile("assets/temp/temp.mp4", fps=30, audio_codec="aac", audio_bitrate="192k", verbose=False, + threads=multiprocessing.cpu_count(), ) + if settings.config["settings"]['background']["background_audio"] and exists(f"assets/backgrounds/background.mp3"): + if not isinstance(VOLUME_MULTIPLIER, float): + print("No background audio volume set, using default of .3 set it in the config.toml file") + assert VOLUME_MULTIPLIER == float(0.3) + print('Merging background audio with video') + my_clip = mpe.VideoFileClip('assets/temp/temp.mp4') + audio_background = AudioFileClip("assets/backgrounds/background.mp3") + lowered_audio = audio_background.multiply_volume( + VOLUME_MULTIPLIER) # lower volume by background_audio_volume, use with fx + lowered_audio = lowered_audio.subclip(0, my_clip.duration) # trim the audio to the length of the video + lowered_audio.set_duration(my_clip.duration) # set the duration of the audio to the length of the video + final_audio = mpe.CompositeAudioClip([my_clip.audio, lowered_audio]) + final_clip = my_clip.set_audio(final_audio) + + final_clip.write_videofile("assets/temp/temp_audio.mp4", fps=30, audio_codec="aac", audio_bitrate="192k", + verbose=False, threads=multiprocessing.cpu_count()) + ffmpeg_extract_subclip( # check if this gets run + "assets/temp/temp_audio.mp4", 0, final.duration, targetname=f"results/{subreddit}/{filename}", ) else: - print("debug duck") - ffmpeg_extract_subclip( - "assets/temp/temp.mp4", - 0, - final.duration, - targetname=f"results/{subreddit}/{filename}", - ) + ffmpeg_extract_subclip("assets/temp/temp.mp4", 0, final.duration, + targetname=f"results/{subreddit}/{filename}", ) print_step("Removing temporary files 🗑") cleanups = cleanup() print_substep(f"Removed {cleanups} temporary files 🗑") print_substep("See result in the results folder!") - print_step( - f'Reddit title: {reddit_obj["thread_title"]} \n Background Credit: {background_config[2]}' - ) + print_step(f'Reddit title: {reddit_obj["thread_title"]} \n Background Credit: {background_config[2]}') diff --git a/video_creation/voices.py b/video_creation/voices.py index ffc0898..74894eb 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -34,7 +34,7 @@ def save_text_to_mp3(reddit_obj) -> Tuple[int, int]: """ voice = settings.config["settings"]["tts"]["choice"] - if voice.casefold() in map(lambda _: _.casefold(), TTSProviders): + if str(voice).casefold() in map(lambda _: _.casefold(), TTSProviders): text_to_mp3 = TTSEngine(get_case_insensitive_key_value(TTSProviders, voice), reddit_obj) else: while True: From aeafb53da3368a2b1975ed93fc7376074b9b45c0 Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 10 Jul 2022 11:44:40 -0400 Subject: [PATCH 03/21] background audio implementation p2. removed debug calls and testing rn style: removed useless comment imports --- TTS/streamlabs_polly.py | 2 -- main.py | 1 - video_creation/final_video.py | 27 +++++++++++++++++++-------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/TTS/streamlabs_polly.py b/TTS/streamlabs_polly.py index a5fda6a..bcfa175 100644 --- a/TTS/streamlabs_polly.py +++ b/TTS/streamlabs_polly.py @@ -48,8 +48,6 @@ class StreamlabsPolly: else: try: - print(body) - print(response.json()) voice_data = requests.get(response.json()["speak_url"]) with open(filepath, "wb") as f: f.write(voice_data.content) diff --git a/main.py b/main.py index 63e4e84..41ae8e1 100755 --- a/main.py +++ b/main.py @@ -7,7 +7,6 @@ from utils.cleanup import cleanup from utils.console import print_markdown, print_step from utils import settings -# from utils.checker import envUpdate from video_creation.background import ( download_background, chop_background_video, diff --git a/video_creation/final_video.py b/video_creation/final_video.py index bccbd0a..2e774c4 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -4,11 +4,15 @@ import os import re from os.path import exists from typing import Tuple, Any -import translators as ts - -from moviepy.editor import (VideoFileClip, AudioFileClip, ImageClip, concatenate_videoclips, concatenate_audioclips, - CompositeAudioClip, CompositeVideoClip, ) -from moviepy.video.io.ffmpeg_tools import ffmpeg_merge_video_audio, ffmpeg_extract_subclip +from moviepy import * +from moviepy.audio.AudioClip import concatenate_audioclips, CompositeAudioClip +from moviepy.audio.fx.audio_normalize import audio_normalize +from moviepy.audio.io.AudioFileClip import AudioFileClip +from moviepy.video.VideoClip import ImageClip +from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip +from moviepy.video.compositing.concatenate import concatenate_videoclips +from moviepy.video.io.VideoFileClip import VideoFileClip +from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip from rich.console import Console import moviepy.editor as mpe @@ -18,7 +22,10 @@ from utils.videos import save_data from utils import settings console = Console() -VOLUME_MULTIPLIER = settings.config["settings"]['background']["background_audio_volume"] +try: + VOLUME_MULTIPLIER = settings.config["settings"]['background']["background_audio_volume"] +except (TypeError, KeyError): + VOLUME_MULTIPLIER = 1 W, H = 1080, 1920 @@ -32,6 +39,7 @@ def name_normalize(name: str) -> str: lang = settings.config["reddit"]["thread"]["post_lang"] if lang: + import translators as ts print_substep("Translating filename...") translated_name = ts.google(name, to_language=lang) return translated_name @@ -110,8 +118,11 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict, backgr print('Merging background audio with video') my_clip = mpe.VideoFileClip('assets/temp/temp.mp4') audio_background = AudioFileClip("assets/backgrounds/background.mp3") - lowered_audio = audio_background.multiply_volume( - VOLUME_MULTIPLIER) # lower volume by background_audio_volume, use with fx + lowered_audio = audio_background.fl(lambda gf, t: VOLUME_MULTIPLIER * gf(t), + keep_duration=True) # to testr + #lowered_audio = audio_normalize(audio_background) + # lowered_audio = audio_background.multiply_volume( # todo get this to work + # VOLUME_MULTIPLIER) # lower volume by background_audio_volume, use with fx lowered_audio = lowered_audio.subclip(0, my_clip.duration) # trim the audio to the length of the video lowered_audio.set_duration(my_clip.duration) # set the duration of the audio to the length of the video final_audio = mpe.CompositeAudioClip([my_clip.audio, lowered_audio]) From 2b0d66f451cd31f377b685ebedca0929a84080d4 Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 10 Jul 2022 11:54:51 -0400 Subject: [PATCH 04/21] added backup contingency --- TTS/engine_wrapper.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/TTS/engine_wrapper.py b/TTS/engine_wrapper.py index 4f3cf1c..160c61a 100644 --- a/TTS/engine_wrapper.py +++ b/TTS/engine_wrapper.py @@ -114,9 +114,12 @@ class TTSEngine: # self.length += MP3(f"{self.path}/{filename}.mp3").info.length # except (MutagenError, HeaderNotFoundError): # self.length += sox.file_info.duration(f"{self.path}/{filename}.mp3") - clip = AudioFileClip(f"{self.path}/{filename}.mp3") - self.length += clip.duration - clip.close() + try: + clip = AudioFileClip(f"{self.path}/{filename}.mp3") + self.length += clip.duration + clip.close() + except: + self.length = 0 def process_text(text: str): From b027679c011b1b4c38d87e6acc5a953612408d41 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 11 Jul 2022 19:58:29 -0400 Subject: [PATCH 05/21] I give up on #11 can't implement --- .config.template.toml | 8 +++--- video_creation/background.py | 2 +- video_creation/final_video.py | 50 ++++++++++++----------------------- 3 files changed, 22 insertions(+), 38 deletions(-) diff --git a/.config.template.toml b/.config.template.toml index 16a6436..1060a09 100644 --- a/.config.template.toml +++ b/.config.template.toml @@ -32,10 +32,10 @@ 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" } -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.)" } -background_audio_volume = { optional = true, type = "float", default = 0.3, example = 0.1, explanation="Sets the volume of the background audio. only used if the background_audio is also set to true" } +#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.)" } +#background_audio_volume = { optional = true, type = "float", default = 0.3, example = 0.1, explanation="Sets the volume of the background audio. only used if the background_audio is also set to true" } [settings.tts] diff --git a/video_creation/background.py b/video_creation/background.py index a6efc8b..be0f46c 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -30,7 +30,7 @@ background_options = { "https://www.youtube.com/watch?v=2X9QGY__0II", "rocket_league.mp4", "Orbital Gameplay", - "top", + lambda t: ("center", 200 + t), ), "minecraft": ( # Minecraft parkour "https://www.youtube.com/watch?v=n_Dv4JMiwK8", diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 2e774c4..de53a7a 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -4,9 +4,7 @@ import os import re from os.path import exists from typing import Tuple, Any -from moviepy import * from moviepy.audio.AudioClip import concatenate_audioclips, CompositeAudioClip -from moviepy.audio.fx.audio_normalize import audio_normalize from moviepy.audio.io.AudioFileClip import AudioFileClip from moviepy.video.VideoClip import ImageClip from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip @@ -14,7 +12,6 @@ from moviepy.video.compositing.concatenate import concatenate_videoclips from moviepy.video.io.VideoFileClip import VideoFileClip from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip from rich.console import Console -import moviepy.editor as mpe from utils.cleanup import cleanup from utils.console import print_step, print_substep @@ -22,10 +19,6 @@ from utils.videos import save_data from utils import settings console = Console() -try: - VOLUME_MULTIPLIER = settings.config["settings"]['background']["background_audio_volume"] -except (TypeError, KeyError): - VOLUME_MULTIPLIER = 1 W, H = 1080, 1920 @@ -56,6 +49,12 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict, backgr reddit_obj (dict): The reddit object that contains the posts to read. background_config (Tuple[str, str, str, Any]): The background config to use. """ + #try: # if it isn't found (i.e you just updated and copied over config.toml) it will throw an error + # VOLUME_MULTIPLIER = settings.config["settings"]['background']["background_audio_volume"] + #except (TypeError, KeyError): + # print('No background audio volume found in config.toml. Using default value of 1.') + # VOLUME_MULTIPLIER = 1 + print_step("Creating the final video 🎥") VideoFileClip.reW = lambda clip: clip.resize(width=W) VideoFileClip.reH = lambda clip: clip.resize(width=H) @@ -103,38 +102,23 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict, backgr filename = f"{name_normalize(title)}.mp4" subreddit = settings.config["reddit"]["thread"]["subreddit"] - save_data(subreddit, filename, title, idx, background_config[2]) - if not exists(f"./results/{subreddit}"): print_substep("The results folder didn't exist so I made it") os.makedirs(f"./results/{subreddit}") + #if settings.config["settings"]['background']["background_audio"] and exists(f"assets/backgrounds/background.mp3"): + # audioclip = mpe.AudioFileClip(f"assets/backgrounds/background.mp3").set_duration(final.duration) + # audioclip = audioclip.fx( volumex, 0.2) + # final_audio = mpe.CompositeAudioClip([final.audio, audioclip]) + # # lowered_audio = audio_background.multiply_volume( # todo get this to work + # # VOLUME_MULTIPLIER) # lower volume by background_audio_volume, use with fx + # final.set_audio(final_audio) + final.write_videofile("assets/temp/temp.mp4", fps=30, audio_codec="aac", audio_bitrate="192k", verbose=False, threads=multiprocessing.cpu_count(), ) - if settings.config["settings"]['background']["background_audio"] and exists(f"assets/backgrounds/background.mp3"): - if not isinstance(VOLUME_MULTIPLIER, float): - print("No background audio volume set, using default of .3 set it in the config.toml file") - assert VOLUME_MULTIPLIER == float(0.3) - print('Merging background audio with video') - my_clip = mpe.VideoFileClip('assets/temp/temp.mp4') - audio_background = AudioFileClip("assets/backgrounds/background.mp3") - lowered_audio = audio_background.fl(lambda gf, t: VOLUME_MULTIPLIER * gf(t), - keep_duration=True) # to testr - #lowered_audio = audio_normalize(audio_background) - # lowered_audio = audio_background.multiply_volume( # todo get this to work - # VOLUME_MULTIPLIER) # lower volume by background_audio_volume, use with fx - lowered_audio = lowered_audio.subclip(0, my_clip.duration) # trim the audio to the length of the video - lowered_audio.set_duration(my_clip.duration) # set the duration of the audio to the length of the video - final_audio = mpe.CompositeAudioClip([my_clip.audio, lowered_audio]) - final_clip = my_clip.set_audio(final_audio) - - final_clip.write_videofile("assets/temp/temp_audio.mp4", fps=30, audio_codec="aac", audio_bitrate="192k", - verbose=False, threads=multiprocessing.cpu_count()) - ffmpeg_extract_subclip( # check if this gets run - "assets/temp/temp_audio.mp4", 0, final.duration, targetname=f"results/{subreddit}/{filename}", ) - else: - ffmpeg_extract_subclip("assets/temp/temp.mp4", 0, final.duration, - targetname=f"results/{subreddit}/{filename}", ) + ffmpeg_extract_subclip("assets/temp/temp.mp4", 0, final.duration, + targetname=f"results/{subreddit}/{filename}", ) + save_data(subreddit, filename, title, idx, background_config[2]) print_step("Removing temporary files 🗑") cleanups = cleanup() print_substep(f"Removed {cleanups} temporary files 🗑") From b2c9f30347b4ab2fc34c0eccd848e552347dd834 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 11 Jul 2022 20:27:18 -0400 Subject: [PATCH 06/21] moved index.html and added devs section --- index.html => GUI/index.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) rename index.html => GUI/index.html (96%) diff --git a/index.html b/GUI/index.html similarity index 96% rename from index.html rename to GUI/index.html index 46ae793..807c9e7 100644 --- a/index.html +++ b/GUI/index.html @@ -59,7 +59,7 @@ white-space: nowrap; -webkit-overflow-scrolling: touch; } - + #tooltip { background-color: #333; color: white; @@ -105,8 +105,8 @@

Back to top

-

Album Example Theme by © Bootstrap.

-

If your data is not refreshing, try to Hard reload(Ctrl + F5) and visit your local videos.json file.

+

Album Example Theme by © Bootstrap. Developers and Maintainers

+

If your data is not refreshing, try to hard reload(Ctrl + F5) and visit your local videos.json file.

@@ -134,7 +134,7 @@ } $(document).ready(function () { - $.getJSON("video_creation/data/videos.json", + $.getJSON("../video_creation/data/videos.json", function (data) { data.sort((b, a) => a['time'] - b['time']) var video = ''; @@ -163,7 +163,7 @@ video += ''; }); - + $('#videos').append(video); }); }); @@ -278,4 +278,4 @@ } - \ No newline at end of file + From 482a666941ed91f9f33ab7510e271241d1322805 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 11 Jul 2022 20:28:32 -0400 Subject: [PATCH 07/21] adds a min comment's var fixes #924 chore: updated version number --- .config.template.toml | 2 +- main.py | 2 +- utils/subreddit.py | 3 +++ video_creation/final_video.py | 1 - video_creation/voices.py | 1 - 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.config.template.toml b/.config.template.toml index 1060a09..32c0f7a 100644 --- a/.config.template.toml +++ b/.config.template.toml @@ -16,7 +16,7 @@ subreddit = { optional = false, regex = "[_0-9a-zA-Z]+$", nmin = 3, nmax = 21, e post_id = { optional = true, default = "", regex = "^((?!://|://)[+a-zA-Z])*$", explanation = "Used if you want to use a specific post.", example = "urdtfx" } max_comment_length = { default = 500, optional = false, nmin = 10, nmax = 10000, type = "int", explanation = "max number of characters a comment can have. default is 500", example = 500, oob_error = "the max comment length should be between 10 and 10000" } post_lang = { default = "", optional = true, explanation = "The language you would like to translate to.", example = "es-cr" } - +min_comments = { default = 20, optional = false, nmin = 15, nmax = 999999, type = "int", explanation = "The minimum number of comments a post should have to be included. default is 20", example = 29, oob_error = "the minimum number of comments should be between 15 and 999999" } [settings] allow_nsfw = { optional = false, type = "bool", default = false, example = false, options = [true, false, diff --git a/main.py b/main.py index 41ae8e1..0dbd2c9 100755 --- a/main.py +++ b/main.py @@ -16,7 +16,7 @@ from video_creation.final_video import make_final_video from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts from video_creation.voices import save_text_to_mp3 -VERSION = "2.2.9" +VERSION = "2.2.10" print( """ ██████╗ ███████╗██████╗ ██████╗ ██╗████████╗ ██╗ ██╗██╗██████╗ ███████╗ ██████╗ ███╗ ███╗ █████╗ ██╗ ██╗███████╗██████╗ diff --git a/utils/subreddit.py b/utils/subreddit.py index 48dceba..6f9ed49 100644 --- a/utils/subreddit.py +++ b/utils/subreddit.py @@ -34,6 +34,9 @@ def get_subreddit_undone(submissions: list, subreddit): if submission.stickied: print_substep("This post was pinned by moderators. Skipping...") continue + if submission.num_comments < int(settings.config["reddit"]['thread']["min_comments"]): + print_substep(f'This post has under the specified minimum of comments ({settings.config["reddit"]["thread"]["min_comments"]}). Skipping...') + continue return submission print("all submissions have been done going by top submission order") return get_subreddit_undone( diff --git a/video_creation/final_video.py b/video_creation/final_video.py index de53a7a..264c5af 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -54,7 +54,6 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict, backgr #except (TypeError, KeyError): # print('No background audio volume found in config.toml. Using default value of 1.') # VOLUME_MULTIPLIER = 1 - print_step("Creating the final video 🎥") VideoFileClip.reW = lambda clip: clip.resize(width=W) VideoFileClip.reH = lambda clip: clip.resize(width=H) diff --git a/video_creation/voices.py b/video_creation/voices.py index 74894eb..ac33dd7 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -45,7 +45,6 @@ def save_text_to_mp3(reddit_obj) -> Tuple[int, int]: break print("Unknown Choice") text_to_mp3 = TTSEngine(get_case_insensitive_key_value(TTSProviders, choice), reddit_obj) - return text_to_mp3.run() From 36e07c4c37bc7b368640585a60d3866b0b2d8f77 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 11 Jul 2022 20:30:37 -0400 Subject: [PATCH 08/21] see https://github.com/elebumm/RedditVideoMakerBot/issues/924#issuecomment-1181169525 fixes #11 --- utils/subreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/subreddit.py b/utils/subreddit.py index 6f9ed49..cdaf4a6 100644 --- a/utils/subreddit.py +++ b/utils/subreddit.py @@ -34,7 +34,7 @@ def get_subreddit_undone(submissions: list, subreddit): if submission.stickied: print_substep("This post was pinned by moderators. Skipping...") continue - if submission.num_comments < int(settings.config["reddit"]['thread']["min_comments"]): + if submission.num_comments <= int(settings.config["reddit"]['thread']["min_comments"]): print_substep(f'This post has under the specified minimum of comments ({settings.config["reddit"]["thread"]["min_comments"]}). Skipping...') continue return submission From 882bf64e1ca36e7f7a9f964883c309409678fbec Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 11 Jul 2022 20:30:53 -0400 Subject: [PATCH 09/21] typo --- utils/subreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/subreddit.py b/utils/subreddit.py index cdaf4a6..f80f695 100644 --- a/utils/subreddit.py +++ b/utils/subreddit.py @@ -41,7 +41,7 @@ def get_subreddit_undone(submissions: list, subreddit): print("all submissions have been done going by top submission order") return get_subreddit_undone( subreddit.top(time_filter="hour"), subreddit - ) # all of the videos in hot have already been done + ) # all the videos in hot have already been done def already_done(done_videos: list, submission) -> bool: From 1872ef36c194fc74bcdc6af18179985b80d9b2b5 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 11 Jul 2022 20:31:20 -0400 Subject: [PATCH 10/21] reformatted --- utils/subreddit.py | 6 ++-- video_creation/final_video.py | 56 +++++++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/utils/subreddit.py b/utils/subreddit.py index f80f695..4eb0108 100644 --- a/utils/subreddit.py +++ b/utils/subreddit.py @@ -34,8 +34,10 @@ def get_subreddit_undone(submissions: list, subreddit): if submission.stickied: print_substep("This post was pinned by moderators. Skipping...") continue - if submission.num_comments <= int(settings.config["reddit"]['thread']["min_comments"]): - print_substep(f'This post has under the specified minimum of comments ({settings.config["reddit"]["thread"]["min_comments"]}). Skipping...') + if submission.num_comments <= int(settings.config["reddit"]["thread"]["min_comments"]): + print_substep( + f'This post has under the specified minimum of comments ({settings.config["reddit"]["thread"]["min_comments"]}). Skipping...' + ) continue return submission print("all submissions have been done going by top submission order") diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 264c5af..28956e6 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -33,6 +33,7 @@ def name_normalize(name: str) -> str: lang = settings.config["reddit"]["thread"]["post_lang"] if lang: import translators as ts + print_substep("Translating filename...") translated_name = ts.google(name, to_language=lang) return translated_name @@ -41,7 +42,9 @@ def name_normalize(name: str) -> str: return name -def make_final_video(number_of_clips: int, length: int, reddit_obj: dict, background_config: Tuple[str, str, str, Any]): +def make_final_video( + 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: number_of_clips (int): Index to end at when going through the screenshots' @@ -49,9 +52,9 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict, backgr reddit_obj (dict): The reddit object that contains the posts to read. background_config (Tuple[str, str, str, Any]): The background config to use. """ - #try: # if it isn't found (i.e you just updated and copied over config.toml) it will throw an error + # try: # if it isn't found (i.e you just updated and copied over config.toml) it will throw an error # VOLUME_MULTIPLIER = settings.config["settings"]['background']["background_audio_volume"] - #except (TypeError, KeyError): + # except (TypeError, KeyError): # print('No background audio volume found in config.toml. Using default value of 1.') # VOLUME_MULTIPLIER = 1 print_step("Creating the final video 🎥") @@ -59,8 +62,11 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict, backgr VideoFileClip.reH = lambda clip: clip.resize(width=H) opacity = settings.config["settings"]["opacity"] background_clip = ( - VideoFileClip("assets/temp/background.mp4").without_audio().resize(height=H).crop(x1=1166.6, y1=0, x2=2246.6, - y2=1920)) + VideoFileClip("assets/temp/background.mp4") + .without_audio() + .resize(height=H) + .crop(x1=1166.6, y1=0, x2=2246.6, y2=1920) + ) # Gather all audio clips audio_clips = [AudioFileClip(f"assets/temp/mp3/{i}.mp3") for i in range(number_of_clips)] @@ -73,13 +79,21 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict, backgr image_clips = [] # Gather all images new_opacity = 1 if opacity is None or float(opacity) >= 1 else float(opacity) - image_clips.insert(0, ImageClip("assets/temp/png/title.png").set_duration(audio_clips[0].duration).resize( - width=W - 100).set_opacity(new_opacity), ) + image_clips.insert( + 0, + ImageClip("assets/temp/png/title.png") + .set_duration(audio_clips[0].duration) + .resize(width=W - 100) + .set_opacity(new_opacity), + ) for i in range(0, number_of_clips): image_clips.append( - ImageClip(f"assets/temp/png/comment_{i}.png").set_duration(audio_clips[i + 1].duration).resize( - width=W - 100).set_opacity(new_opacity)) + ImageClip(f"assets/temp/png/comment_{i}.png") + .set_duration(audio_clips[i + 1].duration) + .resize(width=W - 100) + .set_opacity(new_opacity) + ) # if os.path.exists("assets/mp3/posttext.mp3"): # image_clips.insert( @@ -105,7 +119,7 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict, backgr print_substep("The results folder didn't exist so I made it") os.makedirs(f"./results/{subreddit}") - #if settings.config["settings"]['background']["background_audio"] and exists(f"assets/backgrounds/background.mp3"): + # if settings.config["settings"]['background']["background_audio"] and exists(f"assets/backgrounds/background.mp3"): # audioclip = mpe.AudioFileClip(f"assets/backgrounds/background.mp3").set_duration(final.duration) # audioclip = audioclip.fx( volumex, 0.2) # final_audio = mpe.CompositeAudioClip([final.audio, audioclip]) @@ -113,14 +127,26 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict, backgr # # VOLUME_MULTIPLIER) # lower volume by background_audio_volume, use with fx # final.set_audio(final_audio) - final.write_videofile("assets/temp/temp.mp4", fps=30, audio_codec="aac", audio_bitrate="192k", verbose=False, - threads=multiprocessing.cpu_count(), ) - ffmpeg_extract_subclip("assets/temp/temp.mp4", 0, final.duration, - targetname=f"results/{subreddit}/{filename}", ) + final.write_videofile( + "assets/temp/temp.mp4", + fps=30, + audio_codec="aac", + audio_bitrate="192k", + verbose=False, + threads=multiprocessing.cpu_count(), + ) + ffmpeg_extract_subclip( + "assets/temp/temp.mp4", + 0, + final.duration, + targetname=f"results/{subreddit}/{filename}", + ) save_data(subreddit, filename, title, idx, background_config[2]) print_step("Removing temporary files 🗑") cleanups = cleanup() print_substep(f"Removed {cleanups} temporary files 🗑") print_substep("See result in the results folder!") - print_step(f'Reddit title: {reddit_obj["thread_title"]} \n Background Credit: {background_config[2]}') + print_step( + f'Reddit title: {reddit_obj["thread_title"]} \n Background Credit: {background_config[2]}' + ) From a7c54f48e864bd05f9b69ee5f8058b1de19ed17d Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 11 Jul 2022 20:42:37 -0400 Subject: [PATCH 11/21] Improved AWS Polly eh improved handling for errors like like #929 --- TTS/aws_polly.py | 64 +++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/TTS/aws_polly.py b/TTS/aws_polly.py index 13eaea1..e1d5318 100644 --- a/TTS/aws_polly.py +++ b/TTS/aws_polly.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 from boto3 import Session -from botocore.exceptions import BotoCoreError, ClientError +from botocore.exceptions import BotoCoreError, ClientError, ProfileNotFound import sys from utils import settings import random @@ -30,36 +30,44 @@ class AWSPolly: self.voices = voices def run(self, text, filepath, random_voice: bool = False): - session = Session(profile_name="polly") - polly = session.client("polly") - if random_voice: - voice = self.randomvoice() - else: - if not settings.config["settings"]["tts"]["aws_polly_voice"]: - return ValueError( - f"Please set the TOML variable AWS_VOICE to a valid voice. options are: {voices}" - ) - voice = str(settings.config["settings"]["tts"]["aws_polly_voice"]).capitalize() try: - # Request speech synthesis - response = polly.synthesize_speech( - Text=text, OutputFormat="mp3", VoiceId=voice, Engine="neural" - ) - except (BotoCoreError, ClientError) as error: - # The service returned an error, exit gracefully - print(error) - sys.exit(-1) + session = Session(profile_name="polly") + polly = session.client("polly") + if random_voice: + voice = self.randomvoice() + else: + if not settings.config["settings"]["tts"]["aws_polly_voice"]: + return ValueError( + f"Please set the TOML variable AWS_VOICE to a valid voice. options are: {voices}" + ) + voice = str(settings.config["settings"]["tts"]["aws_polly_voice"]).capitalize() + try: + # Request speech synthesis + response = polly.synthesize_speech( + Text=text, OutputFormat="mp3", VoiceId=voice, Engine="neural" + ) + except (BotoCoreError, ClientError) as error: + # The service returned an error, exit gracefully + print(error) + sys.exit(-1) - # Access the audio stream from the response - if "AudioStream" in response: - file = open(filepath, "wb") - file.write(response["AudioStream"].read()) - file.close() - # print_substep(f"Saved Text {idx} to MP3 files successfully.", style="bold green") + # Access the audio stream from the response + if "AudioStream" in response: + file = open(filepath, "wb") + file.write(response["AudioStream"].read()) + file.close() + # print_substep(f"Saved Text {idx} to MP3 files successfully.", style="bold green") - else: - # The response didn't contain audio data, exit gracefully - print("Could not stream audio") + else: + # The response didn't contain audio data, exit gracefully + print("Could not stream audio") + sys.exit(-1) + except ProfileNotFound: + print("You need to install the AWS CLI and configure your profile") + print(""" + Linux: https://docs.aws.amazon.com/polly/latest/dg/setup-aws-cli.html + Windows: https://docs.aws.amazon.com/polly/latest/dg/install-voice-plugin2.html + """) sys.exit(-1) def randomvoice(self): From 49cecb0811ff7b8a7b962ddf6f9ae3e450a02a3d Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 11 Jul 2022 20:56:24 -0400 Subject: [PATCH 12/21] removed hard cap on subreddit length --- .config.template.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.config.template.toml b/.config.template.toml index 32c0f7a..18f1b00 100644 --- a/.config.template.toml +++ b/.config.template.toml @@ -12,11 +12,11 @@ password = { optional = false, nmin = 8, explanation = "the password of your red random = { optional = true, options = [true, false, ], default = false, type = "bool", explanation = "If set to no, it will ask you a thread link to extract the thread, if yes it will randomize it. Default: 'False'", example = "True" } -subreddit = { optional = false, regex = "[_0-9a-zA-Z]+$", nmin = 3, nmax = 21, explanation = "what subreddit to pull posts from, the name of the sub, not the URL", example = "AskReddit", oob_error = "A subreddit name HAS to be between 3 and 20 characters" } +subreddit = { optional = false, regex = "[_0-9a-zA-Z]+$", nmin = 3, explanation = "what subreddit to pull posts from, the name of the sub, not the URL", example = "AskReddit", oob_error = "A subreddit name HAS to be between 3 and 20 characters" } post_id = { optional = true, default = "", regex = "^((?!://|://)[+a-zA-Z])*$", explanation = "Used if you want to use a specific post.", example = "urdtfx" } max_comment_length = { default = 500, optional = false, nmin = 10, nmax = 10000, type = "int", explanation = "max number of characters a comment can have. default is 500", example = 500, oob_error = "the max comment length should be between 10 and 10000" } post_lang = { default = "", optional = true, explanation = "The language you would like to translate to.", example = "es-cr" } -min_comments = { default = 20, optional = false, nmin = 15, nmax = 999999, type = "int", explanation = "The minimum number of comments a post should have to be included. default is 20", example = 29, oob_error = "the minimum number of comments should be between 15 and 999999" } +min_comments = { default = 20, optional = false, nmin = 15, type = "int", explanation = "The minimum number of comments a post should have to be included. default is 20", example = 29, oob_error = "the minimum number of comments should be between 15 and 999999" } [settings] allow_nsfw = { optional = false, type = "bool", default = false, example = false, options = [true, false, From 2f5d394bba68a234610d4cba8512024ec787004d Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 11 Jul 2022 21:01:29 -0400 Subject: [PATCH 13/21] chore: updated version number --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 0dbd2c9..b4737e0 100755 --- a/main.py +++ b/main.py @@ -16,7 +16,7 @@ from video_creation.final_video import make_final_video from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts from video_creation.voices import save_text_to_mp3 -VERSION = "2.2.10" +VERSION = "2.3" print( """ ██████╗ ███████╗██████╗ ██████╗ ██╗████████╗ ██╗ ██╗██╗██████╗ ███████╗ ██████╗ ███╗ ███╗ █████╗ ██╗ ██╗███████╗██████╗ From 6528fdc668711f32f6c207527f9972512f378d6f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Jul 2022 11:10:30 +0000 Subject: [PATCH 14/21] Bump rich from 12.4.4 to 12.5.1 Bumps [rich](https://github.com/willmcgugan/rich) from 12.4.4 to 12.5.1. - [Release notes](https://github.com/willmcgugan/rich/releases) - [Changelog](https://github.com/Textualize/rich/blob/master/CHANGELOG.md) - [Commits](https://github.com/willmcgugan/rich/compare/v12.4.4...v12.5.1) --- updated-dependencies: - dependency-name: rich dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 40c7632..2b7d9eb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,5 +8,5 @@ praw==7.6.0 python-dotenv==0.20.0 pytube==12.1.0 requests==2.28.1 -rich==12.4.4 +rich==12.5.1 translators==5.3.1 From c5c64a5e4b6240b61fdbde21609c25ec8694eeed Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Tue, 12 Jul 2022 16:23:56 +0100 Subject: [PATCH 15/21] fix: dont use blank text splits --- TTS/engine_wrapper.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/TTS/engine_wrapper.py b/TTS/engine_wrapper.py index 160c61a..c5ed714 100644 --- a/TTS/engine_wrapper.py +++ b/TTS/engine_wrapper.py @@ -85,15 +85,16 @@ class TTSEngine: r" *(((.|\n){0," + str(self.tts_module.max_chars) + "})(\.|.$))", text ) ] - + offset = 0 for idy, text_cut in enumerate(split_text): # print(f"{idx}-{idy}: {text_cut}\n") - if text_cut == "": - print("Empty text cut: tell the devs about this") + if not text_cut or text_cut.isspace(): + offset += 1 continue - self.call_tts(f"{idx}-{idy}.part", text_cut) - split_files.append(AudioFileClip(f"{self.path}/{idx}-{idy}.part.mp3")) + self.call_tts(f"{idx}-{idy - offset}.part", text_cut) + split_files.append(AudioFileClip(f"{self.path}/{idx}-{idy - offset}.part.mp3")) + CompositeAudioClip([concatenate_audioclips(split_files)]).write_audiofile( f"{self.path}/{idx}.mp3", fps=44100, verbose=False, logger=None ) From 89ab71270ab45cdacafc32e95f64de154c8cf8a8 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Tue, 12 Jul 2022 16:25:29 +0100 Subject: [PATCH 16/21] style: format --- video_creation/final_video.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 28956e6..8524051 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -43,7 +43,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: From 1d3410646d674334b2169e0e59b1a731c00f1faf Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 12 Jul 2022 11:40:15 -0400 Subject: [PATCH 17/21] readme: re-added Freebie --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 028dcd4..8a9e205 100644 --- a/README.md +++ b/README.md @@ -90,3 +90,5 @@ CallumIO (c.#6837) - https://github.com/CallumIO Verq (Verq#2338) - https://github.com/CordlessCoder LukaHietala (Pix.#0001) - https://github.com/LukaHietala + +Freebiell (Freebie#6429) - https://github.com/FreebieII From 3068cead0c0e4479b93ce3041cc698c92cba96d3 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Tue, 12 Jul 2022 16:46:22 +0100 Subject: [PATCH 18/21] fix: raise ValueErrors rather than return --- TTS/aws_polly.py | 8 +++++--- TTS/streamlabs_polly.py | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/TTS/aws_polly.py b/TTS/aws_polly.py index e1d5318..efd762b 100644 --- a/TTS/aws_polly.py +++ b/TTS/aws_polly.py @@ -37,7 +37,7 @@ class AWSPolly: voice = self.randomvoice() else: if not settings.config["settings"]["tts"]["aws_polly_voice"]: - return ValueError( + raise ValueError( f"Please set the TOML variable AWS_VOICE to a valid voice. options are: {voices}" ) voice = str(settings.config["settings"]["tts"]["aws_polly_voice"]).capitalize() @@ -64,10 +64,12 @@ class AWSPolly: sys.exit(-1) except ProfileNotFound: print("You need to install the AWS CLI and configure your profile") - print(""" + print( + """ Linux: https://docs.aws.amazon.com/polly/latest/dg/setup-aws-cli.html Windows: https://docs.aws.amazon.com/polly/latest/dg/install-voice-plugin2.html - """) + """ + ) sys.exit(-1) def randomvoice(self): diff --git a/TTS/streamlabs_polly.py b/TTS/streamlabs_polly.py index bcfa175..8078af5 100644 --- a/TTS/streamlabs_polly.py +++ b/TTS/streamlabs_polly.py @@ -37,7 +37,7 @@ class StreamlabsPolly: voice = self.randomvoice() else: if not settings.config["settings"]["tts"]["streamlabs_polly_voice"]: - return ValueError( + raise ValueError( f"Please set the config variable STREAMLABS_VOICE to a valid voice. options are: {voices}" ) voice = str(settings.config["settings"]["tts"]["streamlabs_polly_voice"]).capitalize() @@ -51,7 +51,7 @@ class StreamlabsPolly: voice_data = requests.get(response.json()["speak_url"]) with open(filepath, "wb") as f: f.write(voice_data.content) - except (KeyError, JSONDecodeError) as e: + except (KeyError, JSONDecodeError): try: if response.json()["error"] == "No text specified!": raise ValueError("Please specify a text to convert to speech.") From 359e9d8c218d547a22e83fe3b23a1654954a23ad Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 12 Jul 2022 11:50:45 -0400 Subject: [PATCH 19/21] fixed STREAMLABS_POLLY_VOICE typo see https://github.com/elebumm/RedditVideoMakerBot/pull/880/files/1d3410646d674334b2169e0e59b1a731c00f1faf..3068cead0c0e4479b93ce3041cc698c92cba96d3#r915594390 --- TTS/streamlabs_polly.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TTS/streamlabs_polly.py b/TTS/streamlabs_polly.py index 8078af5..75c4f49 100644 --- a/TTS/streamlabs_polly.py +++ b/TTS/streamlabs_polly.py @@ -38,7 +38,7 @@ class StreamlabsPolly: else: if not settings.config["settings"]["tts"]["streamlabs_polly_voice"]: raise ValueError( - f"Please set the config variable STREAMLABS_VOICE to a valid voice. options are: {voices}" + f"Please set the config variable STREAMLABS_POLLY_VOICE to a valid voice. options are: {voices}" ) voice = str(settings.config["settings"]["tts"]["streamlabs_polly_voice"]).capitalize() body = {"voice": voice, "text": text, "service": "polly"} From 2cf00a1da8813fa42b94261e1196edb331bf3ca4 Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 12 Jul 2022 11:52:03 -0400 Subject: [PATCH 20/21] chore: updated version and added a branch tag --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index b4737e0..9afc15c 100755 --- a/main.py +++ b/main.py @@ -16,7 +16,9 @@ from video_creation.final_video import make_final_video from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts from video_creation.voices import save_text_to_mp3 -VERSION = "2.3" +__VERSION__ = "2.3" +__BRANCH__ = "master" + print( """ ██████╗ ███████╗██████╗ ██████╗ ██╗████████╗ ██╗ ██╗██╗██████╗ ███████╗ ██████╗ ███╗ ███╗ █████╗ ██╗ ██╗███████╗██████╗ From 900816535bd5e4b0291baf5f09533e559ef652db Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 12 Jul 2022 11:52:52 -0400 Subject: [PATCH 21/21] oh GOD i almost did a 2.2 again. --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 9afc15c..10ab3c1 100755 --- a/main.py +++ b/main.py @@ -33,7 +33,7 @@ print( print_markdown( "### Thanks for using this tool! [Feel free to contribute to this project on GitHub!](https://lewismenelaws.com) If you have any questions, feel free to reach out to me on Twitter or submit a GitHub issue. You can find solutions to many common problems in the [Documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/)" ) -print_step(f"You are using v{VERSION} of the bot") +print_step(f"You are using v{__VERSION__} of the bot") def main(POST_ID=None):