From f55dda166a17df9a1128cff3efd4836457c50c13 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Sun, 5 Jun 2022 15:17:57 +0200 Subject: [PATCH 1/7] tts will no longer read aloud link There is an often issue where when commentators link to another site the tts will read out the link in its entirety. This PR uses Regex to filter that stuff out. --- 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 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 2/7] 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 3/7] 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 4/7] 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) From 76e52af6b2fca20d852edfc743aa0e185cf79261 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Mon, 6 Jun 2022 23:48:29 +0200 Subject: [PATCH 5/7] fixed errors --- main.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/main.py b/main.py index 27e46a8..31b14a1 100644 --- a/main.py +++ b/main.py @@ -30,6 +30,9 @@ 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." ) +""" +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") @@ -53,4 +56,43 @@ for val in REQUIRED_VALUES: if val not in os.environ or not os.getenv(val): console.log(f'[bold red]Missing Variable: "{val}"') configured = False + console.log( + "[red]Looks like you need to set your Reddit credentials in the .env file. Please follow the instructions in the README.md file to set them up." + ) + time.sleep(0.5) + console.log( + "[red]We can also launch the easy setup wizard. type yes to launch it, or no to quit the program." + ) + setup_ask = input("Launch setup wizard? > ") + if setup_ask == "yes": + console.log("[bold green]Here goes nothing! Launching setup wizard...") + time.sleep(0.5) + os.system("python3 setup.py") + + elif setup_ask == "no": + console.print("[red]Exiting...") + time.sleep(0.5) + exit() + else: + console.print("[red]I don't understand that. Exiting...") + time.sleep(0.5) + exit() +try: + float(os.getenv("OPACITY")) +except: + console.log( + f"[red]Please ensure that OPACITY is set between 0 and 1 in your .env file" + ) + configured = False + exit() +console.log("[bold green]Enviroment Variables are set! Continuing...") +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) From 2f61580af7907ccff11cffc0ed7c548f00266cbe Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Mon, 6 Jun 2022 23:49:27 +0200 Subject: [PATCH 6/7] fixed error --- main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.py b/main.py index 31b14a1..eedc718 100644 --- a/main.py +++ b/main.py @@ -31,8 +31,10 @@ print_markdown( ) """ +- 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") From c302d8c2e5d60e4177ed7b13e0c680121cba755e Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Mon, 6 Jun 2022 23:51:23 +0200 Subject: [PATCH 7/7] fixed errors --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index eedc718..9aabe78 100644 --- a/main.py +++ b/main.py @@ -31,10 +31,10 @@ print_markdown( ) """ -- + 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")