diff --git a/.env b/.env new file mode 100644 index 0000000..7b6a0d8 --- /dev/null +++ b/.env @@ -0,0 +1,48 @@ +REDDIT_CLIENT_ID="KJ0zznAbjjDhXgiQbyvgoA" +REDDIT_CLIENT_SECRET="qxG7-OR-fTzH-kK9nPMBp7NVKNOr8A" + +REDDIT_USERNAME="ayoubkam" +REDDIT_PASSWORD="IMayoub7" + +# If no, it will ask you a thread link to extract the thread, if yes it will randomize it. Default: "no" +RANDOM_THREAD="no" + +# Valid options are "yes" and "no" for the variable below AskReddit AskMen +REDDIT_2FA="no" +SUBREDDIT="AskReddit" +# True or False +ALLOW_NSFW="False" +# Used if you want to use a specific post. example of one is urdtfx +POST_ID="" +#set to either LIGHT or DARK +RandomTheme="yes" +THEME="LIGHT" +# used if you want to run multiple times. set to an int e.g. 4 or 29 and leave blank for 1 +TIMES_TO_RUN="" +# max number of characters a comment can have. +MAX_COMMENT_LENGTH="500" # default is 500 +# Range is 0 -> 1 recommended around 0.8-0.9 +OPACITY="0.9" + +# choose wish Background video you want +RandomBackground="yes" # yes or no +BackgroundChoice="subway" # gta - rocket-league - minecraft - subway + +# choose wish music you want +RandomMusic="yes" # yes or no +MusicChoice="eternalyouth" # lilnas - pianojapan - sundayvibes - eternalyouth + +# Once the thread is generated you can comfirm it or generate a new one. (Yes for this to be active). +# If this is left blank the bot will choose a thread randomly and make the video +Choose_Thread="" + +# If True, all text that go through TTS will be filtered by inappropriate language +# Use "yes" or "no" (default) +PROFANE_FILTER="yes" + +# see different voice options: todo: add docs +VOICE="en_us_007" # e.g. en_us_002 Matthew RUSSELL Justin en_us_006 en_us_007 +TTsChoice="tiktok" + +# IN-PROGRESS - not yet implemented +STORYMODE="False" diff --git a/.gitignore b/.gitignore index 793db5d..4ee3693 100644 --- a/.gitignore +++ b/.gitignore @@ -241,5 +241,3 @@ reddit-bot-351418-5560ebc49cac.json *.pyc video_creation/data/videos.json video_creation/data/envvars.txt - -config.toml diff --git a/.pylintrc b/.pylintrc index b03c808..e3fead7 100644 --- a/.pylintrc +++ b/.pylintrc @@ -149,7 +149,7 @@ disable=raw-checker-failed, suppressed-message, useless-suppression, deprecated-pragma, - use-symbolic-message-instead, + use-symbolic-message-instead attribute-defined-outside-init, invalid-name, missing-docstring, diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8fc7d3d..e3e858d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,3 @@ - # Contributing to Reddit Video Maker Bot 🎥 Thanks for taking the time to contribute! ❤️ @@ -106,41 +105,13 @@ Enhancement suggestions are tracked as [GitHub issues](https://github.com/elebum 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. -#### Setting up your development repository - -These steps are only specified for beginner developers trying to contribute to this repository. -If you know how to make a fork and clone, you can skip these steps. - -Before contributing, follow these steps (if you are a beginner) - -- Create a fork of this repository to your personal account -- Clone the repo to your computer -- Make sure that you have all dependencies installed -- Run `python main.py` to make sure that the program is working -- Now, you are all setup to contribute your own features to this repo! - -Even if you are a beginner to working with python or contributing to open source software, -don't worry! You can still try contributing even to the documentation! - -("Setting up your development repository" was written by a beginner developer themselves!) - - #### 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 -- Where possible, you have used `git pull --rebase`, to avoid creating unnecessary merge commits -- You have meaningful commits, and if possible, follow the commit style guide of `type: explanation` -- Here are the commit types: - - **feat** - a new feature - - **fix** - a bug fix - - **docs** - a change to documentation / commenting - - **style** - formatting changes - does not impact code - - **refactor** - refactored code - - **chore** - updating configs, workflows etc - does not impact code +- 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 diff --git a/Color-Reddit-Logo.jpg b/Color-Reddit-Logo.jpg new file mode 100644 index 0000000..267a827 Binary files /dev/null and b/Color-Reddit-Logo.jpg differ diff --git a/Color-Reddit.jpg b/Color-Reddit.jpg new file mode 100644 index 0000000..b57e025 Binary files /dev/null and b/Color-Reddit.jpg differ diff --git a/README.md b/README.md index 8d61d9a..26b5814 100644 --- a/README.md +++ b/README.md @@ -32,41 +32,36 @@ The only original thing being done is the editing and gathering of all materials ## Requirements -- Python 3.9+ +- Python 3.6+ - Playwright (this should install automatically in installation) +- Sox ## Installation 👩‍💻 1. Clone this repository -2. Run `pip install -r requirements.txt` +2. 2a **Automatic Install**: Run `python main.py` and type 'yes' to activate the setup assistant. -3. Run `python -m playwright install` and `python -m playwright install-deps` + 2b **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. -**EXPERIMENTAL!!!!** +3. Install [SoX](https://sourceforge.net/projects/sox/files/sox/) + +4. Run `pip install -r requirements.txt` -On MacOS and Linux (debian, arch, fedora and centos, and based on those), you can run an install script that will automatically install steps 1 to 3. (requires bash) +5. Run `playwright install` and `playwright install-deps`. (if this fails try adding python -m to the front of the command) -`bash <(curl -sL https://raw.githubusercontent.com/elebumm/RedditVideoMakerBot/master/install.sh)` - -This can also be used to update the installation - -4. Run `python main.py` -5. Visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps), and set up an app that is a "script". Paste any URL in redirect URL. Ex:google.com -6. The bot will ask you to fill in your details to connect to the Reddit API, and configure the bot to your liking +6. Run `python main.py` (unless you chose automatic install, then the installer will automatically run main.py) + 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. 7. Enjoy 😎 -8. If you need to reconfigure the bot, simply open the `config.toml` file and delete the lines that need to be changed. On the next run of the bot, it will help you reconfigure those options. (Note if you got an error installing or running the bot try first rerunning the command with a three after the name e.g. python3 or pip3) - -If you want to read more detailed guide about the bot, please refer to the [documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/) - ## Video https://user-images.githubusercontent.com/66544866/173453972-6526e4e6-c6ef-41c5-ab40-5d275e724e7c.mp4 ## Contributing & Ways to improve 📈 -In its current state, this bot does exactly what it needs to do. However, improvements can always be made! +In its current state, this bot does exactly what it needs to do. However, lots of improvements can be made. I have tried to simplify the code so anyone can read it and start contributing at any skill level. Don't be shy :) contribute! @@ -85,11 +80,11 @@ Please read our [contributing guidelines](CONTRIBUTING.md) for more detailed inf Elebumm (Lewis#6305) - https://github.com/elebumm (Founder) -Jason (JasonLovesDoggo#1904) - https://github.com/JasonLovesDoggo (Maintainer) +Jason (JasonLovesDoggo#1904) - https://github.com/JasonLovesDoggo CallumIO (c.#6837) - https://github.com/CallumIO -Verq (Verq#2338) - https://github.com/CordlessCoder +HarryDaDev (hrvyy#9677) - https://github.com/ImmaHarry LukaHietala (Pix.#0001) - https://github.com/LukaHietala diff --git a/k0ozkhhjubh31.jpg b/k0ozkhhjubh31.jpg new file mode 100644 index 0000000..a520214 Binary files /dev/null and b/k0ozkhhjubh31.jpg differ diff --git a/k0ozkhhjubh31.webp b/k0ozkhhjubh31.webp new file mode 100644 index 0000000..8857040 Binary files /dev/null and b/k0ozkhhjubh31.webp differ diff --git a/main.py b/main.py index 8a0755d..0a64820 100755 --- a/main.py +++ b/main.py @@ -1,29 +1,17 @@ -#!/usr/bin/env python -import math -import re -from subprocess import Popen -from os import name - -from prawcore import ResponseException +import time +from subprocess import Popen +from dotenv import load_dotenv +from os import getenv, name from reddit.subreddit import get_subreddit_threads from utils.cleanup import cleanup -from utils.console import print_markdown, print_step, print_substep -from utils import settings -from utils.id import id -from utils.version import checkversion - -from video_creation.background import ( - download_background, - chop_background_video, - get_background_config, -) +from utils.console import print_markdown, print_step +# from utils.checker import envUpdate +from video_creation.background import download_background, chop_background_video, get_background_config 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.4.1" - +VERSION = 2.1 print( """ ██████╗ ███████╗██████╗ ██████╗ ██╗████████╗ ██╗ ██╗██╗██████╗ ███████╗ ██████╗ ███╗ ███╗ █████╗ ██╗ ██╗███████╗██████╗ @@ -34,71 +22,72 @@ print( ╚═╝ ╚═╝╚══════╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ """ ) +load_dotenv() # Modified by JasonLovesDoggo 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/)" ) -checkversion(__VERSION__) +time.sleep(1) + +client_id = getenv("REDDIT_CLIENT_ID") +client_secret = getenv("REDDIT_CLIENT_SECRET") +username = getenv("REDDIT_USERNAME") +password = getenv("REDDIT_PASSWORD") +reddit2fa = getenv("REDDIT_2FA") + + +def main(): + #envUpdate() + cleanup() + + def get_obj(): + reddit_obj = get_subreddit_threads() + return reddit_obj + try: + reddit_object = get_obj() + except AttributeError: + print_step("problem in the internet, try again") + + if getenv("Choose_Thread").lower() == "yes": #The user isn't forced to choose the random thread + u_inp = input("Is this a good threads?(Y/N/Stop) :") + if u_inp.upper() == 'STOP': exit() + elif u_inp.upper() != 'Y': + print_step("Searching for a new thread...") + main() -def main(POST_ID=None): - reddit_object = get_subreddit_threads(POST_ID) - global redditid - redditid = id(reddit_object) + length, number_of_comments = save_text_to_mp3(reddit_object) - length = math.ceil(length) download_screenshots_of_reddit_posts(reddit_object, number_of_comments) + + bg_config = get_background_config() download_background(bg_config) - chop_background_video(bg_config, length, reddit_object) - make_final_video(number_of_comments, length, reddit_object, bg_config) + chop_background_video(bg_config, length) + make_final_video(number_of_comments, length, bg_config) + + #download_background() + #chop_background_video(length) + #make_final_video(number_of_comments, length) def run_many(times): - for x in range(1, times + 1): + for x in range(times): + x = x + 1 print_step( - f'on the {x}{("th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th")[x % 10]} iteration of {times}' + f'on the {x}{("st" if x == 1 else ("nd" if x == 2 else ("rd" if x == 3 else "th")))} iteration of {times}' ) # correct 1st 2nd 3rd 4th 5th.... main() Popen("cls" if name == "nt" else "clear", shell=True).wait() -def shutdown(): - print_markdown("## Clearing temp files") - try: - redditid - except NameError: - print("Exiting...") - exit() - else: - cleanup(redditid) - print("Exiting...") - exit() - if __name__ == "__main__": - config = settings.check_toml("utils/.config.template.toml", "config.toml") - config is False and exit() try: - if config["settings"]["times_to_run"]: - run_many(config["settings"]["times_to_run"]) - - elif len(config["reddit"]["thread"]["post_id"].split("+")) > 1: - for index, post_id in enumerate(config["reddit"]["thread"]["post_id"].split("+")): - index += 1 - print_step( - f'on the {index}{("st" if index % 10 == 1 else ("nd" if index % 10 == 2 else ("rd" if index % 10 == 3 else "th")))} post of {len(config["reddit"]["thread"]["post_id"].split("+"))}' - ) - main(post_id) - Popen("cls" if name == "nt" else "clear", shell=True).wait() + if getenv("TIMES_TO_RUN") and isinstance(int(getenv("TIMES_TO_RUN")), int): + run_many(int(getenv("TIMES_TO_RUN"))) else: main() except KeyboardInterrupt: - shutdown() - except ResponseException: - # error for invalid credentials - print_markdown("## Invalid credentials") - print_markdown("Please check your credentials in the config.toml file") - - shutdown() - - # todo error + print_markdown("## Clearing temp files") + cleanup() + exit() diff --git a/requirements.txt b/requirements.txt index a954c20..490b0c1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,13 +1,10 @@ -boto3==1.24.24 -botocore==1.27.24 gTTS==2.2.4 moviepy==1.0.3 -playwright==1.23.0 +mutagen==1.45.1 +playwright==1.22.0 praw==7.6.0 +python-dotenv==0.20.0 pytube==12.1.0 -requests==2.28.1 -rich==12.5.1 -toml==0.10.2 -translators==5.3.1 -pyttsx3==2.90 -Pillow~=9.1.1 +requests==2.28.0 +rich==12.4.4 +sox==1.4.1 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..a8d7f12 --- /dev/null +++ b/setup.py @@ -0,0 +1,205 @@ +#!/usr/bin/env python3 +# Setup Script for RedditVideoMakerBot + + +# Imports +import os +import subprocess +import re +from utils.console import print_markdown +from utils.console import print_step +from rich.console import Console +from utils.loader import Loader + +console = Console() + + +def handle_input( + message: str = "", + check_type=False, + match: str = "", + err_message: str = "", + nmin=None, + nmax=None, + oob_error="", +): + match = re.compile(match + "$") + while True: + user_input = input(message + "\n> ").strip() + if re.match(match, user_input) is not None: + if check_type is not False: + try: + user_input = check_type(user_input) + if nmin is not None and user_input < nmin: + console.log("[red]" + oob_error) # Input too low failstate + continue + if nmax is not None and user_input > nmax: + console.log("[red]" + oob_error) # Input too high + continue + break # Successful type conversion and number in bounds + except ValueError: + console.log("[red]" + err_message) # Type conversion failed + continue + if nmin is not None and len(user_input) < nmin: # Check if string is long enough + console.log("[red]" + oob_error) + continue + if nmax is not None and len(user_input) > nmax: # Check if string is not too long + console.log("[red]" + oob_error) + continue + break + console.log("[red]" + err_message) + + return user_input + + +if os.path.isfile(".setup-done-before"): + console.log( + "[red]Setup was already completed! Please make sure you have to run this script again. If that is such, 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. + +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. +if input("Are you sure you want to continue? > ").strip().casefold() != "yes": + console.print("[red]Exiting...") + exit() +# This code is inaccessible if the prior check fails, and thus an else statement is unnecessary + + +# 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" +) + + +if input("Are you sure you want to continue? > ").strip().casefold() != "yes": + console.print("[red]Abort mission! Exiting...") + exit() +# This is once again inaccessible if the prior checks fail +# Once they confirm, move on with the script. +console.print("[bold green]Alright! Let's get started!") + +print() +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") +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)") +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." +) +print() + + +if input("Are you sure you have the credentials? > ").strip().casefold() != "yes": + console.print("[red]I don't understand that.") + console.print("[red]Exiting...") + exit() + + +console.print("[bold green]Alright! Let's get started!") + +# Begin the setup process. + +console.log("Enter your credentials now.") +client_id = handle_input( + "Client ID > ", + False, + "[-a-zA-Z0-9._~+/]+=*", + "That is somehow not a correct ID, try again.", + 12, + 30, + "The ID should be over 12 and under 30 characters, double check your input.", +) +client_sec = handle_input( + "Client Secret > ", + False, + "[-a-zA-Z0-9._~+/]+=*", + "That is somehow not a correct secret, try again.", + 20, + 40, + "The secret should be over 20 and under 40 characters, double check your input.", +) +user = handle_input( + "Username > ", + False, + r"[_0-9a-zA-Z]+", + "That is not a valid user", + 3, + 20, + "A username HAS to be between 3 and 20 characters", +) +passw = handle_input("Password > ", False, ".*", "", 8, None, "Password too short") +twofactor = handle_input( + "2fa Enabled? (yes/no) > ", + False, + r"(yes)|(no)", + "You need to input either yes or no", +) +opacity = handle_input( + "Opacity? (range of 0-1) > ", + float, + ".*", + "You need to input a number between 0 and 1", + 0, + 1, + "Your number is not between 0 and 1", +) +subreddit = handle_input( + "Subreddit (without r/) > ", + False, + r"[_0-9a-zA-Z]+", + "This subreddit cannot exist, make sure you typed it in correctly and removed the r/ (or /r/).", + 3, + 20, + "A subreddit name HAS to be between 3 and 20 characters", +) +theme = handle_input( + "Theme? (light or dark) > ", + False, + r"(light)|(dark)", + "You need to input 'light' or 'dark'", +) +loader = Loader("Attempting to save your credentials...", "Done!").start() +# you can also put a while loop here, e.g. while VideoIsBeingMade == True: ... +console.log("Writing to the .env file...") +with open(".env", "w") as f: + f.write( + f"""REDDIT_CLIENT_ID="{client_id}" +REDDIT_CLIENT_SECRET="{client_sec}" +REDDIT_USERNAME="{user}" +REDDIT_PASSWORD="{passw}" +REDDIT_2FA="{twofactor}" +THEME="{theme}" +SUBREDDIT="{subreddit}" +OPACITY={opacity} +""" + ) + +with open(".setup-done-before", "w") 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...") + +# Post-Setup: send message and try to run main.py again. +subprocess.call("python3 main.py", shell=True)