diff --git a/.env.template b/.env.template index 9e75c22..df9b261 100644 --- a/.env.template +++ b/.env.template @@ -4,3 +4,4 @@ REDDIT_USERNAME="" REDDIT_PASSWORD="" SUBREDDIT="AskReddit" ALLOW_NSFW="False" +POST_ID="" diff --git a/README.md b/README.md index bdeb895..6058b65 100644 --- a/README.md +++ b/README.md @@ -36,14 +36,15 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 4. install [SoX](https://sourceforge.net/projects/sox/files/sox/) 5. Run `python3 main.py` 6. Enjoy 😎 - +## Usage + * an example of a reddit ID is ult7el ## Contributing & Ways to improve 📈 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 contibuting at any skill level. Don't be shy :) contribute! -- [ ] Allowing users to choose a reddit thread instead of being randomized. +- [x] Allowing users to choose a reddit thread instead of being randomized. - [x] Allowing users to choose a background that is picked instead of the Minecraft one. - [x] Allowing users to choose between any subreddit. - [x] Allowing users to change voice. diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 25f5d48..ada56e5 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -4,7 +4,7 @@ from utils.console import print_step, print_substep import praw import random from dotenv import load_dotenv -import os +from os import getenv, environ def ascifi(text): @@ -26,25 +26,31 @@ def get_subreddit_threads(): content = {} load_dotenv() - 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=os.getenv("REDDIT_PASSWORD"), ) + reddit = praw.Reddit(client_id=getenv("REDDIT_CLIENT_ID"), client_secret=getenv("REDDIT_CLIENT_SECRET"), + user_agent="Accessing AskReddit threads", username=getenv("REDDIT_USERNAME"), + password=getenv("REDDIT_PASSWORD"), ) """ Ask user for subreddit input """ - if not os.getenv("SUBREDDIT"): + if not getenv("SUBREDDIT"): subreddit = reddit.subreddit( input("What subreddit would you like to pull from? ")) # if the env isnt set, ask user else: - print_substep(f"Using subreddit: r/{os.getenv('SUBREDDIT')} from environment variable config") + print_substep(f"Using subreddit: r/{getenv('SUBREDDIT')} from environment variable config") subreddit = reddit.subreddit( - os.getenv("SUBREDDIT")) # Allows you to specify in .env. Done for automation purposes. + getenv("SUBREDDIT")) # Allows you to specify in .env. Done for automation purposes. - threads = subreddit.hot(limit=25) - submission = list(threads)[random.randrange(0, 25)] - print_substep(f'subreddit thread is: {submission.title}\n(if you dont like this, you can change it by exiting and rerunning the program)') + if getenv('POST_ID'): + submission = reddit.submission(id=getenv('POST_ID')) + else: + threads = subreddit.hot(limit=25) + submission = list(threads)[random.randrange(0, 25)] + + print(submission) + print_substep( + f'subreddit thread is: {submission.title}\n(if you dont like this, you can change it by exiting and rerunning the program)') - os.environ["VIDEO_TITLE"] = str(ascifi(submission.title)) + environ["VIDEO_TITLE"] = str(ascifi(submission.title)) try: content["thread_url"] = submission.url diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index fec1ada..9023d82 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -32,7 +32,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num): if getenv("ALLOW_NSFW").casefold() == "false": print_substep("NSFW Post Detected. Skipping...") from subprocess import call - call(["python3", "main.py"]) + call(["python", "main.py"]) exit(1) print_substep("Post is NSFW. You are spicy... :fire:") diff --git a/video_creation/voices.py b/video_creation/voices.py index 47c4960..ccb4a9d 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -36,7 +36,7 @@ def save_text_to_mp3(reddit_obj): ttttsw.tts(comment["comment_body"], filename=f"assets/temp/mp3/{idx}.mp3", random_speaker=False) try: length += MP3(f"assets/temp/mp3/{idx}.mp3").info.length - except HeaderNotFoundError or MutagenError: + except (HeaderNotFoundError, MutagenError, Exception): length = sox.file_info.duration(f"assets/temp/mp3/{idx}.mp3") print_substep("Saved Text to MP3 files Successfully.", style="bold green")