From f4b7ff736f60ba50c79fe8c2618ffc5dc5581933 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 19:46:51 -0400 Subject: [PATCH 01/35] .gitignore: Add pycaches --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index a4589e5..3b9b9a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ assets/ +reddit/__pycache__/ +utils/__pycache__/ .env reddit-bot-351418-5560ebc49cac.json \ No newline at end of file From 39a691887eaec73c4fb41214ed906a37f7db5eb1 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 20:44:54 -0400 Subject: [PATCH 02/35] Create setup TUI and improve overall UX --- main.py | 48 ++++++++++++++++++++++- reddit/askreddit.py | 7 +++- requirements.txt | 2 +- setup.py | 96 +++++++++++++++++++++++++++++++++++++++++++++ utils/loader.py | 53 +++++++++++++++++++++++++ 5 files changed, 202 insertions(+), 4 deletions(-) create mode 100644 setup.py create mode 100644 utils/loader.py diff --git a/main.py b/main.py index 8fb3d50..7e16291 100644 --- a/main.py +++ b/main.py @@ -1,15 +1,61 @@ +# 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 +import os from reddit.askreddit import get_askreddit_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 +console = Console() 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") +client_secret=os.getenv("REDDIT_CLIENT_SECRET") +username=os.getenv("REDDIT_USERNAME") +password=os.getenv("REDDIT_PASSWORD") + +console.log("[bold green]Checking environment variables...") +time.sleep(1) + +if client_id == "" or client_secret == "" or username == "" or password == "": + + 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") + else: + if 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() + + + exit() + +console.log("[bold green]Enviroment Variables are set! Continuing...") time.sleep(3) diff --git a/reddit/askreddit.py b/reddit/askreddit.py index 7c7110a..42afab4 100644 --- a/reddit/askreddit.py +++ b/reddit/askreddit.py @@ -1,9 +1,10 @@ +from rich import Console from utils.console import print_markdown, print_step, print_substep import praw import random from dotenv import load_dotenv import os - +console = Console() def get_askreddit_threads(): """ @@ -14,6 +15,7 @@ def get_askreddit_threads(): content = {} load_dotenv() + console.log("Logging in to reddit...") reddit = praw.Reddit( client_id=os.getenv("REDDIT_CLIENT_ID"), client_secret=os.getenv("REDDIT_CLIENT_SECRET"), @@ -25,6 +27,7 @@ def get_askreddit_threads(): threads = askreddit.hot(limit=25) submission = list(threads)[random.randrange(0, 25)] print_substep(f"Video will be: {submission.title} :thumbsup:") + console.log("Getting video comments...") try: content["thread_url"] = submission.url @@ -43,4 +46,4 @@ def get_askreddit_threads(): except AttributeError as e: pass print_substep("Received AskReddit threads Successfully.", style="bold green") - return content + return content \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index da87ca9..e90970b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -34,7 +34,7 @@ rich==12.4.4 six==1.16.0 toml==0.10.1 tqdm==4.64.0 -typed-ast==1.4.1 +typed-ast==1.5.4 # Please see issue https://github.com/elebumm/RedditVideoMakerBot/issues/16 comment three. typing_extensions==4.2.0 update-checker==0.18.0 urllib3==1.26.9 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..8214f72 --- /dev/null +++ b/setup.py @@ -0,0 +1,96 @@ +""" + +Setup Script for RedditVideoMakerBot + +""" + +# Imports +import os +import time +from utils.console import print_markdown +from utils.console import print_step +from utils.console import print_substep +from rich.console import Console +from utils.loader import Loader +console = Console() + +# These lines ensure the user: +# - knows they are in setup mode +# - knows that they are about to erase any other setup files/data. + +print_step("Setup Assistant") + +print_markdown( + "### You're in the setup wizard. Ensure you're supposed to be here, then type yes to continue. If you're not sure, type no to quit." +) + +# This Input is used to ensure the user is sure they want to continue. +ensureSetupIsRequired = input("Are you sure you want to continue? > ") +if ensureSetupIsRequired != "yes": + console.print("[red]Exiting...") + time.sleep(0.5) + exit() +else: + # Again, let them know they are about to erase all other setup data. + console.print("[bold red] This will overwrite your current settings. Are you sure you want to continue? [bold green]yes/no") + overwriteSettings = input("Are you sure you want to continue? > ") + if overwriteSettings != "yes": + console.print("[red]Abort mission! Exiting...") + time.sleep(0.5) + exit() + else: + # Once they confirm, move on with the script. + console.print("[bold green]Alright! Let's get started!") + time.sleep(1) + +console.log("Ensure you have the following ready to enter:") +console.log("[bold green]Reddit Client ID") +console.log("[bold green]Reddit Client Secret") +console.log("[bold green]Reddit Username") +console.log("[bold green]Reddit Password") +time.sleep(0.5) +console.print("[green]If you don't have these, please follow the instructions in the README.md file to set them up.") +console.print("[green]If you do have these, type yes to continue. If you dont, go ahead and grab those quickly and come back.") +confirmUserHasCredentials = input("Are you sure you have the credentials? > ") +if confirmUserHasCredentials != "yes": + console.print("[red]I don't understand that.") + console.print("[red]Exiting...") + exit() +else: + console.print("[bold green]Alright! Let's get started!") + time.sleep(1) + +""" + +Begin the setup process. + +""" + +console.log("Enter your credentials now.") +cliID = input("Client ID > ") +cliSec = input("Client Secret > ") +user = input("Username > ") +passw = input("Password > ") +console.log("Attempting to save your credentials...") +loader = Loader("Saving Credentials...", "Done!").start() + # you can also put a while loop here, e.g. while VideoIsBeingMade == True: ... +time.sleep(0.5) +console.log("Removing old .env file...") +os.remove(".env") +time.sleep(0.5) +console.log("Creating new .env file...") +with open('.env', 'a') as f: + f.write(f'REDDIT_CLIENT_ID="{cliID}"\n') + time.sleep(0.5) + f.write(f'REDDIT_CLIENT_SECRET="{cliSec}"\n') + time.sleep(0.5) + f.write(f'REDDIT_USERNAME="{user}"\n') + time.sleep(0.5) + f.write(f'REDDIT_PASSWORD="{passw}"\n') + +loader.stop() + +console.log("[bold green]Setup Complete! Returning...") + +# Post-Setup: send message and try to run main.py again. +os.system("python3 main.py") \ No newline at end of file diff --git a/utils/loader.py b/utils/loader.py new file mode 100644 index 0000000..58fd662 --- /dev/null +++ b/utils/loader.py @@ -0,0 +1,53 @@ +""" + +Okay, have to admit. This code is from StackOverflow. It's so efficient, that it's probably the best way to do it. +Although, it is edited to use less threads. + +""" +from itertools import cycle +from shutil import get_terminal_size +from threading import Thread +from time import sleep + + +class Loader: + def __init__(self, desc="Loading...", end="Done!", timeout=0.1): + """ + A loader-like context manager + + Args: + desc (str, optional): The loader's description. Defaults to "Loading...". + end (str, optional): Final print. Defaults to "Done!". + timeout (float, optional): Sleep time between prints. Defaults to 0.1. + """ + self.desc = desc + self.end = end + self.timeout = timeout + + self._thread = Thread(target=self._animate, daemon=True) + self.steps = ["β’Ώ", "β£»", "β£½", "β£Ύ", "β£·", "β£―", "⣟", "β‘Ώ"] + self.done = False + + def start(self): + self._thread.start() + return self + + def _animate(self): + for c in cycle(self.steps): + if self.done: + break + print(f"\r{self.desc} {c}", flush=True, end="") + sleep(self.timeout) + + def __enter__(self): + self.start() + + def stop(self): + self.done = True + cols = get_terminal_size((80, 20)).columns + print("\r" + " " * cols, end="", flush=True) + print(f"\r{self.end}", flush=True) + + def __exit__(self, exc_type, exc_value, tb): + # handle exceptions with those variables ^ + self.stop() \ No newline at end of file From 74363f021e73a3cad3ee7d0a2f229d2915a27607 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 20:48:26 -0400 Subject: [PATCH 03/35] README Updates --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 26d8156..3b3acce 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,12 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p ## Installation πŸ‘©β€πŸ’» 1. Clone this repository -2. Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. -3. Run `pip3 install -r requirements.txt` -4. Run `python3 main.py` -5. ... +2. Run `pip3 install -r requirements.txt` +3. + 2a. **Automatic Setup** Run `python3 main.py`, it will automatically detect that you do not have variables set + 2b. **Manual Setup** Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. + +4. (only if you did manual setup) Run `python3 main.py` 6. Enjoy 😎 ## Contributing & Ways to improve πŸ“ˆ From 1e42fd2a3d6ccdfecf620e1c206273149b5f2d26 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 20:49:23 -0400 Subject: [PATCH 04/35] make readme look better --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3b3acce..708b5ad 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,8 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 1. Clone this repository 2. Run `pip3 install -r requirements.txt` 3. - 2a. **Automatic Setup** Run `python3 main.py`, it will automatically detect that you do not have variables set - 2b. **Manual Setup** Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. + 2a. **Automatic Setup**: Run `python3 main.py`, it will automatically detect that you do not have variables set + 2b. **Manual Setup**: Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. 4. (only if you did manual setup) Run `python3 main.py` 6. Enjoy 😎 From 3c4eac42c097a7c4fe7a54cab6699ae325052fdd Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 20:49:46 -0400 Subject: [PATCH 05/35] maybe a *little* bit better --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 708b5ad..82d047d 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 2. Run `pip3 install -r requirements.txt` 3. 2a. **Automatic Setup**: Run `python3 main.py`, it will automatically detect that you do not have variables set + 2b. **Manual Setup**: Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. 4. (only if you did manual setup) Run `python3 main.py` From e4ed7aa69e75538e194d6e75b4cc5e409cd62806 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 20:51:01 -0400 Subject: [PATCH 06/35] Clarification for setup. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 82d047d..6369b4f 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 1. Clone this repository 2. Run `pip3 install -r requirements.txt` 3. - 2a. **Automatic Setup**: Run `python3 main.py`, it will automatically detect that you do not have variables set + 2a. **Automatic Setup**: Run `python3 main.py` and type "yes" where it says "Setup Wizard". The Setup Wizard will guide you through the setup process. 2b. **Manual Setup**: Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. From e03f52988837745f3c583d31525fb6f6132f08b4 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 20:55:20 -0400 Subject: [PATCH 07/35] README: got some of the stages mixed up. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6369b4f..8e7eec7 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,9 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 1. Clone this repository 2. Run `pip3 install -r requirements.txt` 3. - 2a. **Automatic Setup**: Run `python3 main.py` and type "yes" where it says "Setup Wizard". The Setup Wizard will guide you through the setup process. + 3a. **Automatic Setup**: Run `python3 main.py` and type "yes" where it says "Setup Wizard". The Setup Wizard will guide you through the setup process. - 2b. **Manual Setup**: Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. + 3b. **Manual Setup**: Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. 4. (only if you did manual setup) Run `python3 main.py` 6. Enjoy 😎 From 16664e010a8d57a89acef3ad576143e8580c8330 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 13:11:10 -0400 Subject: [PATCH 08/35] Reviews: Various Changes --- main.py | 2 +- setup.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 7e16291..2c026ae 100644 --- a/main.py +++ b/main.py @@ -32,7 +32,7 @@ password=os.getenv("REDDIT_PASSWORD") console.log("[bold green]Checking environment variables...") time.sleep(1) -if client_id == "" or client_secret == "" or username == "" or password == "": +if not all(client_id, client_secret, username, password): 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) diff --git a/setup.py b/setup.py index 8214f72..7e4521f 100644 --- a/setup.py +++ b/setup.py @@ -12,8 +12,15 @@ from utils.console import print_step from utils.console import print_substep from rich.console import Console from utils.loader import Loader +from os.path import exists console = Console() +setup_done = exists(".setup-done-before") + +if setup_done == True: + console.log("[red]Setup was already completed! Please make sure you have to run this script again. If you have to, please delete the file .setup-done-before") + exit() + # These lines ensure the user: # - knows they are in setup mode # - knows that they are about to erase any other setup files/data. @@ -25,7 +32,7 @@ print_markdown( ) # This Input is used to ensure the user is sure they want to continue. -ensureSetupIsRequired = input("Are you sure you want to continue? > ") +ensureSetupIsRequired = input("Are you sure you want to continue? > ").casefold() if ensureSetupIsRequired != "yes": console.print("[red]Exiting...") time.sleep(0.5) @@ -33,7 +40,7 @@ if ensureSetupIsRequired != "yes": else: # Again, let them know they are about to erase all other setup data. console.print("[bold red] This will overwrite your current settings. Are you sure you want to continue? [bold green]yes/no") - overwriteSettings = input("Are you sure you want to continue? > ") + overwriteSettings = input("Are you sure you want to continue? > ").casefold() if overwriteSettings != "yes": console.print("[red]Abort mission! Exiting...") time.sleep(0.5) @@ -51,7 +58,7 @@ console.log("[bold green]Reddit Password") time.sleep(0.5) console.print("[green]If you don't have these, please follow the instructions in the README.md file to set them up.") console.print("[green]If you do have these, type yes to continue. If you dont, go ahead and grab those quickly and come back.") -confirmUserHasCredentials = input("Are you sure you have the credentials? > ") +confirmUserHasCredentials = input("Are you sure you have the credentials? > ").casefold() if confirmUserHasCredentials != "yes": console.print("[red]I don't understand that.") console.print("[red]Exiting...") @@ -88,6 +95,9 @@ with open('.env', 'a') as f: time.sleep(0.5) f.write(f'REDDIT_PASSWORD="{passw}"\n') +with open('.setup-done-before', 'a') as f: + f.write("This file blocks the setup assistant from running again. Delete this file to run setup again.") + loader.stop() console.log("[bold green]Setup Complete! Returning...") From 52302cc42d7e399ccfaf47c94f37381f32fadfb9 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:09:47 -0400 Subject: [PATCH 09/35] gitignore - new files --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3b9b9a4..d6b5611 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ assets/ reddit/__pycache__/ utils/__pycache__/ .env -reddit-bot-351418-5560ebc49cac.json \ No newline at end of file +reddit-bot-351418-5560ebc49cac.json +video_creation/__pycache__/ +.setup-done-before \ No newline at end of file From 4506339e21f673e911f8f5badaee4d20d53c1c07 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:16:15 -0400 Subject: [PATCH 10/35] ACCEPT: Incoming Change (main.py) --- main.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/main.py b/main.py index f1782b2..498d78f 100644 --- a/main.py +++ b/main.py @@ -4,15 +4,8 @@ from utils.console import print_step from utils.console import print_substep from rich.console import Console import time -<<<<<<< HEAD import os -from reddit.askreddit import get_askreddit_threads -||||||| 5b39896 -from reddit.askreddit import get_askreddit_threads -======= - from reddit.subreddit import get_subreddit_threads ->>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9 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 d8def59e5d583071c47eb89cbf86241574eb2808 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:17:48 -0400 Subject: [PATCH 11/35] ACCEPT: Incoming change. (README.md) --- README.md | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/README.md b/README.md index 05ae2df..1dbec21 100644 --- a/README.md +++ b/README.md @@ -31,29 +31,12 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p ## Installation πŸ‘©β€πŸ’» 1. Clone this repository -<<<<<<< HEAD -2. Run `pip3 install -r requirements.txt` -3. - 3a. **Automatic Setup**: Run `python3 main.py` and type "yes" where it says "Setup Wizard". The Setup Wizard will guide you through the setup process. - - 3b. **Manual Setup**: Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. - -4. (only if you did manual setup) Run `python3 main.py` -6. Enjoy 😎 -||||||| 5b39896 -2. Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. -3. Run `pip3 install -r requirements.txt` -4. Run `python3 main.py` -5. ... -6. Enjoy 😎 -======= 2. Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` file, along with whether your account uses two-factor authentication. 3. Run `pip3 install -r requirements.txt` 4. Run `playwright install` and `playwright install-deps`. 5. Run `python3 main.py` 6. ... 7. Enjoy 😎 ->>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9 ## Contributing & Ways to improve πŸ“ˆ @@ -65,4 +48,4 @@ I have tried to simplify the code so anyone can read it and start contributing a - [ ] Allowing users to choose a background that is picked instead of the Minecraft one. - [x] Allowing users to choose between any subreddit. - [ ] Allowing users to change voice. -- [ ] Creating better documentation and adding a command line interface. +- [ ] Creating better documentation and adding a command line interface. \ No newline at end of file From b1c98726eb8389553c78882717877b7cc28251ed Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:20:35 -0400 Subject: [PATCH 12/35] README: Automatic install --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1dbec21..630cca4 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,14 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p ## Installation πŸ‘©β€πŸ’» 1. Clone this repository -2. Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` file, along with whether your account uses two-factor authentication. -3. Run `pip3 install -r requirements.txt` -4. Run `playwright install` and `playwright install-deps`. -5. Run `python3 main.py` +2. Run `pip3 install -r requirements.txt` +3. Run `playwright install` and `playwright install-deps`. +4. + 4a **Automatic Install**: Run `python3 main.py` and type 'yes' to activate the setup assistant. + + 4b **Manual Install**: Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` file, along with whether your account uses two-factor authentication. + +5. Run `python3 main.py` (unless you chose automatic install, then the installer will automatically run main.py) 6. ... 7. Enjoy 😎 From 3b26c0e282fd3e9cbd344fb154d6c5034c0310fa Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:22:07 -0400 Subject: [PATCH 13/35] main.py: Add REDDIT_2FA to env variable check. --- main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.py b/main.py index 498d78f..07f2f13 100644 --- a/main.py +++ b/main.py @@ -28,6 +28,8 @@ 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") + console.log("[bold green]Checking environment variables...") time.sleep(1) From e18bb1229ac19f166389c67cbc6e4ef361b9e058 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:23:09 -0400 Subject: [PATCH 14/35] REQUIREMENTS.TXT: Accept Incoming Change --- requirements.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index 6ae7cfe..59dc596 100644 --- a/requirements.txt +++ b/requirements.txt @@ -35,13 +35,7 @@ rich==12.4.4 six==1.16.0 toml==0.10.1 tqdm==4.64.0 -<<<<<<< HEAD -typed-ast==1.5.4 # Please see issue https://github.com/elebumm/RedditVideoMakerBot/issues/16 comment three. -||||||| 5b39896 -typed-ast==1.4.1 -======= typed-ast==1.5.4 ->>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9 typing_extensions==4.2.0 update-checker==0.18.0 urllib3==1.26.9 From 51d561bc3e479bd6cb5b5791411a6459b028d4d2 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:25:39 -0400 Subject: [PATCH 15/35] Removed an extra line in main.py; added 2fa to setup.py --- main.py | 2 +- setup.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 07f2f13..1882039 100644 --- a/main.py +++ b/main.py @@ -67,4 +67,4 @@ length, number_of_comments = save_text_to_mp3(reddit_object) download_screenshots_of_reddit_posts(reddit_object, number_of_comments) download_background() chop_background_video(length) -final_video = make_final_video(number_of_comments) +final_video = make_final_video(number_of_comments) \ No newline at end of file diff --git a/setup.py b/setup.py index 7e4521f..f49b03b 100644 --- a/setup.py +++ b/setup.py @@ -55,6 +55,7 @@ console.log("[bold green]Reddit Client ID") console.log("[bold green]Reddit Client Secret") console.log("[bold green]Reddit Username") console.log("[bold green]Reddit Password") +console.log("[bold green]Reddit 2FA (yes or no)") time.sleep(0.5) console.print("[green]If you don't have these, please follow the instructions in the README.md file to set them up.") console.print("[green]If you do have these, type yes to continue. If you dont, go ahead and grab those quickly and come back.") @@ -78,6 +79,7 @@ cliID = input("Client ID > ") cliSec = input("Client Secret > ") user = input("Username > ") passw = input("Password > ") +twofactor = input("2fa Enabled? (yes/no) > ") console.log("Attempting to save your credentials...") loader = Loader("Saving Credentials...", "Done!").start() # you can also put a while loop here, e.g. while VideoIsBeingMade == True: ... @@ -94,6 +96,8 @@ with open('.env', 'a') as f: f.write(f'REDDIT_USERNAME="{user}"\n') time.sleep(0.5) f.write(f'REDDIT_PASSWORD="{passw}"\n') + time.sleep(0.5) + f.write(f'REDDIT_2FA="{twofactor}"\n') with open('.setup-done-before', 'a') as f: f.write("This file blocks the setup assistant from running again. Delete this file to run setup again.") From 6b8b96665cb411a0ba89d964e05c411ff8eed48b Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:26:32 -0400 Subject: [PATCH 16/35] Accept Incoming Change --- reddit/subreddit.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index ce4e342..e4a6e69 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -28,14 +28,6 @@ def get_subreddit_threads(): passkey = os.getenv("REDDIT_PASSWORD") content = {} -<<<<<<< HEAD:reddit/askreddit.py - load_dotenv() - console.log("Logging in to reddit...") -||||||| 5b39896:reddit/askreddit.py - load_dotenv() -======= - ->>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9:reddit/subreddit.py reddit = praw.Reddit( client_id=os.getenv("REDDIT_CLIENT_ID"), client_secret=os.getenv("REDDIT_CLIENT_SECRET"), @@ -77,14 +69,6 @@ def get_subreddit_threads(): except AttributeError as e: pass -<<<<<<< HEAD:reddit/askreddit.py - print_substep("Received AskReddit threads Successfully.", style="bold green") - return content -||||||| 5b39896:reddit/askreddit.py - print_substep("Received AskReddit threads Successfully.", style="bold green") - return content -======= print_substep("Received AskReddit threads successfully.", style="bold green") return content ->>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9:reddit/subreddit.py From c4f32a3821317ae039dadd0043b265a2619cf49e Mon Sep 17 00:00:00 2001 From: MeDBeD1 <82283979+MeDBeD1@users.noreply.github.com> Date: Sat, 4 Jun 2022 00:48:20 +1000 Subject: [PATCH 17/35] TTS reads text below the tittle of the post Added option for TTS to read the whole post if text apart from tittle is present (useful for such threads as r/maliciouscompliance) --- subreddit.py | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 subreddit.py diff --git a/subreddit.py b/subreddit.py new file mode 100644 index 0000000..e9ae4fe --- /dev/null +++ b/subreddit.py @@ -0,0 +1,73 @@ +from utils.console import print_markdown, print_step, print_substep +import praw +import random +from dotenv import load_dotenv +import os + + +def get_subreddit_threads(): + + """ + Returns a list of threads from the AskReddit subreddit. + """ + + load_dotenv() + + print_step("Getting AskReddit threads...") + + if os.getenv("REDDIT_2FA").lower() == "yes": + print( + "\nEnter your two-factor authentication code from your authenticator app.\n" + ) + code = input("> ") + print() + pw = os.getenv("REDDIT_PASSWORD") + passkey = f"{pw}:{code}" + else: + passkey = os.getenv("REDDIT_PASSWORD") + + content = {} + + reddit = praw.Reddit( + client_id=os.getenv("REDDIT_CLIENT_ID"), + client_secret=os.getenv("REDDIT_CLIENT_SECRET"), + user_agent="Accessing AskReddit threads", + username=os.getenv("REDDIT_USERNAME"), + password=passkey, + ) + + if os.getenv("SUBREDDIT"): + subreddit = reddit.subreddit(os.getenv("SUBREDDIT")) + else: + # ! Prompt the user to enter a subreddit + try: + subreddit = reddit.subreddit( + input("What subreddit would you like to pull from? ") + ) + except ValueError: + subreddit = reddit.subreddit("askreddit") + print_substep("Subreddit not defined. Using AskReddit.") + + threads = subreddit.hot(limit=25) + submission = list(threads)[random.randrange(0, 25)] + print_substep(f"Video will be: {submission.title} :thumbsup:") + try: + + content["thread_url"] = submission.url + content["thread_title"] = submission.title + submission.selftext + content["comments"] = [] + + for top_level_comment in submission.comments: + content["comments"].append( + { + "comment_body": top_level_comment.body, + "comment_url": top_level_comment.permalink, + "comment_id": top_level_comment.id, + } + ) + + except AttributeError as e: + pass + print_substep("Received AskReddit threads successfully.", style="bold green") + + return content From 310006a166974580645570b8103f88cec7e25db0 Mon Sep 17 00:00:00 2001 From: MeDBeD1 <82283979+MeDBeD1@users.noreply.github.com> Date: Sat, 4 Jun 2022 00:50:36 +1000 Subject: [PATCH 18/35] Deleting becasue i commited in the wrong way, whoops --- subreddit.py | 73 ---------------------------------------------------- 1 file changed, 73 deletions(-) delete mode 100644 subreddit.py diff --git a/subreddit.py b/subreddit.py deleted file mode 100644 index e9ae4fe..0000000 --- a/subreddit.py +++ /dev/null @@ -1,73 +0,0 @@ -from utils.console import print_markdown, print_step, print_substep -import praw -import random -from dotenv import load_dotenv -import os - - -def get_subreddit_threads(): - - """ - Returns a list of threads from the AskReddit subreddit. - """ - - load_dotenv() - - print_step("Getting AskReddit threads...") - - if os.getenv("REDDIT_2FA").lower() == "yes": - print( - "\nEnter your two-factor authentication code from your authenticator app.\n" - ) - code = input("> ") - print() - pw = os.getenv("REDDIT_PASSWORD") - passkey = f"{pw}:{code}" - else: - passkey = os.getenv("REDDIT_PASSWORD") - - content = {} - - reddit = praw.Reddit( - client_id=os.getenv("REDDIT_CLIENT_ID"), - client_secret=os.getenv("REDDIT_CLIENT_SECRET"), - user_agent="Accessing AskReddit threads", - username=os.getenv("REDDIT_USERNAME"), - password=passkey, - ) - - if os.getenv("SUBREDDIT"): - subreddit = reddit.subreddit(os.getenv("SUBREDDIT")) - else: - # ! Prompt the user to enter a subreddit - try: - subreddit = reddit.subreddit( - input("What subreddit would you like to pull from? ") - ) - except ValueError: - subreddit = reddit.subreddit("askreddit") - print_substep("Subreddit not defined. Using AskReddit.") - - threads = subreddit.hot(limit=25) - submission = list(threads)[random.randrange(0, 25)] - print_substep(f"Video will be: {submission.title} :thumbsup:") - try: - - content["thread_url"] = submission.url - content["thread_title"] = submission.title + submission.selftext - content["comments"] = [] - - for top_level_comment in submission.comments: - content["comments"].append( - { - "comment_body": top_level_comment.body, - "comment_url": top_level_comment.permalink, - "comment_id": top_level_comment.id, - } - ) - - except AttributeError as e: - pass - print_substep("Received AskReddit threads successfully.", style="bold green") - - return content From 89d69ff0af09d5904406ae04096460e106a9a59b Mon Sep 17 00:00:00 2001 From: MeDBeD1 <82283979+MeDBeD1@users.noreply.github.com> Date: Sat, 4 Jun 2022 00:53:14 +1000 Subject: [PATCH 19/35] TTS update to read the text below tittle if there is any --- reddit/subreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 5d020fe..e9ae4fe 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -54,7 +54,7 @@ def get_subreddit_threads(): try: content["thread_url"] = submission.url - content["thread_title"] = submission.title + content["thread_title"] = submission.title + submission.selftext content["comments"] = [] for top_level_comment in submission.comments: From 20217be743aad2b7e2d30e608304eb1fc921c9da Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Fri, 3 Jun 2022 13:22:23 -0400 Subject: [PATCH 20/35] resolve gitignore conflict --- .gitignore | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.gitignore b/.gitignore index b85be09..6cf136b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,13 +2,7 @@ assets/ reddit/__pycache__/ utils/__pycache__/ .env -<<<<<<< HEAD reddit-bot-351418-5560ebc49cac.json video_creation/__pycache__/ .setup-done-before -||||||| 5b39896 -reddit-bot-351418-5560ebc49cac.json -======= -reddit-bot-351418-5560ebc49cac.json __pycache__ ->>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9 From 6ec947523273e7ba6c09be85b2cd37e76bbe72bb Mon Sep 17 00:00:00 2001 From: MeDBeD1 <82283979+MeDBeD1@users.noreply.github.com> Date: Sat, 4 Jun 2022 08:47:24 +1000 Subject: [PATCH 21/35] First 2 files of requested changes --- video_creation/final_video.py | 3 ++- video_creation/voices.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index e1f71ff..7dd8d02 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -29,6 +29,7 @@ def make_final_video(number_of_clips): for i in range(0, number_of_clips): audio_clips.append(AudioFileClip(f"assets/mp3/{i}.mp3")) audio_clips.insert(0, AudioFileClip(f"assets/mp3/title.mp3")) + audio_clips.insert(1, AudioFileClip(f"assets/mp3/posttext.mp3")) audio_concat = concatenate_audioclips(audio_clips) audio_composite = CompositeAudioClip([audio_concat]) @@ -44,7 +45,7 @@ def make_final_video(number_of_clips): image_clips.insert( 0, ImageClip(f"assets/png/title.png") - .set_duration(audio_clips[0].duration) + .set_duration(audio_clips[0].duration + audio_clips[1].duration) .set_position("center") .resize(width=W - 100), ) diff --git a/video_creation/voices.py b/video_creation/voices.py index e8d8e43..b4650e6 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -21,6 +21,10 @@ def save_text_to_mp3(reddit_obj): tts.save(f"assets/mp3/title.mp3") length += MP3(f"assets/mp3/title.mp3").info.length + tts = gTTS(text=reddit_obj["thread_post"], lang="en", slow=False) + tts.save(f"assets/mp3/posttext.mp3") + length += MP3(f"assets/mp3/posttext.mp3").info.length + for idx, comment in track(enumerate(reddit_obj["comments"]), "Saving..."): # ! 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: From 2fbb369f8a70905f98a5b2b055e1f8073927d57c Mon Sep 17 00:00:00 2001 From: MeDBeD1 <82283979+MeDBeD1@users.noreply.github.com> Date: Sat, 4 Jun 2022 08:48:10 +1000 Subject: [PATCH 22/35] the 3rd file of requested changes --- reddit/subreddit.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index e9ae4fe..66148d5 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -54,7 +54,8 @@ def get_subreddit_threads(): try: content["thread_url"] = submission.url - content["thread_title"] = submission.title + submission.selftext + content["thread_title"] = submission.title + content["thread_post"] = submission.selftext content["comments"] = [] for top_level_comment in submission.comments: From 2ef606fe29d818cbb666fbddddf9aabd727cdf8b Mon Sep 17 00:00:00 2001 From: MeDBeD1 <82283979+MeDBeD1@users.noreply.github.com> Date: Sat, 4 Jun 2022 16:52:37 +1000 Subject: [PATCH 23/35] Fixed a bug: an error if the thread has no selftext Had to implement a few checks for the thread having selftext and for selftext tts file to exist --- video_creation/final_video.py | 31 ++++++++++++++++++++++--------- video_creation/voices.py | 7 ++++--- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 7dd8d02..6f2fbbf 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -8,7 +8,7 @@ from moviepy.editor import ( CompositeVideoClip, ) from utils.console import print_step - +from pathlib import Path W, H = 1080, 1920 @@ -29,7 +29,10 @@ def make_final_video(number_of_clips): for i in range(0, number_of_clips): audio_clips.append(AudioFileClip(f"assets/mp3/{i}.mp3")) audio_clips.insert(0, AudioFileClip(f"assets/mp3/title.mp3")) - audio_clips.insert(1, AudioFileClip(f"assets/mp3/posttext.mp3")) + try: + audio_clips.insert(1, AudioFileClip(f"assets/mp3/posttext.mp3")) + except: + OSError() audio_concat = concatenate_audioclips(audio_clips) audio_composite = CompositeAudioClip([audio_concat]) @@ -42,13 +45,23 @@ def make_final_video(number_of_clips): .set_position("center") .resize(width=W - 100), ) - image_clips.insert( - 0, - ImageClip(f"assets/png/title.png") - .set_duration(audio_clips[0].duration + audio_clips[1].duration) - .set_position("center") - .resize(width=W - 100), - ) + + if Path(f"assets/mp3/posttext.mp3").is_file(): #audio_clips[1] == AudioFileClip(f"assets/mp3/0.mp3"): + image_clips.insert( + 0, + ImageClip(f"assets/png/title.png") + .set_duration(audio_clips[0].duration + audio_clips[1].duration) + .set_position("center") + .resize(width=W - 100), + ) + else: + image_clips.insert( + 0, + ImageClip(f"assets/png/title.png") + .set_duration(audio_clips[0].duration) + .set_position("center") + .resize(width=W - 100), + ) image_concat = concatenate_videoclips(image_clips).set_position( ("center", "center") ) diff --git a/video_creation/voices.py b/video_creation/voices.py index b4650e6..56a2b23 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -21,9 +21,10 @@ def save_text_to_mp3(reddit_obj): tts.save(f"assets/mp3/title.mp3") length += MP3(f"assets/mp3/title.mp3").info.length - tts = gTTS(text=reddit_obj["thread_post"], lang="en", slow=False) - tts.save(f"assets/mp3/posttext.mp3") - length += MP3(f"assets/mp3/posttext.mp3").info.length + if reddit_obj["thread_post"] != "": + tts = gTTS(text=reddit_obj["thread_post"], lang="en", slow=False) + tts.save(f"assets/mp3/posttext.mp3") + length += MP3(f"assets/mp3/posttext.mp3").info.length for idx, comment in track(enumerate(reddit_obj["comments"]), "Saving..."): # ! Stop creating mp3 files if the length is greater than 50 seconds. This can be longer, but this is just a good starting point From 3115155d894329a4e94bb82cd18e56d3a0c96289 Mon Sep 17 00:00:00 2001 From: MeDBeD1 <82283979+MeDBeD1@users.noreply.github.com> Date: Sun, 5 Jun 2022 08:59:26 +1000 Subject: [PATCH 24/35] Added a check for selftext if selftext file exists it gets deleted and recreated if it is present in the thread --- video_creation/voices.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/video_creation/voices.py b/video_creation/voices.py index 56a2b23..c0df8b7 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -21,6 +21,11 @@ def save_text_to_mp3(reddit_obj): tts.save(f"assets/mp3/title.mp3") length += MP3(f"assets/mp3/title.mp3").info.length + try: + Path(f"assets/mp3/posttext.mp3").unlink() + except OSError as e: + pass + if reddit_obj["thread_post"] != "": tts = gTTS(text=reddit_obj["thread_post"], lang="en", slow=False) tts.save(f"assets/mp3/posttext.mp3") From 49da171b55f562378d01f3bf2a8aa8decd45b2d8 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Sun, 5 Jun 2022 07:35:45 -0400 Subject: [PATCH 25/35] Add OPACITY, SUBREDDIT, and THEME. --- setup.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f49b03b..feaa344 100644 --- a/setup.py +++ b/setup.py @@ -56,6 +56,9 @@ console.log("[bold green]Reddit Client Secret") console.log("[bold green]Reddit Username") console.log("[bold green]Reddit Password") console.log("[bold green]Reddit 2FA (yes or no)") +console.log("[bold green]Opacity (range of 0-1, decimals are OK)") +console.log("[bold green]Subreddit (without r/ or /r/)") +console.log("[bold green]Theme (light or dark)") time.sleep(0.5) console.print("[green]If you don't have these, please follow the instructions in the README.md file to set them up.") console.print("[green]If you do have these, type yes to continue. If you dont, go ahead and grab those quickly and come back.") @@ -80,6 +83,9 @@ cliSec = input("Client Secret > ") user = input("Username > ") passw = input("Password > ") twofactor = input("2fa Enabled? (yes/no) > ") +opacity = input("Opacity? (range of 0-1) > ") +subreddit = input("Subreddit (without r/) > ") +theme = input("Theme? (light or dark) > ") console.log("Attempting to save your credentials...") loader = Loader("Saving Credentials...", "Done!").start() # you can also put a while loop here, e.g. while VideoIsBeingMade == True: ... @@ -98,6 +104,12 @@ with open('.env', 'a') as f: f.write(f'REDDIT_PASSWORD="{passw}"\n') time.sleep(0.5) f.write(f'REDDIT_2FA="{twofactor}"\n') + time.sleep(0.5) + f.write(f'THEME="{theme}"\n') + time.sleep(0.5) + f.write(f'SUBREDDIT="{subreddit}"\n') + time.sleep(0.5) + f.write(f'OPACITY="{opacity}"\n') with open('.setup-done-before', 'a') as f: f.write("This file blocks the setup assistant from running again. Delete this file to run setup again.") @@ -107,4 +119,4 @@ loader.stop() console.log("[bold green]Setup Complete! Returning...") # Post-Setup: send message and try to run main.py again. -os.system("python3 main.py") \ No newline at end of file +os.system("python3 main.py") From c6ab604c186e892b962f026e69997753edf8d83a Mon Sep 17 00:00:00 2001 From: Lewis Menelaws Date: Sun, 5 Jun 2022 13:44:12 -0400 Subject: [PATCH 26/35] Fixed a couple of issues.. --- main.py | 84 +++++++++++++++++++++++++++------------------ reddit/subreddit.py | 25 ++++++++------ 2 files changed, 65 insertions(+), 44 deletions(-) diff --git a/main.py b/main.py index 689ca14..6ebb0ea 100644 --- a/main.py +++ b/main.py @@ -11,12 +11,19 @@ from video_creation.screenshot_downloader import download_screenshots_of_reddit_ from video_creation.final_video import make_final_video from utils.loader import Loader from dotenv import load_dotenv + console = Console() from dotenv import load_dotenv import os, time, shutil configured = True -REQUIRED_VALUES = ["REDDIT_CLIENT_ID","REDDIT_CLIENT_SECRET","REDDIT_USERNAME","REDDIT_PASSWORD", "OPACITY"] +REQUIRED_VALUES = [ + "REDDIT_CLIENT_ID", + "REDDIT_CLIENT_SECRET", + "REDDIT_USERNAME", + "REDDIT_PASSWORD", + "OPACITY", +] print_markdown( @@ -30,68 +37,77 @@ If there is a .env file, check if the required variables are set. If not, print """ -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") +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() 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): - console.log(f"[bold red]Missing Variable: \"{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") - else: - if 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() - - - exit() + 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") + else: + if 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() + + 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") + 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...") -load_dotenv() length, number_of_comments = save_text_to_mp3(reddit_object) -download_screenshots_of_reddit_posts(reddit_object, number_of_comments, os.getenv("THEME")) +download_screenshots_of_reddit_posts( + reddit_object, number_of_comments, os.getenv("THEME") +) download_background() chop_background_video(length) final_video = make_final_video(number_of_comments) - - 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_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) \ No newline at end of file + final_video = make_final_video(number_of_comments) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 9624e35..58ada57 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -1,8 +1,11 @@ -from rich import Console +from rich.console import Console from utils.console import print_markdown, print_step, print_substep from dotenv import load_dotenv + console = Console() import os, random, praw, re + + def get_subreddit_threads(): global submission """ @@ -39,7 +42,9 @@ def get_subreddit_threads(): # ! Prompt the user to enter a subreddit try: subreddit = reddit.subreddit( - re.sub(r"r\/", "", input("What subreddit would you like to pull from? ")) + re.sub( + r"r\/", "", input("What subreddit would you like to pull from? ") + ) ) except ValueError: subreddit = reddit.subreddit("askreddit") @@ -56,14 +61,14 @@ def get_subreddit_threads(): content["comments"] = [] for top_level_comment in submission.comments: - if not top_level_comment.stickied: - content["comments"].append( - { - "comment_body": top_level_comment.body, - "comment_url": top_level_comment.permalink, - "comment_id": top_level_comment.id, - } - ) + if not top_level_comment.stickied: + content["comments"].append( + { + "comment_body": top_level_comment.body, + "comment_url": top_level_comment.permalink, + "comment_id": top_level_comment.id, + } + ) except AttributeError as e: pass From fea66a465c0bd406c698fb44fa5cf78d3ca8e0ab Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sun, 5 Jun 2022 20:03:30 +0100 Subject: [PATCH 27/35] Add contributing guidelines --- CONTRIBUTING.md | 109 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..643ea4c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,109 @@ +# Contributing to Reddit Video Maker Bot πŸŽ₯ + +Thanks for taking the time to contribute! ❀️ + +All types of contributions are encouraged and valued. See the [Table of Contents](#table-of-contents) for different ways to help and details about how this project handles them. Please make sure to read the relevant section before making your contribution. It will make it a lot easier for the maintainers and smooth out the experience for all involved. We are looking forward to your contributions. πŸŽ‰ + +> And if you like the project, but just don't have time to contribute, that's fine. There are other easy ways to support the project and show your appreciation, which we would also be very happy about: +> +> - Star the project +> - Tweet about it +> - Refer this project in your project's readme + +## Table of Contents + +- [I Have a Question](#i-have-a-question) +- [I Want To Contribute](#i-want-to-contribute) +- [Reporting Bugs](#reporting-bugs) +- [Suggesting Enhancements](#suggesting-enhancements) +- [Your First Code Contribution](#your-first-code-contribution) +- [Improving The Documentation](#improving-the-documentation) + +## I Have a Question + +> If you want to ask a question, we assume that you have read the available [Documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/). + +Before you ask a question, it is best to search for existing [Issues](https://github.com/elebumm/RedditVideoMakerBot/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue. It is also advisable to search the internet for answers first. + +If you then still feel the need to ask a question and need clarification, we recommend the following: + +- Open an [Issue](https://github.com/elebumm/RedditVideoMakerBot/issues/new). +- Provide as much context as you can about what you're running into. +- Provide project and platform versions (nodejs, npm, etc), depending on what seems relevant. + +We will then take care of the issue as soon as possible. + +Additionally, there is a [discord channel](https://discord.gg/swqtb7AsNQ) for any questions you may have + +## I Want To Contribute + +### Reporting Bugs + +#### Before Submitting a Bug Report + +A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. Please complete the following steps in advance to help us fix any potential bug as fast as possible. + +- Make sure that you are using the latest version. +- Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions (Make sure that you have read the [documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/). If you are looking for support, you might want to check [this section](#i-have-a-question)). +- To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [issues](https://github.com/elebumm/RedditVideoMakerBot/). +- Also make sure to search the internet (including Stack Overflow) to see if users outside of the GitHub community have discussed the issue - you probably aren't the first to get the error! +- Collect information about the bug: + - Stack trace (Traceback) - preferably formatted in a code block. + - OS, Platform and Version (Windows, Linux, macOS, x86, ARM) + - Version of the interpreter, compiler, SDK, runtime environment, package manager, depending on what seems relevant. + - Your input and the output + - Is the issue reproducable? Does it exist in previous versions? + +#### How Do I Submit a Good Bug Report? + +We use GitHub issues to track bugs and errors. If you run into an issue with the project: + +- Open an [Issue](https://github.com/elebumm/RedditVideoMakerBot/issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.) +- Explain the behavior you would expect and the actual behavior. +- Please provide as much context as possible and describe the _reproduction steps_ that someone else can follow to recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem and create a reduced test case. +- Provide the information you collected in the previous section. + +Once it's filed: + +- The project team will label the issue accordingly. +- A team member will try to reproduce the issue with your provided steps. If there are no reproduction steps or no obvious way to reproduce the issue, the team will try to support you as best as they can, but you may not recieve an instant. +- If the team discovers that this is an issue it will be marked `bug` or `error`, as well as possibly other tags relating to the nature of the error), and the issue will be left to be [implemented by someone](#your-first-code-contribution). + +### Suggesting Enhancements + +This section guides you through submitting an enhancement suggestion for Reddit Video Maker Bot, **including completely new features and minor improvements to existing functionality**. Following these guidelines will help maintainers and the community to understand your suggestion and find related suggestions. + +#### Before Submitting an Enhancement + +- Make sure that you are using the latest version. +- Read the [documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/) carefully and find out if the functionality is already covered, maybe by an individual configuration. +- Perform a [search](https://github.com/elebumm/RedditVideoMakerBot/issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one. +- Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. + +#### How Do I Submit a Good Enhancement Suggestion? + +Enhancement suggestions are tracked as [GitHub issues](https://github.com/elebumm/RedditVideoMakerBot/issues). + +- Use a **clear and descriptive title** for the issue to identify the suggestion. +- Provide a **step-by-step description of the suggested enhancement** in as many details as possible. +- **Describe the current behavior** and **explain which behavior you expected to see instead** and why. At this point you can also tell which alternatives do not work for you. +- You may want to **include screenshots and animated GIFs** which help you demonstrate the steps or point out the part which the suggestion is related to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on macOS and Windows, and [this tool](https://github.com/colinkeenan/silentcast) or [this tool](https://github.com/GNOME/byzanz) on Linux. +- **Explain why this enhancement would be useful** to most users. You may also want to point out the other projects that solved it better and which could serve as inspiration. + +### Your First Code Contribution + +#### Your environment + +You development environment should follow the requirements stated in the [README file](README.md). If you are not using the specified versions, **please reference this in your pull request**, so reviewers can test your code on both versions. + +#### Making your first PR + +When making your PR, follow these guidelines: + +- Your branch has a base of _develop_ **not** _master_ +- You are merging your branch into the _develop_ branch +- You link any issues that are resolved or fixed by your changes. (this is done by typing "Fixes #\") in your pull request. + +### Improving The Documentation + +All updates to the documentation should be made in a pull request to [this repo](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/) From 39ac0c7bc24150ca4c1ffae62e93389b41c58cca Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sun, 5 Jun 2022 20:03:43 +0100 Subject: [PATCH 28/35] Link contributing guidelines in README --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dbb0250..a79da04 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ All done WITHOUT video editing or asset compiling. Just pure ✨programming magi Created by Lewis Menelaws & [TMRRW](https://tmrrwinc.ca) [ + @@ -38,7 +39,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 6. Enjoy 😎 If you want to see more detailed guide, please refer to the official [documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/). -*The Documentation is still being developed and worked on, please be patient as we change / add new knowledge! +\*The Documentation is still being developed and worked on, please be patient as we change / add new knowledge! ## Contributing & Ways to improve πŸ“ˆ @@ -51,3 +52,5 @@ I have tried to simplify the code so anyone can read it and start contributing a - [x] Allowing users to choose between any subreddit. - [ ] Allowing users to change voice. - [ ] Creating better documentation and adding a command line interface. + +Please read our [contributing guidelines](CONTRIBUTING.md) for more detailed information. From f088c482ba8755732f421cfbc39c7e4e5ce36482 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sun, 5 Jun 2022 20:16:07 +0100 Subject: [PATCH 29/35] Add PR template --- .../pull_request_template.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE/pull_request_template.md diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md new file mode 100644 index 0000000..7fc8f80 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md @@ -0,0 +1,21 @@ +# Description + + + +# Issue Fixes + + + +None + +# Checklist: + +- [ ] I am pushing to the **develop** branch +- [ ] I am using the recommended development environment +- [ ] I have performed a self-review of my own code +- [ ] My changes generate no new warnings +- [ ] I have commented my code, particularly in hard-to-understand areas + +# Any other information (e.g how to test the changes) + +None From 1dca1995f2b4a30828306f20f60defe31b4bde12 Mon Sep 17 00:00:00 2001 From: Luka Hietala <95122845+LukaHietala@users.noreply.github.com> Date: Sun, 5 Jun 2022 23:21:36 +0300 Subject: [PATCH 30/35] Fixed the link to the documentation repository. --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 643ea4c..244c711 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -106,4 +106,4 @@ When making your PR, follow these guidelines: ### Improving The Documentation -All updates to the documentation should be made in a pull request to [this repo](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/) +All updates to the documentation should be made in a pull request to [this repo]([https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/](https://github.com/LukaHietala/reddit-bot-docs)) From ea328ba908b02a0e642550d133e701a8c8865b41 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sun, 5 Jun 2022 21:23:57 +0100 Subject: [PATCH 31/35] Make link work --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 244c711..e17be29 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -106,4 +106,4 @@ When making your PR, follow these guidelines: ### Improving The Documentation -All updates to the documentation should be made in a pull request to [this repo]([https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/](https://github.com/LukaHietala/reddit-bot-docs)) +All updates to the documentation should be made in a pull request to [this repo](https://github.com/LukaHietala/reddit-bot-docs) From 156c9884202e529a141f1c3a9075981be95b82d7 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sun, 5 Jun 2022 21:26:22 +0100 Subject: [PATCH 32/35] Fix PR Template --- .../pull_request_template.md | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 .github/PULL_REQUEST_TEMPLATE/pull_request_template.md diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md deleted file mode 100644 index 7fc8f80..0000000 --- a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +++ /dev/null @@ -1,21 +0,0 @@ -# Description - - - -# Issue Fixes - - - -None - -# Checklist: - -- [ ] I am pushing to the **develop** branch -- [ ] I am using the recommended development environment -- [ ] I have performed a self-review of my own code -- [ ] My changes generate no new warnings -- [ ] I have commented my code, particularly in hard-to-understand areas - -# Any other information (e.g how to test the changes) - -None From 3693dce2cad58315b0a1462ee182207880cecfbc Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Sun, 5 Jun 2022 16:37:17 -0400 Subject: [PATCH 33/35] Update main.py --- main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/main.py b/main.py index 6ebb0ea..61ccbbb 100644 --- a/main.py +++ b/main.py @@ -50,7 +50,6 @@ 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.") From 72a4bdabaf898619f92db2d2a5beb3ce5369526f Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sun, 5 Jun 2022 22:27:04 +0100 Subject: [PATCH 34/35] Fix merge errors from other PR's --- .env.template | 6 +++--- main.py | 18 +++--------------- reddit/subreddit.py | 2 +- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/.env.template b/.env.template index 6b55f99..e95c209 100644 --- a/.env.template +++ b/.env.template @@ -4,11 +4,11 @@ REDDIT_CLIENT_SECRET="" REDDIT_USERNAME="" REDDIT_PASSWORD="" -# Valid options are "yes" and "no" +# Valid options are "yes" and "no" REDDIT_2FA="" -#If no, it will ask you a thread link to extract the thread, if yes it will randomize it. -RANDOM_THREAD="no" +#If no, it will ask you a thread link to extract the thread, if yes it will randomize it. +RANDOM_THREAD="yes" # Valid options are "light" and "dark" THEME="" diff --git a/main.py b/main.py index 61ccbbb..9aabe78 100644 --- a/main.py +++ b/main.py @@ -54,7 +54,7 @@ if not os.path.exists(".env"): console.log("[red] Your .env file is invalid, or was never created. Standby.") for val in REQUIRED_VALUES: - print(os.getenv(val)) + #print(os.getenv(val)) if val not in os.environ or not os.getenv(val): console.log(f'[bold red]Missing Variable: "{val}"') configured = False @@ -70,8 +70,8 @@ for val in REQUIRED_VALUES: console.log("[bold green]Here goes nothing! Launching setup wizard...") time.sleep(0.5) os.system("python3 setup.py") - else: - if setup_ask == "no": + + elif setup_ask == "no": console.print("[red]Exiting...") time.sleep(0.5) exit() @@ -79,8 +79,6 @@ for val in REQUIRED_VALUES: console.print("[red]I don't understand that. Exiting...") time.sleep(0.5) exit() - - exit() try: float(os.getenv("OPACITY")) except: @@ -91,16 +89,6 @@ except: exit() console.log("[bold green]Enviroment Variables are set! Continuing...") - -length, number_of_comments = save_text_to_mp3(reddit_object) -download_screenshots_of_reddit_posts( - reddit_object, number_of_comments, os.getenv("THEME") -) -download_background() -chop_background_video(length) -final_video = make_final_video(number_of_comments) - - if configured: reddit_object = get_subreddit_threads() length, number_of_comments = save_text_to_mp3(reddit_object) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 6d5fa7a..c560293 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -33,7 +33,7 @@ def get_subreddit_threads(): username=os.getenv("REDDIT_USERNAME"), password=passkey, ) - + # If the user specifies that he doesnt want a random thread, or if he doesn't insert the "RANDOM_THREAD" variable at all, ask the thread link if not os.getenv("RANDOM_THREAD") or os.getenv("RANDOM_THREAD") == "no": print_substep("Insert the full thread link:", style="bold green") From 7ff6739fee0b694437e6464c5f9f160254cad36d Mon Sep 17 00:00:00 2001 From: MeDBeD1 <82283979+MeDBeD1@users.noreply.github.com> Date: Mon, 6 Jun 2022 07:29:00 +1000 Subject: [PATCH 35/35] Uploaded file with requested changes via DMs --- main.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/main.py b/main.py index 61ccbbb..0727e20 100644 --- a/main.py +++ b/main.py @@ -91,16 +91,6 @@ except: exit() console.log("[bold green]Enviroment Variables are set! Continuing...") - -length, number_of_comments = save_text_to_mp3(reddit_object) -download_screenshots_of_reddit_posts( - reddit_object, number_of_comments, os.getenv("THEME") -) -download_background() -chop_background_video(length) -final_video = make_final_video(number_of_comments) - - if configured: reddit_object = get_subreddit_threads() length, number_of_comments = save_text_to_mp3(reddit_object)