diff --git a/.env.template b/.env.template index f00c2ac..5ab4ae4 100644 --- a/.env.template +++ b/.env.template @@ -6,5 +6,6 @@ REDDIT_PASSWORD="" # Valid options are "yes" and "no" for the variable below REDDIT_2FA="" +THEME="" SUBREDDIT="" diff --git a/README.md b/README.md index 630cca4..8dcd1aa 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p ## Installation 👩‍💻 1. Clone this repository + 2. Run `pip3 install -r requirements.txt` 3. Run `playwright install` and `playwright install-deps`. 4. @@ -39,9 +40,9 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 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 😎 + ## Contributing & Ways to improve 📈 In its current state, this bot does exactly what it needs to do. However, lots of improvements can be made. diff --git a/main.py b/main.py index 1882039..42f98f3 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,8 @@ 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 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." ) @@ -63,8 +65,9 @@ time.sleep(3) reddit_object = get_subreddit_threads() +load_dotenv() length, number_of_comments = save_text_to_mp3(reddit_object) -download_screenshots_of_reddit_posts(reddit_object, number_of_comments) +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) \ No newline at end of file diff --git a/video_creation/cookies.json b/video_creation/cookies.json new file mode 100644 index 0000000..2e4e116 --- /dev/null +++ b/video_creation/cookies.json @@ -0,0 +1,8 @@ +[ + { + "name": "USER", + "value": "eyJwcmVmcyI6eyJ0b3BDb250ZW50RGlzbWlzc2FsVGltZSI6MCwiZ2xvYmFsVGhlbWUiOiJSRURESVQiLCJuaWdodG1vZGUiOnRydWUsImNvbGxhcHNlZFRyYXlTZWN0aW9ucyI6eyJmYXZvcml0ZXMiOmZhbHNlLCJtdWx0aXMiOmZhbHNlLCJtb2RlcmF0aW5nIjpmYWxzZSwic3Vic2NyaXB0aW9ucyI6ZmFsc2UsInByb2ZpbGVzIjpmYWxzZX0sInRvcENvbnRlbnRUaW1lc0Rpc21pc3NlZCI6MH19", + "domain": ".reddit.com", + "path": "/" + } +] diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 91fed8a..4c4380a 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -2,9 +2,10 @@ from playwright.sync_api import sync_playwright from pathlib import Path from rich.progress import track from utils.console import print_step, print_substep +import json -def download_screenshots_of_reddit_posts(reddit_object, screenshot_num): +def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): """Downloads screenshots of reddit posts as they are seen on the web. Args: @@ -20,9 +21,15 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num): print_substep("Launching Headless Browser...") browser = p.chromium.launch() + context = browser.new_context() + + if theme.casefold() == "dark": + cookie_file = open('video_creation/cookies.json') + cookies = json.load(cookie_file) + context.add_cookies(cookies) # Get the thread screenshot - page = browser.new_page() + page = context.new_page() page.goto(reddit_object["thread_url"]) if page.locator('[data-testid="content-gate"]').is_visible():