synched with changes from wherever patch

pull/280/head
iaacornus 3 years ago
commit d33e516b39
No known key found for this signature in database
GPG Key ID: 281739AE7252598C

@ -2,8 +2,14 @@ REDDIT_CLIENT_ID=""
REDDIT_CLIENT_SECRET="" REDDIT_CLIENT_SECRET=""
REDDIT_USERNAME="" REDDIT_USERNAME=""
REDDIT_PASSWORD="" REDDIT_PASSWORD=""
# Valid options are "yes" and "no"
# Valid options are "yes" and "no" for the variable below
REDDIT_2FA="" REDDIT_2FA=""
# Valid options are "light" and "dark"
THEME="" THEME=""
# Enter a subreddit, e.g. "AskReddit"
SUBREDDIT=""
# Range is 0 -> 1
OPACITY="0.9"

@ -37,7 +37,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p
5. Run `python3 main.py` 5. Run `python3 main.py`
6. Enjoy 😎 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! *The Documentation is still being developed and worked on, please be patient as we change / add new knowledge!
## Contributing & Ways to improve 📈 ## Contributing & Ways to improve 📈

@ -1,5 +1,5 @@
import os import os
import time import shutil
from dotenv import load_dotenv from dotenv import load_dotenv
@ -12,19 +12,35 @@ from utils.console import print_markdown
def main(subreddit_=None, background=None): def main(subreddit_=None, background=None):
REQUIRED_VALUES = [
"REDDIT_CLIENT_ID",
"REDDIT_CLIENT_SECRET",
"REDDIT_USERNAME",
"REDDIT_PASSWORD",
"OPACITY"
]
print_markdown( print_markdown(
"### Thanks for using this tool! [Feel free to contribute to this project on " "### 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" + "GitHub!](https://lewismenelaws.com) If you have any questions, feel free to"
+ "reach out to me on Twitter or submit a GitHub issue." + "reach out to me on Twitter or submit a GitHub issue."
) )
time.sleep(3) if not os.path.exists(".env"):
shutil.copy(".env.template", ".env")
reddit_object = get_subreddit_threads(subreddit_) configured = False
load_dotenv() 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")) for val in REQUIRED_VALUES:
download_background(background) if not os.getenv(val):
chop_background_video(length) print(f"Please set the variable \"{val}\" in your .env file.")
final_video = make_final_video(number_of_comments) configured = False
if configured:
reddit_object = get_subreddit_threads(subreddit_)
length, number_of_comments = save_text_to_mp3(reddit_object)
download_screenshots_of_reddit_posts(reddit_object, number_of_comments, os.getenv("THEME"))
download_background(background)
chop_background_video(length)
final_video = make_final_video(number_of_comments)

@ -1,5 +1,6 @@
import random import random
import os import os
import re
import praw import praw
from dotenv import load_dotenv from dotenv import load_dotenv
@ -20,7 +21,7 @@ def get_subreddit_threads(subreddit_):
print_step("Getting AskReddit threads...") print_step("Getting AskReddit threads...")
if os.getenv("REDDIT_2FA").lower() == "yes": if os.getenv("REDDIT_2FA", default="no").casefold() == "yes":
print( print(
"\nEnter your two-factor authentication code from your authenticator app.\n" "\nEnter your two-factor authentication code from your authenticator app.\n"
) )
@ -45,7 +46,11 @@ def get_subreddit_threads(subreddit_):
subreddit = reddit.subreddit(subreddit_) subreddit = reddit.subreddit(subreddit_)
except ValueError: except ValueError:
subreddit = reddit.subreddit("askreddit") if os.getenv("SUBREDDIT"):
subreddit = reddit.subreddit(re.sub(r"r\/", "", os.getenv("SUBREDDIT")))
else:
subreddit = reddit.subreddit("askreddit")
print_substep("Subreddit not defined. Using AskReddit.") print_substep("Subreddit not defined. Using AskReddit.")
threads = subreddit.hot(limit=25) threads = subreddit.hot(limit=25)

@ -1,3 +1,6 @@
import os
from dotenv import load_dotenv
from moviepy.editor import ( from moviepy.editor import (
VideoFileClip, VideoFileClip,
AudioFileClip, AudioFileClip,
@ -15,6 +18,10 @@ W, H = 1080, 1920
def make_final_video(number_of_clips): def make_final_video(number_of_clips):
# Calls opacity from the .env
load_dotenv()
opacity = os.getenv("OPACITY")
print_step("Creating the final video...") print_step("Creating the final video...")
VideoFileClip.reW = lambda clip: clip.resize(width=W) VideoFileClip.reW = lambda clip: clip.resize(width=W)
VideoFileClip.reH = lambda clip: clip.resize(width=H) VideoFileClip.reH = lambda clip: clip.resize(width=H)
@ -25,6 +32,12 @@ def make_final_video(number_of_clips):
.resize(height=H) .resize(height=H)
.crop(x1=1166.6, y1=0, x2=2246.6, y2=1920) .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 # Gather all audio clips
audio_clips = [] audio_clips = []
for i in range(0, number_of_clips): for i in range(0, number_of_clips):
@ -41,7 +54,8 @@ def make_final_video(number_of_clips):
ImageClip(f"assets/png/comment_{i}.png") ImageClip(f"assets/png/comment_{i}.png")
.set_duration(audio_clips[i + 1].duration) .set_duration(audio_clips[i + 1].duration)
.set_position("center") .set_position("center")
.resize(width=W - 100), .resize(width=W - 100)
.set_opacity(float(opacity)),
) )
image_clips.insert( image_clips.insert(
@ -49,7 +63,8 @@ def make_final_video(number_of_clips):
ImageClip("assets/png/title.png") ImageClip("assets/png/title.png")
.set_duration(audio_clips[0].duration) .set_duration(audio_clips[0].duration)
.set_position("center") .set_position("center")
.resize(width=W - 100), .resize(width=W - 100)
.set_opacity(float(opacity)),
) )
image_concat = concatenate_videoclips(image_clips).set_position( image_concat = concatenate_videoclips(image_clips).set_position(
("center", "center") ("center", "center")

@ -25,7 +25,8 @@ def save_text_to_mp3(reddit_obj):
length += MP3("assets/mp3/title.mp3").info.length length += MP3("assets/mp3/title.mp3").info.length
for idx, comment in track(enumerate(reddit_obj["comments"]), "Saving..."): for idx, comment in track(enumerate(reddit_obj["comments"]), "Saving..."):
# ! Stop creating mp3 files if the length is greater than 50 seconds. This can be longer, but this is just a good starting point # ! Stop creating mp3 files if the length is greater than 50 seconds.
# ! This can be longer, but this is just a good starting point
if length > 50: if length > 50:
break break
tts = gTTS(text=comment["comment_body"], lang="en", slow=False) tts = gTTS(text=comment["comment_body"], lang="en", slow=False)

Loading…
Cancel
Save