Merge branch 'master' of https://github.com/elebumm/RedditVideoMakerBot into elebumm-master

pull/125/head
BlockArchitech 3 years ago
commit 44edf4ab31
No known key found for this signature in database
GPG Key ID: B264EC928CE5983E

@ -1,4 +1,10 @@
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
REDDIT_2FA=""
SUBREDDIT=""

9
.gitignore vendored

@ -2,6 +2,13 @@ assets/
reddit/__pycache__/ reddit/__pycache__/
utils/__pycache__/ utils/__pycache__/
.env .env
<<<<<<< HEAD
reddit-bot-351418-5560ebc49cac.json reddit-bot-351418-5560ebc49cac.json
video_creation/__pycache__/ video_creation/__pycache__/
.setup-done-before .setup-done-before
||||||| 5b39896
reddit-bot-351418-5560ebc49cac.json
=======
reddit-bot-351418-5560ebc49cac.json
__pycache__
>>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9

@ -26,11 +26,12 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p
## Requirements ## Requirements
- Python 3.6+ - Python 3.6+
- Playwright (this should install automatically in installation) - Playwright (this should install automatically during installation)
## Installation 👩‍💻 ## Installation 👩‍💻
1. Clone this repository 1. Clone this repository
<<<<<<< HEAD
2. Run `pip3 install -r requirements.txt` 2. Run `pip3 install -r requirements.txt`
3. 3.
3a. **Automatic Setup**: Run `python3 main.py` and type "yes" where it says "Setup Wizard". The Setup Wizard will guide you through the setup process. 3a. **Automatic Setup**: Run `python3 main.py` and type "yes" where it says "Setup Wizard". The Setup Wizard will guide you through the setup process.
@ -39,15 +40,29 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p
4. (only if you did manual setup) Run `python3 main.py` 4. (only if you did manual setup) Run `python3 main.py`
6. Enjoy 😎 6. Enjoy 😎
||||||| 5b39896
2. Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files.
3. Run `pip3 install -r requirements.txt`
4. Run `python3 main.py`
5. ...
6. Enjoy 😎
=======
2. Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` file, along with whether your account uses two-factor authentication.
3. Run `pip3 install -r requirements.txt`
4. Run `playwright install` and `playwright install-deps`.
5. Run `python3 main.py`
6. ...
7. Enjoy 😎
>>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9
## Contributing & Ways to improve 📈 ## Contributing & Ways to improve 📈
In its current state, this bot does exactly what it needs to do. However, lots of improvements can be made. In its current state, this bot does exactly what it needs to do. However, lots of improvements can be made.
I have tried to simplify the code so anyone can read it and start contibuting 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. - [ ] 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. - [ ] Allowing users to choose a background that is picked instead of the Minecraft one.
- [ ] 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.

@ -4,8 +4,15 @@ from utils.console import print_step
from utils.console import print_substep from utils.console import print_substep
from rich.console import Console from rich.console import Console
import time import time
<<<<<<< HEAD
import os import os
from reddit.askreddit import get_askreddit_threads from reddit.askreddit import get_askreddit_threads
||||||| 5b39896
from reddit.askreddit import get_askreddit_threads
=======
from reddit.subreddit import get_subreddit_threads
>>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9
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
@ -14,7 +21,7 @@ from utils.loader import Loader
from dotenv import load_dotenv from dotenv import load_dotenv
console = Console() console = Console()
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."
) )
""" """
@ -59,7 +66,7 @@ console.log("[bold green]Enviroment Variables are set! Continuing...")
time.sleep(3) time.sleep(3)
reddit_object = get_askreddit_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) download_screenshots_of_reddit_posts(reddit_object, number_of_comments)

@ -1,49 +0,0 @@
from rich import Console
from utils.console import print_markdown, print_step, print_substep
import praw
import random
from dotenv import load_dotenv
import os
console = Console()
def get_askreddit_threads():
"""
Returns a list of threads from the AskReddit subreddit.
"""
print_step("Getting AskReddit threads...")
content = {}
load_dotenv()
console.log("Logging in to reddit...")
reddit = praw.Reddit(
client_id=os.getenv("REDDIT_CLIENT_ID"),
client_secret=os.getenv("REDDIT_CLIENT_SECRET"),
user_agent="Accessing AskReddit threads",
username=os.getenv("REDDIT_USERNAME"),
password=os.getenv("REDDIT_PASSWORD"),
)
askreddit = reddit.subreddit("askreddit")
threads = askreddit.hot(limit=25)
submission = list(threads)[random.randrange(0, 25)]
print_substep(f"Video will be: {submission.title} :thumbsup:")
console.log("Getting video comments...")
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,
}
)
except AttributeError as e:
pass
print_substep("Received AskReddit threads Successfully.", style="bold green")
return content

@ -0,0 +1,90 @@
from rich import Console
from utils.console import print_markdown, print_step, print_substep
import praw
import random
from dotenv import load_dotenv
import os
console = Console()
def get_subreddit_threads():
"""
Returns a list of threads from the AskReddit subreddit.
"""
load_dotenv()
print_step("Getting AskReddit threads...")
if os.getenv("REDDIT_2FA").lower() == "yes":
print(
"\nEnter your two-factor authentication code from your authenticator app.\n"
)
code = input("> ")
print()
pw = os.getenv("REDDIT_PASSWORD")
passkey = f"{pw}:{code}"
else:
passkey = os.getenv("REDDIT_PASSWORD")
content = {}
<<<<<<< HEAD:reddit/askreddit.py
load_dotenv()
console.log("Logging in to reddit...")
||||||| 5b39896:reddit/askreddit.py
load_dotenv()
=======
>>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9:reddit/subreddit.py
reddit = praw.Reddit(
client_id=os.getenv("REDDIT_CLIENT_ID"),
client_secret=os.getenv("REDDIT_CLIENT_SECRET"),
user_agent="Accessing AskReddit threads",
username=os.getenv("REDDIT_USERNAME"),
password=passkey,
)
if os.getenv("SUBREDDIT"):
subreddit = reddit.subreddit(os.getenv("SUBREDDIT"))
else:
# ! Prompt the user to enter a subreddit
try:
subreddit = reddit.subreddit(
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)]
print_substep(f"Video will be: {submission.title} :thumbsup:")
console.log("Getting video comments...")
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,
}
)
except AttributeError as e:
pass
<<<<<<< HEAD:reddit/askreddit.py
print_substep("Received AskReddit threads Successfully.", style="bold green")
return content
||||||| 5b39896:reddit/askreddit.py
print_substep("Received AskReddit threads Successfully.", style="bold green")
return content
=======
print_substep("Received AskReddit threads successfully.", style="bold green")
return content
>>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9:reddit/subreddit.py

@ -27,16 +27,24 @@ pyee==8.1.0
pyflakes==2.2.0 pyflakes==2.2.0
Pygments==2.12.0 Pygments==2.12.0
python-dotenv==0.20.0 python-dotenv==0.20.0
pytube==12.1.0
regex==2020.10.15 regex==2020.10.15
requests==2.27.1 requests==2.27.1
rich==12.4.4 rich==12.4.4
six==1.16.0 six==1.16.0
toml==0.10.1 toml==0.10.1
tqdm==4.64.0 tqdm==4.64.0
<<<<<<< HEAD
typed-ast==1.5.4 # Please see issue https://github.com/elebumm/RedditVideoMakerBot/issues/16 comment three. typed-ast==1.5.4 # Please see issue https://github.com/elebumm/RedditVideoMakerBot/issues/16 comment three.
||||||| 5b39896
typed-ast==1.4.1
=======
typed-ast==1.5.4
>>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9
typing_extensions==4.2.0 typing_extensions==4.2.0
update-checker==0.18.0 update-checker==0.18.0
urllib3==1.26.9 urllib3==1.26.9
websocket-client==1.3.2 websocket-client==1.3.2
websockets==10.1 websockets==10.1
yt-dlp==2022.5.18

@ -1,5 +1,7 @@
from random import randrange from random import randrange
from pytube import YouTube
from yt_dlp import YoutubeDL
from pathlib import Path from pathlib import Path
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from moviepy.editor import VideoFileClip from moviepy.editor import VideoFileClip
@ -11,7 +13,6 @@ def get_start_and_end_times(video_length, length_of_clip):
random_time = randrange(180, int(length_of_clip) - int(video_length)) random_time = randrange(180, int(length_of_clip) - int(video_length))
return random_time, random_time + video_length return random_time, random_time + video_length
def download_background(): def download_background():
"""Downloads the background video from youtube. """Downloads the background video from youtube.
@ -20,20 +21,24 @@ def download_background():
if not Path("assets/mp4/background.mp4").is_file(): if not Path("assets/mp4/background.mp4").is_file():
print_step( print_step(
"We need to download the Minecraft background video. This is fairly large but it's only done once. 😎" "We need to download the Minecraft background video. This is fairly large but it's only done once."
)
print_substep("Downloading the background video... please be patient 🙏")
YouTube("https://www.youtube.com/watch?v=n_Dv4JMiwK8").streams.filter(
res="720p"
).first().download(
"assets/mp4",
filename="background.mp4",
) )
print_substep("Background video downloaded successfully! 🎉", style="bold green")
print_substep("Downloading the background video... please be patient.")
ydl_opts = {
"outtmpl": "assets/mp4/background.mp4",
"merge_output_format": "mp4",
}
with YoutubeDL(ydl_opts) as ydl:
ydl.download("https://www.youtube.com/watch?v=n_Dv4JMiwK8")
print_substep("Background video downloaded successfully!", style="bold green")
def chop_background_video(video_length): def chop_background_video(video_length):
print_step("Finding a spot in the background video to chop...✂️") print_step("Finding a spot in the background video to chop...")
background = VideoFileClip("assets/mp4/background.mp4") background = VideoFileClip("assets/mp4/background.mp4")
start_time, end_time = get_start_and_end_times(video_length, background.duration) start_time, end_time = get_start_and_end_times(video_length, background.duration)
@ -43,4 +48,4 @@ def chop_background_video(video_length):
end_time, end_time,
targetname="assets/mp4/clip.mp4", targetname="assets/mp4/clip.mp4",
) )
print_substep("Background video chopped successfully! 🎉", style="bold green") print_substep("Background video chopped successfully!", style="bold green")

@ -14,7 +14,7 @@ W, H = 1080, 1920
def make_final_video(number_of_clips): def make_final_video(number_of_clips):
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)

@ -28,7 +28,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num):
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.
print_substep("Post is NSFW. You are spicy... :fire:") print_substep("Post is NSFW. You are spicy...")
page.locator('[data-testid="content-gate"] button').click() page.locator('[data-testid="content-gate"] button').click()
page.locator('[data-test-id="post-content"]').screenshot( page.locator('[data-test-id="post-content"]').screenshot(
@ -50,4 +50,4 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num):
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")

@ -11,13 +11,13 @@ def save_text_to_mp3(reddit_obj):
Args: Args:
reddit_obj : The reddit object you received from the reddit API in the askreddit.py file. reddit_obj : The reddit object you received from the reddit API in the askreddit.py file.
""" """
print_step("Saving Text to MP3 files 🎶") print_step("Saving Text to MP3 files...")
length = 0 length = 0
# Create a folder for the mp3 files. # Create a folder for the mp3 files.
Path("assets/mp3").mkdir(parents=True, exist_ok=True) Path("assets/mp3").mkdir(parents=True, exist_ok=True)
tts = gTTS(text=reddit_obj["thread_title"], lang="en", slow=False, tld="co.uk") tts = gTTS(text=reddit_obj["thread_title"], lang="en", slow=False)
tts.save(f"assets/mp3/title.mp3") tts.save(f"assets/mp3/title.mp3")
length += MP3(f"assets/mp3/title.mp3").info.length length += MP3(f"assets/mp3/title.mp3").info.length
@ -25,10 +25,10 @@ def save_text_to_mp3(reddit_obj):
# ! 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") tts = gTTS(text=comment["comment_body"], lang="en", slow=False)
tts.save(f"assets/mp3/{idx}.mp3") tts.save(f"assets/mp3/{idx}.mp3")
length += MP3(f"assets/mp3/{idx}.mp3").info.length length += MP3(f"assets/mp3/{idx}.mp3").info.length
print_substep("Saved Text to MP3 files Successfully.", style="bold green") print_substep("Saved Text to MP3 files successfully.", style="bold green")
# ! Return the index so we know how many screenshots of comments we need to make. # ! Return the index so we know how many screenshots of comments we need to make.
return length, idx return length, idx

Loading…
Cancel
Save