From 4f3dcaf6944cd060806c6ed3e5de92d5e825d1ef Mon Sep 17 00:00:00 2001 From: Arjun Dureja Date: Wed, 1 Jun 2022 14:33:35 -0400 Subject: [PATCH 1/3] add dark mode --- .env.template | 3 ++- main.py | 5 ++++- video_creation/cookies.json | 8 ++++++++ video_creation/screenshot_downloader.py | 11 +++++++++-- 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 video_creation/cookies.json diff --git a/.env.template b/.env.template index e00c242..3f49f24 100644 --- a/.env.template +++ b/.env.template @@ -1,4 +1,5 @@ REDDIT_CLIENT_ID="" REDDIT_CLIENT_SECRET="" REDDIT_USERNAME="" -REDDIT_PASSWORD="" \ No newline at end of file +REDDIT_PASSWORD="" +THEME="" \ No newline at end of file diff --git a/main.py b/main.py index 8fb3d50..3453f6d 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,8 @@ 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 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." @@ -15,8 +17,9 @@ time.sleep(3) reddit_object = get_askreddit_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) 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 66c96f1..5cedabb 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 == "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(): From 374ece3915126e8d5d11987fd7085961c5390d6f Mon Sep 17 00:00:00 2001 From: Vardhaman <83634399+cyai@users.noreply.github.com> Date: Fri, 3 Jun 2022 19:32:59 +0530 Subject: [PATCH 2/3] Removed extra installation step I removed the extra installation step which was not necessary! --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 00e30da..1d292a8 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 3. Run `pip3 install -r requirements.txt` 4. Run `playwright install` and `playwright install-deps`. 5. Run `python3 main.py` -6. ... -7. Enjoy 😎 +6. Enjoy 😎 ## Contributing & Ways to improve 📈 From 16f57bf4775fc72fab7bbd0f035a49dc3fac91cb Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Fri, 3 Jun 2022 17:23:49 +0100 Subject: [PATCH 3/3] Add casefold to ignore case in env file for theme --- video_creation/screenshot_downloader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 744fc3e..4c4380a 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -23,7 +23,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): browser = p.chromium.launch() context = browser.new_context() - if theme == "dark": + if theme.casefold() == "dark": cookie_file = open('video_creation/cookies.json') cookies = json.load(cookie_file) context.add_cookies(cookies)