From 21c8da3648cb1024448f35cd6b6f51b6370d82f2 Mon Sep 17 00:00:00 2001 From: Kamushy <92086533+Kamushy@users.noreply.github.com> Date: Thu, 2 Jun 2022 21:57:32 +1000 Subject: [PATCH 01/28] Made submission global --- reddit/askreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reddit/askreddit.py b/reddit/askreddit.py index 7c7110a..21b2277 100644 --- a/reddit/askreddit.py +++ b/reddit/askreddit.py @@ -4,8 +4,8 @@ import random from dotenv import load_dotenv import os - def get_askreddit_threads(): + global submission """ Returns a list of threads from the AskReddit subreddit. """ From 9bb1aa351e222d10308ab16baacaea43575278b7 Mon Sep 17 00:00:00 2001 From: Kamushy <92086533+Kamushy@users.noreply.github.com> Date: Thu, 2 Jun 2022 22:00:24 +1000 Subject: [PATCH 02/28] made name change correctly line 59 is if any of characters cant be turned into a file remove them --- video_creation/final_video.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 947ab04..25f80f0 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -7,6 +7,8 @@ from moviepy.editor import ( CompositeAudioClip, CompositeVideoClip, ) +import reddit.askreddit +import re from utils.console import print_step @@ -14,6 +16,7 @@ W, H = 1080, 1920 def make_final_video(number_of_clips): + global submission print_step("Creating the final video 🎥") VideoFileClip.reW = lambda clip: clip.resize(width=W) VideoFileClip.reH = lambda clip: clip.resize(width=H) @@ -53,9 +56,7 @@ def make_final_video(number_of_clips): ) image_concat.audio = audio_composite final = CompositeVideoClip([background_clip, image_concat]) - final.write_videofile( - "assets/final_video.mp4", fps=30, audio_codec="aac", audio_bitrate="192k" - ) - + filename = (re.sub('[?\"/%*:|<>]', '', ("assets/" + reddit.askreddit.submission.title + ".mp4"))) + final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k") for i in range(0, number_of_clips): pass From 93bcd7be772d565be7e893f336fe5a4e3cce107d Mon Sep 17 00:00:00 2001 From: Kamushy <92086533+Kamushy@users.noreply.github.com> Date: Thu, 2 Jun 2022 22:57:02 +1000 Subject: [PATCH 03/28] file will now go to correct folder --- video_creation/final_video.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 25f80f0..f711568 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -56,7 +56,7 @@ def make_final_video(number_of_clips): ) image_concat.audio = audio_composite final = CompositeVideoClip([background_clip, image_concat]) - filename = (re.sub('[?\"/%*:|<>]', '', ("assets/" + reddit.askreddit.submission.title + ".mp4"))) + filename = (re.sub('[?\"%*:|<>]', '', ("assets/" + reddit.askreddit.submission.title + ".mp4"))) final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k") for i in range(0, number_of_clips): pass From 593094d14b075eec523382154a84f25c043237e1 Mon Sep 17 00:00:00 2001 From: andronedev Date: Thu, 2 Jun 2022 21:49:38 +0200 Subject: [PATCH 04/28] 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 05/28] 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 06/28] =?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 bed5dd2ab2737735ff24fb9b9523382c2429e40b Mon Sep 17 00:00:00 2001 From: Kamushy <92086533+Kamushy@users.noreply.github.com> Date: Fri, 3 Jun 2022 09:18:05 +1000 Subject: [PATCH 07/28] Made ENV make more sense A couple were submitting links into the subreddit field --- .env.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.template b/.env.template index f00c2ac..033c9d9 100644 --- a/.env.template +++ b/.env.template @@ -6,5 +6,5 @@ REDDIT_PASSWORD="" # Valid options are "yes" and "no" for the variable below REDDIT_2FA="" - +# Enter a subreddit, e.g. "AskReddit" or "r/AskReddit" SUBREDDIT="" From 757768be151e250390e4ff78dcfa82897f5fe6be Mon Sep 17 00:00:00 2001 From: Kamushy <92086533+Kamushy@users.noreply.github.com> Date: Fri, 3 Jun 2022 11:50:54 +1000 Subject: [PATCH 08/28] Making it work with newer code version --- reddit/askreddit.py | 1 - 1 file changed, 1 deletion(-) diff --git a/reddit/askreddit.py b/reddit/askreddit.py index 21b2277..78ec481 100644 --- a/reddit/askreddit.py +++ b/reddit/askreddit.py @@ -5,7 +5,6 @@ from dotenv import load_dotenv import os def get_askreddit_threads(): - global submission """ Returns a list of threads from the AskReddit subreddit. """ From 8546deac7d93cdda847e5941523320161533d645 Mon Sep 17 00:00:00 2001 From: Kamushy Date: Fri, 3 Jun 2022 11:59:36 +1000 Subject: [PATCH 09/28] Added it back Have no idea how do this --- reddit/askreddit.py | 1 + 1 file changed, 1 insertion(+) diff --git a/reddit/askreddit.py b/reddit/askreddit.py index 78ec481..21b2277 100644 --- a/reddit/askreddit.py +++ b/reddit/askreddit.py @@ -5,6 +5,7 @@ from dotenv import load_dotenv import os def get_askreddit_threads(): + global submission """ Returns a list of threads from the AskReddit subreddit. """ From ccd0c60d874a97c0f0d0a092c8412c38e33967b7 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 00:31:56 +0100 Subject: [PATCH 10/28] Add default values for environment variables This should reduce errors by some values not being set in the .env file - namely 2FA and Theme --- main.py | 2 +- reddit/subreddit.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 8cc3c9a..57256df 100644 --- a/main.py +++ b/main.py @@ -20,7 +20,7 @@ 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, os.getenv("THEME")) +download_screenshots_of_reddit_posts(reddit_object, number_of_comments, os.getenv("THEME", "light")) download_background() chop_background_video(length) final_video = make_final_video(number_of_comments) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 5d020fe..c7714ce 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -15,7 +15,7 @@ def get_subreddit_threads(): print_step("Getting AskReddit threads...") - if os.getenv("REDDIT_2FA").lower() == "yes": + if os.getenv("REDDIT_2FA", default="no").lower() == "yes": print( "\nEnter your two-factor authentication code from your authenticator app.\n" ) From f05eff4f88402b53c1dc919c6e793dea628c3da3 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 01:30:10 +0100 Subject: [PATCH 11/28] Alert user if their .env is not configured properly --- main.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 57256df..dff9645 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,13 @@ from utils.console import print_markdown -import time - 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 from video_creation.final_video import make_final_video from dotenv import load_dotenv -import os +import os, time + +REQUIRED_VALUES = ["REDDIT_CLIENT_ID","REDDIT_CLIENT_SECRET","REDDIT_USERNAME","REDDIT_PASSWORD"] 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,10 +15,17 @@ print_markdown( time.sleep(3) +load_dotenv() -reddit_object = get_subreddit_threads() +configured = True -load_dotenv() +for val in REQUIRED_VALUES: + if val not in os.environ or not os.getenv(val): + print(f"Please set the variable \"{val}\" in your .env file.") + configured = False + +if configured: +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, os.getenv("THEME", "light")) download_background() From 87d211281220ea529e6b48008e884a2adb7cd5f9 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 01:40:55 +0100 Subject: [PATCH 12/28] Move to casefold --- reddit/subreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index c7714ce..c64db2b 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -15,7 +15,7 @@ def get_subreddit_threads(): print_step("Getting AskReddit threads...") - if os.getenv("REDDIT_2FA", default="no").lower() == "yes": + if os.getenv("REDDIT_2FA", default="no").casefold() == "yes": print( "\nEnter your two-factor authentication code from your authenticator app.\n" ) From 3a7d91f474de5bbfdab0113b8479b0378949c943 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 01:41:48 +0100 Subject: [PATCH 13/28] Create a .env file if none exists on run Should fix issues users have with creating their own .env file, by simply copying our template to a file for them. --- main.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index dff9645..b813c01 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ 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, time +import os, time, shutil REQUIRED_VALUES = ["REDDIT_CLIENT_ID","REDDIT_CLIENT_SECRET","REDDIT_USERNAME","REDDIT_PASSWORD"] @@ -19,15 +19,19 @@ load_dotenv() configured = True +if not os.path.exists(".env"): + shutil.copy(".env.template", ".env") + configured = False + for val in REQUIRED_VALUES: if val not in os.environ or not os.getenv(val): print(f"Please set the variable \"{val}\" in your .env file.") configured = False if configured: -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, os.getenv("THEME", "light")) -download_background() -chop_background_video(length) -final_video = make_final_video(number_of_comments) + 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, os.getenv("THEME", "light")) + download_background() + chop_background_video(length) + final_video = make_final_video(number_of_comments) From d39386178b254f7bb86837c728fec20cb1dd52de Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 01:53:34 +0100 Subject: [PATCH 14/28] Clean up imports --- reddit/subreddit.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 5d020fe..95d26e7 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -1,8 +1,6 @@ from utils.console import print_markdown, print_step, print_substep -import praw -import random from dotenv import load_dotenv -import os +import os, random, praw, re def get_subreddit_threads(): From cd5924562f021fcd95c8313cf9b8ee5cfc01185c Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 01:57:09 +0100 Subject: [PATCH 15/28] Ignore r/ in subreddit names --- reddit/subreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 95d26e7..e1be0c3 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -40,7 +40,7 @@ def get_subreddit_threads(): # ! Prompt the user to enter a subreddit try: subreddit = reddit.subreddit( - input("What subreddit would you like to pull from? ") + re.sub(r"r\/", "", input("What subreddit would you like to pull from? ")) ) except ValueError: subreddit = reddit.subreddit("askreddit") From 37f22b8b018dd85d3b8db1b4fa9df282a55133cc Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 02:00:19 +0100 Subject: [PATCH 16/28] Ignore r/ in environment subreddit names --- reddit/subreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index e1be0c3..32bcba3 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -35,7 +35,7 @@ def get_subreddit_threads(): ) if os.getenv("SUBREDDIT"): - subreddit = reddit.subreddit(os.getenv("SUBREDDIT")) + subreddit = reddit.subreddit(re.sub(r"r\/", "", os.getenv("SUBREDDIT"))) else: # ! Prompt the user to enter a subreddit try: From d3b288008fbe1f67f9fcddcbf17783493f339ddf Mon Sep 17 00:00:00 2001 From: Kamushy <92086533+Kamushy@users.noreply.github.com> Date: Sat, 4 Jun 2022 11:03:13 +1000 Subject: [PATCH 17/28] Changed function name to match new version --- reddit/subreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 09f4477..1f49152 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -4,7 +4,7 @@ import random from dotenv import load_dotenv import os -def get_askreddit_threads(): +def get_subreddit_threads(): global submission """ Returns a list of threads from the AskReddit subreddit. From 367105fb2dd33cdbf1ae6730036509d82e00531e Mon Sep 17 00:00:00 2001 From: Kamushy <92086533+Kamushy@users.noreply.github.com> Date: Sat, 4 Jun 2022 11:04:30 +1000 Subject: [PATCH 18/28] Changed file import name and resolved conflicts --- video_creation/final_video.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index ba169f0..366f61d 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -7,7 +7,7 @@ from moviepy.editor import ( CompositeAudioClip, CompositeVideoClip, ) -import reddit.askreddit +import reddit.subreddit import re from utils.console import print_step @@ -58,7 +58,7 @@ def make_final_video(number_of_clips): ) image_concat.audio = audio_composite final = CompositeVideoClip([background_clip, image_concat]) - filename = (re.sub('[?\"%*:|<>]', '', ("assets/" + reddit.askreddit.submission.title + ".mp4"))) + filename = (re.sub('[?\"%*:|<>]', '', ("assets/" + reddit.subreddit.submission.title + ".mp4"))) final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k") for i in range(0, number_of_clips): pass From 03f96e7a89780fb3ec8d8df16ff9653fa6cfed79 Mon Sep 17 00:00:00 2001 From: Luka Hietala <95122845+LukaHietala@users.noreply.github.com> Date: Sat, 4 Jun 2022 14:48:13 +0300 Subject: [PATCH 19/28] Fixed link to documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 10e84e9..dbb0250 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, please 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://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/). *The Documentation is still being developed and worked on, please be patient as we change / add new knowledge! ## Contributing & Ways to improve 📈 From 5f2070d34497d6e2bfa5716f4dffdf53a96c3fe8 Mon Sep 17 00:00:00 2001 From: jacesleeman <46321222+jacesleeman@users.noreply.github.com> Date: Sat, 4 Jun 2022 09:04:43 -0400 Subject: [PATCH 20/28] Added opacity setting to the screen shots --- .env.template | 3 +++ video_creation/final_video.py | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.env.template b/.env.template index 5ab4ae4..43cb7d9 100644 --- a/.env.template +++ b/.env.template @@ -9,3 +9,6 @@ REDDIT_2FA="" THEME="" SUBREDDIT="" + +# Range is 0 -> 1 +OPACITY="" diff --git a/video_creation/final_video.py b/video_creation/final_video.py index e1f71ff..9db757e 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -8,12 +8,18 @@ from moviepy.editor import ( CompositeVideoClip, ) from utils.console import print_step - +from dotenv import load_dotenv +import os W, H = 1080, 1920 + def make_final_video(number_of_clips): + # Calls opacity from the .env + load_dotenv() + opacity = os.getenv('OPACITY') + print_step("Creating the final video...") VideoFileClip.reW = lambda clip: clip.resize(width=W) VideoFileClip.reH = lambda clip: clip.resize(width=H) @@ -39,14 +45,16 @@ def make_final_video(number_of_clips): ImageClip(f"assets/png/comment_{i}.png") .set_duration(audio_clips[i + 1].duration) .set_position("center") - .resize(width=W - 100), + .resize(width=W - 100) + .set_opacity(float(opacity)), ) image_clips.insert( 0, ImageClip(f"assets/png/title.png") .set_duration(audio_clips[0].duration) .set_position("center") - .resize(width=W - 100), + .resize(width=W - 100) + .set_opacity(float(opacity)), ) image_concat = concatenate_videoclips(image_clips).set_position( ("center", "center") From 84c8eb25ce3a8735dfb9486330647006e4891a5f Mon Sep 17 00:00:00 2001 From: jacesleeman <46321222+jacesleeman@users.noreply.github.com> Date: Sat, 4 Jun 2022 10:02:01 -0400 Subject: [PATCH 21/28] updated .env to explain better --- .env.template | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.env.template b/.env.template index 43cb7d9..5115d89 100644 --- a/.env.template +++ b/.env.template @@ -3,12 +3,13 @@ REDDIT_CLIENT_SECRET="" REDDIT_USERNAME="" REDDIT_PASSWORD="" -# Valid options are "yes" and "no" for the variable below +SUBREDDIT="" + +# Valid options are "yes" and "no" REDDIT_2FA="" +# Valid options are "light "dark" THEME="" -SUBREDDIT="" - # Range is 0 -> 1 OPACITY="" From 102f791684caddfdd3bb7de1b63c3391790e565b Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 15:43:21 +0100 Subject: [PATCH 22/28] Update .env.template --- .env.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.template b/.env.template index 5115d89..58f3fd3 100644 --- a/.env.template +++ b/.env.template @@ -8,8 +8,8 @@ SUBREDDIT="" # Valid options are "yes" and "no" REDDIT_2FA="" -# Valid options are "light "dark" +# Valid options are "light" and "dark" THEME="" # Range is 0 -> 1 -OPACITY="" +OPACITY="0.9" From fe92918823c0dbfc1dd03d7b675b0bfcb94b15b5 Mon Sep 17 00:00:00 2001 From: jacesleeman <46321222+jacesleeman@users.noreply.github.com> Date: Sat, 4 Jun 2022 10:59:07 -0400 Subject: [PATCH 23/28] updated --- .env.template | 2 +- main.py | 2 ++ video_creation/final_video.py | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.env.template b/.env.template index 43cb7d9..d90bac7 100644 --- a/.env.template +++ b/.env.template @@ -11,4 +11,4 @@ THEME="" SUBREDDIT="" # Range is 0 -> 1 -OPACITY="" +OPACITY=".9" diff --git a/main.py b/main.py index 8cc3c9a..b0a4c28 100644 --- a/main.py +++ b/main.py @@ -9,6 +9,8 @@ from video_creation.final_video import make_final_video from dotenv import load_dotenv import os +REQUIRED_VALUES = ["REDDIT_CLIENT_ID","REDDIT_CLIENT_SECRET","REDDIT_USERNAME","REDDIT_PASSWORD", "OPACITY"] + 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." ) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 9db757e..0a2afb0 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -30,6 +30,11 @@ def make_final_video(number_of_clips): .resize(height=H) .crop(x1=1166.6, y1=0, x2=2246.6, y2=1920) ) + try: + float(os.getenv("OPACITY")) + except: + print(f"Please ensure that OPACITY is set between 0 and 1 in your .env file") + configured = False # Gather all audio clips audio_clips = [] for i in range(0, number_of_clips): From c318e4e0425f288a7189ea9ec6e2f2361367a973 Mon Sep 17 00:00:00 2001 From: jacesleeman <46321222+jacesleeman@users.noreply.github.com> Date: Sat, 4 Jun 2022 11:06:52 -0400 Subject: [PATCH 24/28] default OPACITY --- .env.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.template b/.env.template index a7f6dd3..3fc5e13 100644 --- a/.env.template +++ b/.env.template @@ -12,4 +12,4 @@ THEME="" SUBREDDIT="" # Range is 0 -> 1 -OPACITY="" \ No newline at end of file +OPACITY=".9" From b9ffdd186d1638da22d9d725a320afd5e795047c Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 16:09:26 +0100 Subject: [PATCH 25/28] Added a zero to make it clearer to users --- .env.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.template b/.env.template index 3fc5e13..cab265e 100644 --- a/.env.template +++ b/.env.template @@ -12,4 +12,4 @@ THEME="" SUBREDDIT="" # Range is 0 -> 1 -OPACITY=".9" +OPACITY="0.9" From 0dc32154f2ccce46daf1d5751a9d4f5426e6c5bc Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 16:16:02 +0100 Subject: [PATCH 26/28] Code was placed in the wrong place --- main.py | 6 ++++++ video_creation/final_video.py | 6 +----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index fc12206..3bc6c83 100644 --- a/main.py +++ b/main.py @@ -30,6 +30,12 @@ for val in REQUIRED_VALUES: print(f"Please set the variable \"{val}\" in your .env file.") configured = False +try: + float(os.getenv("OPACITY")) +except: + print(f"Please ensure that OPACITY is set between 0 and 1 in your .env file") + configured = False + if configured: reddit_object = get_subreddit_threads() length, number_of_comments = save_text_to_mp3(reddit_object) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 0a2afb0..1933db3 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -30,11 +30,7 @@ def make_final_video(number_of_clips): .resize(height=H) .crop(x1=1166.6, y1=0, x2=2246.6, y2=1920) ) - try: - float(os.getenv("OPACITY")) - except: - print(f"Please ensure that OPACITY is set between 0 and 1 in your .env file") - configured = False + # Gather all audio clips audio_clips = [] for i in range(0, number_of_clips): From 48688f18c642177cda0a9eb421ce0c3c126c0f42 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 16:19:58 +0100 Subject: [PATCH 27/28] Remove code duplication --- main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/main.py b/main.py index 3bc6c83..1b66e8c 100644 --- a/main.py +++ b/main.py @@ -7,8 +7,6 @@ from video_creation.final_video import make_final_video from dotenv import load_dotenv import os, time, shutil -REQUIRED_VALUES = ["REDDIT_CLIENT_ID","REDDIT_CLIENT_SECRET","REDDIT_USERNAME","REDDIT_PASSWORD"] - REQUIRED_VALUES = ["REDDIT_CLIENT_ID","REDDIT_CLIENT_SECRET","REDDIT_USERNAME","REDDIT_PASSWORD", "OPACITY"] print_markdown( From 211b03e7f5cc4e8c92778f50d80cf9e82f83790c Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Sun, 5 Jun 2022 00:31:59 +0200 Subject: [PATCH 28/28] stickied comments will no longer be used I made a video but it was taken up entirely by a post looking like this: https://imgur.com/a/1fwT94c This isn't a big deal because these serious tags are uncommon, but still a small annoyance. So I fixed it! In threads that are marked 'serious', there is an automatic stickied mod post. ex. (shorturl.at/I1346). My changes will skip any automatically stickied comments, so they won't make it into the final Video. --- reddit/subreddit.py | 1 + 1 file changed, 1 insertion(+) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 1d47974..063b862 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -56,6 +56,7 @@ def get_subreddit_threads(): content["comments"] = [] for top_level_comment in submission.comments: + if not top_level_comment.stickied: content["comments"].append( { "comment_body": top_level_comment.body,