From 4631d26391472c804f5e6088877602aceb60af2e Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Sun, 5 Jun 2022 15:28:04 +0200 Subject: [PATCH 1/3] tts links --- video_creation/voices.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/video_creation/voices.py b/video_creation/voices.py index e8d8e43..55825eb 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -3,6 +3,7 @@ from pathlib import Path from mutagen.mp3 import MP3 from utils.console import print_step, print_substep from rich.progress import track +import re def save_text_to_mp3(reddit_obj): @@ -25,7 +26,9 @@ def save_text_to_mp3(reddit_obj): # ! Stop creating mp3 files if the length is greater than 50 seconds. This can be longer, but this is just a good starting point if length > 50: break - tts = gTTS(text=comment["comment_body"], lang="en", slow=False) + comment=comment["comment_body"] + text=re.sub('((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z]){2,6}([a-zA-Z0-9\.\&\/\?\:@\-_=#])*', '', comment) + tts = gTTS(text, lang="en", slow=False) tts.save(f"assets/mp3/{idx}.mp3") length += MP3(f"assets/mp3/{idx}.mp3").info.length From 2ec2a496d2b804be0109d6aa2b2b8e59f33e83fb Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Sun, 5 Jun 2022 16:25:36 +0200 Subject: [PATCH 2/3] UI changes this mostly adds a nice banner to the terminal when main.py is run --- main.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 1b66e8c..e46bcba 100644 --- a/main.py +++ b/main.py @@ -9,11 +9,32 @@ import os, time, shutil REQUIRED_VALUES = ["REDDIT_CLIENT_ID","REDDIT_CLIENT_SECRET","REDDIT_USERNAME","REDDIT_PASSWORD", "OPACITY"] +banner = ''' + +██████╗░███████╗██████╗░██████╗░██╗████████╗  ██╗░░░██╗██╗██████╗░███████╗░█████╗░ +██╔══██╗██╔════╝██╔══██╗██╔══██╗██║╚══██╔══╝  ██║░░░██║██║██╔══██╗██╔════╝██╔══██╗ +██████╔╝█████╗░░██║░░██║██║░░██║██║░░░██║░░░  ╚██╗░██╔╝██║██║░░██║█████╗░░██║░░██║ +██╔══██╗██╔══╝░░██║░░██║██║░░██║██║░░░██║░░░  ░╚████╔╝░██║██║░░██║██╔══╝░░██║░░██║ +██║░░██║███████╗██████╔╝██████╔╝██║░░░██║░░░  ░░╚██╔╝░░██║██████╔╝███████╗╚█████╔╝ +╚═╝░░╚═╝╚══════╝╚═════╝░╚═════╝░╚═╝░░░╚═╝░░░  ░░░╚═╝░░░╚═╝╚═════╝░╚══════╝░╚════╝░ + +███╗░░░███╗░█████╗░██╗░░██╗███████╗██████╗░ +████╗░████║██╔══██╗██║░██╔╝██╔════╝██╔══██╗ +██╔████╔██║███████║█████═╝░█████╗░░██████╔╝ +██║╚██╔╝██║██╔══██║██╔═██╗░██╔══╝░░██╔══██╗ +██║░╚═╝░██║██║░░██║██║░╚██╗███████╗██║░░██║ +╚═╝░░░░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚══════╝╚═╝░░╚═╝ + +''' +print(banner) + +time.sleep(1.5) + 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." ) -time.sleep(3) +time.sleep(1) load_dotenv() From e41ad649ee07ea6e80f446557602fa07dcd6af8d Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Mon, 6 Jun 2022 19:16:57 +0200 Subject: [PATCH 3/3] Update main.py --- main.py | 72 ++++++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/main.py b/main.py index e46bcba..3c236e4 100644 --- a/main.py +++ b/main.py @@ -1,64 +1,58 @@ +# Main from utils.console import print_markdown +from utils.console import print_step +from utils.console import print_substep +from rich.console import Console +import time from reddit.subreddit import get_subreddit_threads from video_creation.background import download_background, chop_background_video from video_creation.voices import save_text_to_mp3 from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts from video_creation.final_video import make_final_video +from utils.loader import Loader from dotenv import load_dotenv -import os, time, shutil - -REQUIRED_VALUES = ["REDDIT_CLIENT_ID","REDDIT_CLIENT_SECRET","REDDIT_USERNAME","REDDIT_PASSWORD", "OPACITY"] -banner = ''' - -██████╗░███████╗██████╗░██████╗░██╗████████╗  ██╗░░░██╗██╗██████╗░███████╗░█████╗░ -██╔══██╗██╔════╝██╔══██╗██╔══██╗██║╚══██╔══╝  ██║░░░██║██║██╔══██╗██╔════╝██╔══██╗ -██████╔╝█████╗░░██║░░██║██║░░██║██║░░░██║░░░  ╚██╗░██╔╝██║██║░░██║█████╗░░██║░░██║ -██╔══██╗██╔══╝░░██║░░██║██║░░██║██║░░░██║░░░  ░╚████╔╝░██║██║░░██║██╔══╝░░██║░░██║ -██║░░██║███████╗██████╔╝██████╔╝██║░░░██║░░░  ░░╚██╔╝░░██║██████╔╝███████╗╚█████╔╝ -╚═╝░░╚═╝╚══════╝╚═════╝░╚═════╝░╚═╝░░░╚═╝░░░  ░░░╚═╝░░░╚═╝╚═════╝░╚══════╝░╚════╝░ +console = Console() +from dotenv import load_dotenv +import os, time, shutil -███╗░░░███╗░█████╗░██╗░░██╗███████╗██████╗░ -████╗░████║██╔══██╗██║░██╔╝██╔════╝██╔══██╗ -██╔████╔██║███████║█████═╝░█████╗░░██████╔╝ -██║╚██╔╝██║██╔══██║██╔═██╗░██╔══╝░░██╔══██╗ -██║░╚═╝░██║██║░░██║██║░╚██╗███████╗██║░░██║ -╚═╝░░░░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚══════╝╚═╝░░╚═╝ - -''' -print(banner) +configured = True +REQUIRED_VALUES = [ + "REDDIT_CLIENT_ID", + "REDDIT_CLIENT_SECRET", + "REDDIT_USERNAME", + "REDDIT_PASSWORD", + "OPACITY", +] -time.sleep(1.5) 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." ) -time.sleep(1) +""" +Load .env file if exists. If it doesnt exist, print a warning and launch the setup wizard. +If there is a .env file, check if the required variables are set. If not, print a warning and launch the setup wizard. +""" + +client_id = os.getenv("REDDIT_CLIENT_ID") +client_secret = os.getenv("REDDIT_CLIENT_SECRET") +username = os.getenv("REDDIT_USERNAME") +password = os.getenv("REDDIT_PASSWORD") +reddit2fa = os.getenv("REDDIT_2FA") load_dotenv() -configured = True +console.log("[bold green]Checking environment variables...") +time.sleep(1) + if not os.path.exists(".env"): - shutil.copy(".env.template", ".env") configured = False + console.log("[red] Your .env file is invalid, or was never created. Standby.") for val in REQUIRED_VALUES: + #print(os.getenv(val)) if val not in os.environ or not os.getenv(val): - print(f"Please set the variable \"{val}\" in your .env file.") + console.log(f'[bold red]Missing Variable: "{val}"') configured = False - -try: - float(os.getenv("OPACITY")) -except: - print(f"Please ensure that OPACITY is set between 0 and 1 in your .env file") - configured = False - -if configured: - reddit_object = get_subreddit_threads() - length, number_of_comments = save_text_to_mp3(reddit_object) - download_screenshots_of_reddit_posts(reddit_object, number_of_comments, os.getenv("THEME", "light")) - download_background() - chop_background_video(length) - final_video = make_final_video(number_of_comments)