Merge branch 'master' into community-health-files
This commit is contained in:
6 files changed
+62
-43
No files matched your search
@@ -1,10 +1,15 @@
|
||||
REDDIT_CLIENT_ID=""
|
||||
REDDIT_CLIENT_SECRET=""
|
||||
|
||||
REDDIT_USERNAME=""
|
||||
REDDIT_PASSWORD=""
|
||||
|
||||
# Valid options are "yes" and "no"
|
||||
REDDIT_2FA=""
|
||||
|
||||
#If no, it will ask you a thread link to extract the thread, if yes it will randomize it.
|
||||
RANDOM_THREAD="no"
|
||||
|
||||
# Valid options are "light" and "dark"
|
||||
THEME=""
|
||||
|
||||
|
||||
+3
-1
@@ -2,4 +2,6 @@ assets/
|
||||
.env
|
||||
reddit-bot-351418-5560ebc49cac.json
|
||||
__pycache__
|
||||
out
|
||||
.idea/
|
||||
.DS_Store
|
||||
out
|
||||
@@ -21,13 +21,13 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p
|
||||
|
||||
## Disclaimers 🚨
|
||||
|
||||
- This is purely for fun purposes.
|
||||
- **At the moment**, this repository won't attempt to upload this content through this bot. It will give you a file that you will then have to upload manually. This is for the sake of avoiding any sort of community guideline issues.
|
||||
- This is purely for fun purposes.
|
||||
- **At the moment**, this repository won't attempt to upload this content through this bot. It will give you a file that you will then have to upload manually. This is for the sake of avoiding any sort of community guideline issues.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Python 3.6+
|
||||
- Playwright (this should install automatically during installation)
|
||||
- Python 3.6+
|
||||
- Playwright (this should install automatically during installation)
|
||||
|
||||
## Installation 👩💻
|
||||
|
||||
@@ -47,7 +47,7 @@ In its current state, this bot does exactly what it needs to do. However, lots o
|
||||
|
||||
I have tried to simplify the code so anyone can read it and start contributing at any skill level. Don't be shy :) contribute!
|
||||
|
||||
- [ ] Allowing users to choose a reddit thread instead of being randomized.
|
||||
- [x] Allowing users to choose a reddit thread instead of being randomized.
|
||||
- [ ] Allowing users to choose a background that is picked instead of the Minecraft one.
|
||||
- [x] Allowing users to choose between any subreddit.
|
||||
- [ ] Allowing users to change voice.
|
||||
|
||||
@@ -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(
|
||||
@@ -30,6 +28,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)
|
||||
|
||||
+34
-24
@@ -4,15 +4,13 @@ import os, random, praw, re
|
||||
|
||||
|
||||
def get_subreddit_threads():
|
||||
|
||||
global submission
|
||||
"""
|
||||
Returns a list of threads from the AskReddit subreddit.
|
||||
"""
|
||||
|
||||
load_dotenv()
|
||||
|
||||
print_step("Getting AskReddit threads...")
|
||||
|
||||
if os.getenv("REDDIT_2FA", default="no").casefold() == "yes":
|
||||
print(
|
||||
"\nEnter your two-factor authentication code from your authenticator app.\n"
|
||||
@@ -33,36 +31,48 @@ def get_subreddit_threads():
|
||||
username=os.getenv("REDDIT_USERNAME"),
|
||||
password=passkey,
|
||||
)
|
||||
|
||||
if os.getenv("SUBREDDIT"):
|
||||
subreddit = reddit.subreddit(re.sub(r"r\/", "", os.getenv("SUBREDDIT")))
|
||||
# If the user specifies that he doesnt want a random thread, or if he doesn't insert the "RANDOM_THREAD" variable at all, ask the thread link
|
||||
if not os.getenv("RANDOM_THREAD") or os.getenv("RANDOM_THREAD") == "no":
|
||||
print_substep("Insert the full thread link:", style="bold green")
|
||||
thread_link = input()
|
||||
print_step(f"Getting the inserted thread...")
|
||||
submission = reddit.submission(url=thread_link)
|
||||
else:
|
||||
# ! Prompt the user to enter a subreddit
|
||||
try:
|
||||
subreddit = reddit.subreddit(
|
||||
re.sub(r"r\/", "", input("What subreddit would you like to pull from? "))
|
||||
)
|
||||
except ValueError:
|
||||
subreddit = reddit.subreddit("askreddit")
|
||||
print_substep("Subreddit not defined. Using AskReddit.")
|
||||
# Otherwise, picks a random thread from the inserted subreddit
|
||||
if os.getenv("SUBREDDIT"):
|
||||
subreddit = reddit.subreddit(re.sub(r"r\/", "", os.getenv("SUBREDDIT")))
|
||||
else:
|
||||
# ! Prompt the user to enter a subreddit
|
||||
try:
|
||||
subreddit = reddit.subreddit(
|
||||
re.sub(
|
||||
r"r\/",
|
||||
"",
|
||||
input("What subreddit would you like to pull from? "),
|
||||
)
|
||||
)
|
||||
except ValueError:
|
||||
subreddit = reddit.subreddit("askreddit")
|
||||
print_substep("Subreddit not defined. Using AskReddit.")
|
||||
|
||||
threads = subreddit.hot(limit=25)
|
||||
submission = list(threads)[random.randrange(0, 25)]
|
||||
|
||||
threads = subreddit.hot(limit=25)
|
||||
submission = list(threads)[random.randrange(0, 25)]
|
||||
print_substep(f"Video will be: {submission.title} :thumbsup:")
|
||||
try:
|
||||
|
||||
content["thread_url"] = submission.url
|
||||
content["thread_title"] = submission.title
|
||||
content["comments"] = []
|
||||
|
||||
for top_level_comment in submission.comments:
|
||||
content["comments"].append(
|
||||
{
|
||||
"comment_body": top_level_comment.body,
|
||||
"comment_url": top_level_comment.permalink,
|
||||
"comment_id": top_level_comment.id,
|
||||
}
|
||||
)
|
||||
if not top_level_comment.stickied:
|
||||
content["comments"].append(
|
||||
{
|
||||
"comment_body": top_level_comment.body,
|
||||
"comment_url": top_level_comment.permalink,
|
||||
"comment_id": top_level_comment.id,
|
||||
}
|
||||
)
|
||||
|
||||
except AttributeError as e:
|
||||
pass
|
||||
|
||||
@@ -7,6 +7,8 @@ from moviepy.editor import (
|
||||
CompositeAudioClip,
|
||||
CompositeVideoClip,
|
||||
)
|
||||
import reddit.subreddit
|
||||
import re
|
||||
from utils.console import print_step
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
@@ -16,11 +18,13 @@ W, H = 1080, 1920
|
||||
|
||||
|
||||
def make_final_video(number_of_clips):
|
||||
# Calls opacity from the .env
|
||||
|
||||
# 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)
|
||||
|
||||
@@ -30,11 +34,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):
|
||||
@@ -66,9 +66,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.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
|
||||
Reference in new issue
Block a user