Merge branch 'master' into master

pull/139/head
Callum Leslie 3 years ago committed by GitHub
commit f54d2fc282
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1 @@
Dockerfile

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

3
.gitignore vendored

@ -1,4 +1,5 @@
assets/
.env
reddit-bot-351418-5560ebc49cac.json
__pycache__
__pycache__
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"]

@ -35,8 +35,10 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p
3. Run `pip3 install -r requirements.txt`
4. Run `playwright install` and `playwright install-deps`.
5. Run `python3 main.py`
6. ...
7. Enjoy 😎
6. Enjoy 😎
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 📈

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

@ -1,11 +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, time, shutil
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."
@ -13,11 +15,29 @@ print_markdown(
time.sleep(3)
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
reddit_object = get_subreddit_threads()
try:
float(os.getenv("OPACITY"))
except:
print(f"Please ensure that OPACITY is set between 0 and 1 in your .env file")
configured = False
length, number_of_comments = save_text_to_mp3(reddit_object)
download_screenshots_of_reddit_posts(reddit_object, number_of_comments)
download_background()
chop_background_video(length)
final_video = make_final_video(number_of_comments)
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)

@ -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():
global submission
@ -14,7 +12,7 @@ def get_subreddit_threads():
print_step("Getting AskReddit threads...")
if os.getenv("REDDIT_2FA").lower() == "yes":
if os.getenv("REDDIT_2FA", default="no").casefold() == "yes":
print(
"\nEnter your two-factor authentication code from your authenticator app.\n"
)
@ -36,12 +34,12 @@ 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:
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")
@ -57,6 +55,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,

@ -1,44 +1,8 @@
appdirs==1.4.4
black==20.8b1
certifi==2021.10.8
charset-normalizer==2.0.12
click==7.1.2
commonmark==0.9.1
decorator==4.4.2
flake8==3.8.3
greenlet==1.1.2
gTTS==2.2.4
idna==3.3
imageio==2.19.2
imageio-ffmpeg==0.4.7
mccabe==0.6.1
moviepy==1.0.3
mutagen==1.45.1
mypy-extensions==0.4.3
numpy==1.22.3
pathspec==0.8.0
Pillow==9.1.1
playwright==1.22.0
praw==7.6.0
prawcore==2.3.0
proglog==0.1.10
pycodestyle==2.6.0
pyee==8.1.0
pyflakes==2.2.0
Pygments==2.12.0
python-dotenv==0.20.0
regex==2020.10.15
requests==2.27.1
rich==12.4.4
six==1.16.0
toml==0.10.1
tqdm==4.64.0
typed-ast==1.5.4
typing_extensions==4.2.0
update-checker==0.18.0
urllib3==1.26.9
websocket-client==1.3.2
websockets==10.1
yt-dlp==2022.5.18
yt_dlp==2022.5.18

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

@ -0,0 +1,8 @@
[
{
"name": "USER",
"value": "eyJwcmVmcyI6eyJ0b3BDb250ZW50RGlzbWlzc2FsVGltZSI6MCwiZ2xvYmFsVGhlbWUiOiJSRURESVQiLCJuaWdodG1vZGUiOnRydWUsImNvbGxhcHNlZFRyYXlTZWN0aW9ucyI6eyJmYXZvcml0ZXMiOmZhbHNlLCJtdWx0aXMiOmZhbHNlLCJtb2RlcmF0aW5nIjpmYWxzZSwic3Vic2NyaXB0aW9ucyI6ZmFsc2UsInByb2ZpbGVzIjpmYWxzZX0sInRvcENvbnRlbnRUaW1lc0Rpc21pc3NlZCI6MH19",
"domain": ".reddit.com",
"path": "/"
}
]

@ -10,14 +10,19 @@ from moviepy.editor import (
import reddit.subreddit
import re
from utils.console import print_step
from dotenv import load_dotenv
import os
W, H = 1080, 1920
def make_final_video(number_of_clips):
global submission
# 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)
@ -29,6 +34,7 @@ def make_final_video(number_of_clips):
.resize(height=H)
.crop(x1=1166.6, y1=0, x2=2246.6, y2=1920)
)
# Gather all audio clips
audio_clips = []
for i in range(0, number_of_clips):
@ -44,14 +50,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")

@ -1,10 +1,11 @@
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
import json
def download_screenshots_of_reddit_posts(reddit_object, screenshot_num):
def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme):
"""Downloads screenshots of reddit posts as they are seen on the web.
Args:
@ -20,11 +21,17 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num):
print_substep("Launching Headless Browser...")
browser = p.chromium.launch()
context = browser.new_context()
if theme.casefold() == "dark":
cookie_file = open('video_creation/cookies.json')
cookies = json.load(cookie_file)
context.add_cookies(cookies)
# Get the thread screenshot
page = browser.new_page()
page = context.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 +57,6 @@ 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")

Loading…
Cancel
Save