diff --git a/.env.template b/.env.template index e00c242..dab64d3 100644 --- a/.env.template +++ b/.env.template @@ -1,4 +1,6 @@ REDDIT_CLIENT_ID="" REDDIT_CLIENT_SECRET="" REDDIT_USERNAME="" -REDDIT_PASSWORD="" \ No newline at end of file +REDDIT_PASSWORD="" + +SUBREDDIT="" \ No newline at end of file diff --git a/README.md b/README.md index 26d8156..d7ae30a 100644 --- a/README.md +++ b/README.md @@ -33,18 +33,19 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 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. ... -6. Enjoy 😎 +4. Run `playwright install` and `playwright install-deps`. +5. Run `python3 main.py` +6. ... +7. Enjoy 😎 ## 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! +I have tried to simplify the code so anyone can read it and start contributing at any skill level. Don't be shy :) contribute! - [ ] Allowing users to choose a reddit thread instead of being randomized. - [ ] Allowing users to choose a background that is picked instead of the Minecraft one. -- [ ] Allowing users to choose between any subreddit. +- [x] Allowing users to choose between any subreddit. - [ ] Allowing users to change voice. - [ ] Creating better documentation and adding a command line interface. diff --git a/main.py b/main.py index 8fb3d50..02a0c65 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ from utils.console import print_markdown import time -from reddit.askreddit import get_askreddit_threads +from reddit.subreddit import get_subreddit_threads from video_creation.background import download_background, chop_background_video from video_creation.voices import save_text_to_mp3 from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts @@ -13,7 +13,7 @@ print_markdown( time.sleep(3) -reddit_object = get_askreddit_threads() +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) diff --git a/reddit/askreddit.py b/reddit/subreddit.py similarity index 67% rename from reddit/askreddit.py rename to reddit/subreddit.py index 21b2277..c35ea05 100644 --- a/reddit/askreddit.py +++ b/reddit/subreddit.py @@ -10,7 +10,7 @@ def get_askreddit_threads(): Returns a list of threads from the AskReddit subreddit. """ - print_step("Getting AskReddit threads...") + print_step("Getting subreddit threads...") content = {} load_dotenv() @@ -21,8 +21,20 @@ def get_askreddit_threads(): username=os.getenv("REDDIT_USERNAME"), password=os.getenv("REDDIT_PASSWORD"), ) - askreddit = reddit.subreddit("askreddit") - threads = askreddit.hot(limit=25) + + 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: @@ -42,5 +54,5 @@ def get_askreddit_threads(): except AttributeError as e: pass - print_substep("Received AskReddit threads Successfully.", style="bold green") + print_substep("Received subreddit threads Successfully.", style="bold green") return content diff --git a/requirements.txt b/requirements.txt index da87ca9..e464043 100644 --- a/requirements.txt +++ b/requirements.txt @@ -28,13 +28,13 @@ pyflakes==2.2.0 Pygments==2.12.0 python-dotenv==0.20.0 pytube==12.1.0 -regex==2020.10.15 +regex==2022.4.24 requests==2.27.1 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 typing_extensions==4.2.0 update-checker==0.18.0 urllib3==1.26.9 diff --git a/video_creation/background.py b/video_creation/background.py index 20dbe73..d4b8e5f 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -1,5 +1,6 @@ from random import randrange from pytube import YouTube +from pytube.cli import on_progress from pathlib import Path from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip from moviepy.editor import VideoFileClip @@ -11,7 +12,6 @@ def get_start_and_end_times(video_length, length_of_clip): random_time = randrange(180, int(length_of_clip) - int(video_length)) return random_time, random_time + video_length - def download_background(): """Downloads the background video from youtube. @@ -23,7 +23,7 @@ def download_background(): "We need to download the Minecraft background video. This is fairly large but it's only done once. 😎" ) print_substep("Downloading the background video... please be patient 🙏") - YouTube("https://www.youtube.com/watch?v=n_Dv4JMiwK8").streams.filter( + YouTube("https://www.youtube.com/watch?v=n_Dv4JMiwK8", on_progress_callback=on_progress).streams.filter( res="720p" ).first().download( "assets/mp4",