Merge branch 'master' into master

pull/171/head
Hayden 3 years ago committed by GitHub
commit 445d8ce9e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1 @@
Dockerfile

@ -1,11 +1,20 @@
REDDIT_CLIENT_ID="" REDDIT_CLIENT_ID=""
REDDIT_CLIENT_SECRET="" REDDIT_CLIENT_SECRET=""
REDDIT_USERNAME="" REDDIT_USERNAME=""
REDDIT_PASSWORD="" REDDIT_PASSWORD=""
# Valid options are "yes" and "no" for the variable below # Valid options are "yes" and "no"
REDDIT_2FA="" 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="" THEME=""
# Enter a subreddit, e.g. "AskReddit"
SUBREDDIT="" SUBREDDIT=""
# Range is 0 -> 1
OPACITY="0.9"

5
.gitignore vendored

@ -1,4 +1,7 @@
assets/ assets/
.env .env
reddit-bot-351418-5560ebc49cac.json reddit-bot-351418-5560ebc49cac.json
__pycache__/ __pycache__
.idea/
.DS_Store
out

@ -0,0 +1,15 @@
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
# (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"]

@ -7,6 +7,7 @@ All done WITHOUT video editing or asset compiling. Just pure ✨programming magi
Created by Lewis Menelaws & [TMRRW](https://tmrrwinc.ca) Created by Lewis Menelaws & [TMRRW](https://tmrrwinc.ca)
[<picture> [<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/6053155/170528535-e274dc0b-7972-4b27-af22-637f8c370133.png"> <source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/6053155/170528535-e274dc0b-7972-4b27-af22-637f8c370133.png">
<source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/6053155/170528582-cb6671e7-5a2f-4bd4-a048-0e6cfa54f0f7.png"> <source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/6053155/170528582-cb6671e7-5a2f-4bd4-a048-0e6cfa54f0f7.png">
<img src="https://user-images.githubusercontent.com/6053155/170528582-cb6671e7-5a2f-4bd4-a048-0e6cfa54f0f7.png" width="350"> <img src="https://user-images.githubusercontent.com/6053155/170528582-cb6671e7-5a2f-4bd4-a048-0e6cfa54f0f7.png" width="350">
@ -20,13 +21,13 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p
## Disclaimers 🚨 ## Disclaimers 🚨
- This is purely for fun purposes. - 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. - **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 ## Requirements
- Python 3.6+ - Python 3.6+
- Playwright (this should install automatically during installation) - Playwright (this should install automatically during installation)
## Installation 👩‍💻 ## Installation 👩‍💻
@ -37,8 +38,8 @@ 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 📈
@ -46,8 +47,8 @@ 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! 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.
- [x] Allowing users to choose a background that is picked instead of the Minecraft one. - [x] Allowing users to choose a background that is picked instead of the Minecraft one.
- [x] Allowing users to choose between any subreddit. - [x] Allowing users to choose between any subreddit.
- [ ] Allowing users to change voice. - [ ] Allowing users to change voice.
- [ ] Creating better documentation and adding a command line interface. - [ ] Creating better documentation and adding a command line interface.

@ -0,0 +1 @@
docker build -t rvmt .

@ -1,13 +1,13 @@
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
from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts
from video_creation.final_video import make_final_video from video_creation.final_video import make_final_video
from dotenv import load_dotenv from dotenv import load_dotenv
import os import os, time, shutil
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 GitHub!](https://lewismenelaws.com) If you have any questions, feel free to reach out to me on Twitter or submit a GitHub issue." "### 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,15 +15,32 @@ print_markdown(
time.sleep(3) time.sleep(3)
load_dotenv()
reddit_object = get_subreddit_threads() configured = True
load_dotenv() if not os.path.exists(".env"):
length, number_of_comments = save_text_to_mp3(reddit_object) shutil.copy(".env.template", ".env")
download_screenshots_of_reddit_posts(reddit_object, number_of_comments, os.getenv("THEME")) configured = False
while True:
vidpath = download_background(length) for val in REQUIRED_VALUES:
noerror = chop_background_video(length, vidpath) if val not in os.environ or not os.getenv(val):
if noerror is True: print(f"Please set the variable \"{val}\" in your .env file.")
break configured = False
final_video = make_final_video(number_of_comments)
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)
download_screenshots_of_reddit_posts(reddit_object, number_of_comments, os.getenv("THEME"))
while True:
vidpath = download_background(length)
noerror = chop_background_video(length, vidpath)
if noerror is True:
break
final_video = make_final_video(number_of_comments)

@ -1,21 +1,17 @@
from utils.console import print_markdown, print_step, print_substep from utils.console import print_markdown, print_step, print_substep
import praw
import random
from dotenv import load_dotenv from dotenv import load_dotenv
import os import os, random, praw, re
def get_subreddit_threads(): def get_subreddit_threads():
global submission
""" """
Returns a list of threads from the provided subreddit. Returns a list of threads from the provided subreddit.
""" """
load_dotenv() load_dotenv()
print_step("Getting subreddit threads...") if os.getenv("REDDIT_2FA", default="no").casefold() == "yes":
if os.getenv("REDDIT_2FA").lower() == "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"
) )
@ -35,36 +31,49 @@ def get_subreddit_threads():
username=os.getenv("REDDIT_USERNAME"), username=os.getenv("REDDIT_USERNAME"),
password=passkey, password=passkey,
) )
# 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 os.getenv("SUBREDDIT"): if not os.getenv("RANDOM_THREAD") or os.getenv("RANDOM_THREAD") == "no":
subreddit = reddit.subreddit(os.getenv("SUBREDDIT")) 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: else:
# ! Prompt the user to enter a subreddit # Otherwise, picks a random thread from the inserted subreddit
try: if os.getenv("SUBREDDIT"):
subreddit = reddit.subreddit( subreddit = reddit.subreddit(re.sub(r"r\/", "", os.getenv("SUBREDDIT")))
input("What subreddit would you like to pull from? ") else:
) # ! Prompt the user to enter a subreddit
except ValueError: try:
subreddit = reddit.subreddit("askreddit") subreddit = reddit.subreddit(
print_substep("Subreddit not defined. Using AskReddit.") 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}") print_substep(f"Video will be: {submission.title}")
try:
try:
content["thread_url"] = submission.url content["thread_url"] = submission.url
content["thread_title"] = submission.title content["thread_title"] = submission.title
content["comments"] = [] content["comments"] = []
for top_level_comment in submission.comments: for top_level_comment in submission.comments:
content["comments"].append( if not top_level_comment.stickied:
{ content["comments"].append(
"comment_body": top_level_comment.body, {
"comment_url": top_level_comment.permalink, "comment_body": top_level_comment.body,
"comment_id": top_level_comment.id, "comment_url": top_level_comment.permalink,
} "comment_id": top_level_comment.id,
) }
)
except AttributeError as e: except AttributeError as e:
pass pass

