From 4f3dcaf6944cd060806c6ed3e5de92d5e825d1ef Mon Sep 17 00:00:00 2001 From: Arjun Dureja Date: Wed, 1 Jun 2022 14:33:35 -0400 Subject: [PATCH 01/10] 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 654fec94c7c0fe8a4191da2623b76916c477291a Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Thu, 2 Jun 2022 20:37:22 +0100 Subject: [PATCH 02/10] Update dependencies Removed all unnecessary dependencies from requirements.txt --- requirements.txt | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/requirements.txt b/requirements.txt index 59dc596..fd28b7f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,44 +1,8 @@ -appdirs==1.4.4 -black==20.8b1 -certifi==2021.10.8 -charset-normalizer==2.0.12 -click==7.1.2 -commonmark==0.9.1 -decorator==4.4.2 -flake8==3.8.3 -greenlet==1.1.2 gTTS==2.2.4 -idna==3.3 -imageio==2.19.2 -imageio-ffmpeg==0.4.7 -mccabe==0.6.1 moviepy==1.0.3 mutagen==1.45.1 -mypy-extensions==0.4.3 -numpy==1.22.3 -pathspec==0.8.0 -Pillow==9.1.1 playwright==1.22.0 praw==7.6.0 -prawcore==2.3.0 -proglog==0.1.10 -pycodestyle==2.6.0 -pyee==8.1.0 -pyflakes==2.2.0 -Pygments==2.12.0 python-dotenv==0.20.0 - -regex==2020.10.15 - -requests==2.27.1 rich==12.4.4 -six==1.16.0 -toml==0.10.1 -tqdm==4.64.0 -typed-ast==1.5.4 -typing_extensions==4.2.0 -update-checker==0.18.0 -urllib3==1.26.9 -websocket-client==1.3.2 -websockets==10.1 -yt-dlp==2022.5.18 \ No newline at end of file +yt_dlp==2022.5.18 From 593094d14b075eec523382154a84f25c043237e1 Mon Sep 17 00:00:00 2001 From: andronedev Date: Thu, 2 Jun 2022 21:49:38 +0200 Subject: [PATCH 03/10] add Docker support --- .dockerignore | 1 + .gitignore | 4 +++- Dockerfile | 14 ++++++++++++++ build.sh | 1 + run.sh | 1 + video_creation/screenshot_downloader.py | 7 ++++--- 6 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100755 build.sh create mode 100755 run.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1d1fe94 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +Dockerfile \ No newline at end of file diff --git a/.gitignore b/.gitignore index a4589e5..52b1988 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ assets/ .env -reddit-bot-351418-5560ebc49cac.json \ No newline at end of file +reddit-bot-351418-5560ebc49cac.json +__pycache__ +out \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9d7f280 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM mcr.microsoft.com/playwright + +RUN apt update +RUN apt install python3-pip -y + +RUN mkdir /app +ADD . /app +WORKDIR /app +RUN pip install -r requirements.txt + +# tricks for pytube : https://github.com/elebumm/RedditVideoMakerBot/issues/142 +RUN sed -i 's/re.compile(r"^\\w+\\W")/re.compile(r"^\\$*\\w+\\W")/' /usr/local/lib/python3.8/dist-packages/pytube/cipher.py + +CMD ["python3", "main.py"] \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..7d4dfc6 --- /dev/null +++ b/build.sh @@ -0,0 +1 @@ +docker build -t rvmt . \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..f2a150f --- /dev/null +++ b/run.sh @@ -0,0 +1 @@ +docker run -v $(pwd)/out/:/app/assets -it rvmt \ No newline at end of file diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 66c96f1..e5a5dbf 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -1,4 +1,4 @@ -from playwright.sync_api import sync_playwright +from playwright.sync_api import sync_playwright, ViewportSize from pathlib import Path from rich.progress import track from utils.console import print_step, print_substep @@ -24,7 +24,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num): # Get the thread screenshot page = browser.new_page() page.goto(reddit_object["thread_url"]) - + page.set_viewport_size(ViewportSize(width=1920, height=1080)) if page.locator('[data-testid="content-gate"]').is_visible(): # This means the post is NSFW and requires to click the proceed button. @@ -50,4 +50,5 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num): page.locator(f"#t1_{comment['comment_id']}").screenshot( path=f"assets/png/comment_{idx}.png" ) - print_substep("Screenshots downloaded Successfully.", style="bold green") + print_substep("Screenshots downloaded Successfully.", + style="bold green") From 49de46dd539c1d75f77691fa348b0c85cf66862c Mon Sep 17 00:00:00 2001 From: andronedev <31452517+andronedev@users.noreply.github.com> Date: Thu, 2 Jun 2022 22:14:17 +0200 Subject: [PATCH 04/10] Update Dockerfile --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9d7f280..1f68ea0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ WORKDIR /app RUN pip install -r requirements.txt # tricks for pytube : https://github.com/elebumm/RedditVideoMakerBot/issues/142 -RUN sed -i 's/re.compile(r"^\\w+\\W")/re.compile(r"^\\$*\\w+\\W")/' /usr/local/lib/python3.8/dist-packages/pytube/cipher.py +# (NOTE : This is no longer useful since pytube was removed from the dependencies) +# RUN sed -i 's/re.compile(r"^\\w+\\W")/re.compile(r"^\\$*\\w+\\W")/' /usr/local/lib/python3.8/dist-packages/pytube/cipher.py -CMD ["python3", "main.py"] \ No newline at end of file +CMD ["python3", "main.py"] From 030c7706c69905952fbc0e382a312c35e2c85f41 Mon Sep 17 00:00:00 2001 From: andronedev Date: Thu, 2 Jun 2022 22:56:32 +0200 Subject: [PATCH 05/10] =?UTF-8?q?=E2=9C=A8feature:=20possibility=20to=20us?= =?UTF-8?q?e=20an=20external=20.env=20instead=20of=20having=20to=20build?= =?UTF-8?q?=20the=20container=20for=20each=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index f2a150f..4dcb69a 100755 --- a/run.sh +++ b/run.sh @@ -1 +1 @@ -docker run -v $(pwd)/out/:/app/assets -it rvmt \ No newline at end of file +docker run -v $(pwd)/out/:/app/assets -v $(pwd)/.env:/app/.env -it rvmt \ No newline at end of file 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 06/10] 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 07/10] 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) From e8aca757a742b8cd0a1b62d1ad92ada686390fe4 Mon Sep 17 00:00:00 2001 From: Luka Hietala <95122845+LukaHietala@users.noreply.github.com> Date: Fri, 3 Jun 2022 20:36:25 +0300 Subject: [PATCH 08/10] Added link to documentation Added link to the official documentation. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 1d292a8..d9b09fa 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,8 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 5. Run `python3 main.py` 6. Enjoy 😎 +If you want to see more detailed guide, refer to the official [documentation](https://immaharry.gitbook.io/reddit-automated-video-bot/) + ## Contributing & Ways to improve 📈 In its current state, this bot does exactly what it needs to do. However, lots of improvements can be made. From 338c278eaf37263643128f3cb213211e0813e285 Mon Sep 17 00:00:00 2001 From: Luka Hietala <95122845+LukaHietala@users.noreply.github.com> Date: Fri, 3 Jun 2022 20:37:23 +0300 Subject: [PATCH 09/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d9b09fa..0046364 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 5. Run `python3 main.py` 6. Enjoy 😎 -If you want to see more detailed guide, refer to the official [documentation](https://immaharry.gitbook.io/reddit-automated-video-bot/) +If you want to see more detailed guide, please refer to the official [documentation](https://immaharry.gitbook.io/reddit-automated-video-bot/). ## Contributing & Ways to improve 📈 From 9d0728624c12a00bd90282be46e627fc326bee0d Mon Sep 17 00:00:00 2001 From: Freebie <69956546+FreebieII@users.noreply.github.com> Date: Fri, 3 Jun 2022 19:41:12 +0200 Subject: [PATCH 10/10] Added a disclaimer. Documentation is not fully developed yet. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0046364..10e84e9 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 6. Enjoy 😎 If you want to see more detailed guide, please refer to the official [documentation](https://immaharry.gitbook.io/reddit-automated-video-bot/). +*The Documentation is still being developed and worked on, please be patient as we change / add new knowledge! ## Contributing & Ways to improve 📈