solve conflicts '718b005d07c31f8c560c10f213036543af9331be' into refactor/organize-functions

pull/283/head
orenkaizer 3 years ago
commit 140391af6a

@ -2,10 +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="" 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,11 +1,9 @@
import os import os, time,shutil
from sys import platform from sys import platform
if platform == "darwin": if platform == "darwin":
# Check if running on MacOs, needs to add that ffmpeg.exe path # Check if running on MacOs, needs to add that ffmpeg.exe path
os.environ["IMAGEIO_FFMPEG_EXE"] = "YOUR_PATH_TO_FFPEG.EXE" os.environ["IMAGEIO_FFMPEG_EXE"] = "YOUR_PATH_TO_FFPEG.EXE"
from utils.console import print_markdown from utils.console import print_markdown
import time
from reddit.subreddit import get_subreddit_threads from reddit.subreddit import get_subreddit_threads
from video_creation.background import download_background, chop_background_video from video_creation.background import download_background, chop_background_video
from video_creation.voices import save_text_to_mp3 from video_creation.voices import save_text_to_mp3
@ -16,6 +14,9 @@ from dotenv import load_dotenv
load_dotenv() load_dotenv()
REQUIRED_VALUES = ["REDDIT_CLIENT_ID","REDDIT_CLIENT_SECRET","REDDIT_USERNAME","REDDIT_PASSWORD", "OPACITY"]
def startup_config(): def startup_config():
print_markdown( print_markdown(
@ -23,17 +24,39 @@ def startup_config():
) )
time.sleep(3) time.sleep(3)
def is_valid_configuration():
is_valid = True
if not os.path.exists(".env"):
shutil.copy(".env.template", ".env")
is_valid = 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.")
is_valid = False
try:
float(os.getenv("OPACITY"))
except:
print(f"Please ensure that OPACITY is set between 0 and 1 in your .env file")
is_valid = False
return is_valid
def main(): def main():
startup_config() startup_config()
if is_valid_configuration():
reddit_object = get_subreddit_threads() reddit_object = get_subreddit_threads()
length, number_of_comments = save_text_to_mp3(reddit_object) 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"))
download_background() download_background()
chop_background_video(length) chop_background_video(length)
make_final_video(number_of_comments) make_final_video(number_of_comments)
main() main()

@ -2,11 +2,10 @@ from utils.console import print_markdown, print_step, print_substep
from praw import Reddit from praw import Reddit
import random import random
from dotenv import load_dotenv from dotenv import load_dotenv
import os import os, random, re
def get_subreddit_threads(): def get_subreddit_threads():
global submission
""" """
Returns a list of threads from the AskReddit subreddit. Returns a list of threads from the AskReddit subreddit.
""" """
@ -23,6 +22,7 @@ def get_subreddit_threads():
subreddit = choose_subreddit(reddit) subreddit = choose_subreddit(reddit)
threads = subreddit.hot(limit=25) threads = subreddit.hot(limit=25)
submission = list(threads)[random.randrange(0, 25)] submission = list(threads)[random.randrange(0, 25)]
print_substep(f"Video will be: {submission.title} :thumbsup:") print_substep(f"Video will be: {submission.title} :thumbsup:")
@ -36,7 +36,8 @@ def get_subreddit_threads():
return content return content
def handle_2FA(): def handle_2FA():
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"
) )
@ -51,13 +52,13 @@ def handle_2FA():
def choose_subreddit(reddit): def choose_subreddit(reddit):
if os.getenv("SUBREDDIT"): if os.getenv("SUBREDDIT"):
subreddit = reddit.subreddit(os.getenv("SUBREDDIT")) subreddit = reddit.subreddit(re.sub(r"r\/", "", os.getenv("SUBREDDIT")))
else: else:
# ! Prompt the user to enter a subreddit # ! Prompt the user to enter a subreddit
try: try:
subreddit_name = input("What subreddit would you like to pull from? ") subreddit_name = input("What subreddit would you like to pull from? ")
subreddit = reddit.subreddit( subreddit = reddit.subreddit(
subreddit_name re.sub(r"r\/", "", input("What subreddit would you like to pull from? "))
) )
except ValueError: except ValueError:
subreddit = reddit.subreddit("AskReddit") subreddit = reddit.subreddit("AskReddit")
@ -71,6 +72,7 @@ def build_content_comments(submission):
content["comments"] = [] content["comments"] = []
for top_level_comment in submission.comments: for top_level_comment in submission.comments:
if not top_level_comment.stickied:
content["comments"].append( content["comments"].append(
{ {
"comment_body": top_level_comment.body, "comment_body": top_level_comment.body,

@ -7,14 +7,24 @@ from moviepy.editor import (
CompositeAudioClip, CompositeAudioClip,
CompositeVideoClip, CompositeVideoClip,
) )
import reddit.subreddit
import re
from utils.console import print_step from utils.console import print_step
from dotenv import load_dotenv
import os
W, H = 1080, 1920 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 +35,7 @@ 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)
) )
# Gather all audio clips # Gather all audio clips
audio_clips = [AudioFileClip(f"assets/mp3/{i}.mp3") for i in range(0, number_of_clips)] audio_clips = [AudioFileClip(f"assets/mp3/{i}.mp3") for i in range(0, number_of_clips)]
audio_clips.insert(0, AudioFileClip(f"assets/mp3/title.mp3")) audio_clips.insert(0, AudioFileClip(f"assets/mp3/title.mp3"))
@ -35,23 +46,23 @@ def make_final_video(number_of_clips):
image_clips = [ImageClip(f"assets/png/comment_{i}.png") image_clips = [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) for i in range(0, number_of_clips)] .resize(width=W - 100)
.set_opacity(float(opacity)),
]
image_clips.insert( image_clips.insert(
0, 0,
ImageClip(f"assets/png/title.png") ImageClip(f"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")
) )
image_concat.audio = audio_composite image_concat.audio = audio_composite
final = CompositeVideoClip([background_clip, image_concat]) final = CompositeVideoClip([background_clip, image_concat])
final.write_videofile( filename = (re.sub('[?\"%*:|<>]', '', ("assets/" + reddit.subreddit.submission.title + ".mp4")))
"assets/final_video.mp4", fps=30, audio_codec="aac", audio_bitrate="192k" final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k")
)
for i in range(0, number_of_clips): for i in range(0, number_of_clips):
pass pass

Loading…
Cancel
Save