@ -0,0 +1 @@
docker run -v $(pwd)/out/:/app/assets -v $(pwd)/.env:/app/.env -it rvmt

@ -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)
@ -24,6 +34,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 = [] audio_clips = []
for i in range(0, number_of_clips): for i in range(0, number_of_clips):
@ -39,23 +50,23 @@ 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(
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

@ -1,4 +1,4 @@
from playwright.sync_api import sync_playwright from playwright.sync_api import sync_playwright, ViewportSize
from pathlib import Path from pathlib import Path
from rich.progress import track from rich.progress import track
from utils.console import print_step, print_substep from utils.console import print_step, print_substep
@ -34,7 +34,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme):
# Get the thread screenshot # Get the thread screenshot
page = context.new_page() page = context.new_page()
page.goto(reddit_object["thread_url"]) page.goto(reddit_object["thread_url"])
page.set_viewport_size(ViewportSize(width=1920, height=1080))
if page.locator('[data-testid="content-gate"]').is_visible(): if page.locator('[data-testid="content-gate"]').is_visible():
# This means the post is NSFW and requires to click the proceed button. # This means the post is NSFW and requires to click the proceed button.
@ -60,4 +60,6 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme):
page.locator(f"#t1_{comment['comment_id']}").screenshot( page.locator(f"#t1_{comment['comment_id']}").screenshot(
path=f"assets/png/comment_{idx}.png" path=f"assets/png/comment_{idx}.png"
) )
print_substep("Screenshots downloaded successfully.", style="bold green")
print_substep("Screenshots downloaded Successfully.",
style="bold green")

Loading…
Cancel
Save