Skip to content

Commit

Permalink
Version 3.2
Browse files Browse the repository at this point in the history
The RedditVideoMakerBot has been updated to version 3.2, bringing exciting new features and bug fixes. Introducing **ElevenLabs TTS** for high-quality audio. Enjoy **background audio** and **random voices per comment**. Run the bot with one click using the **bat file**. Use the **zoom setting** for bigger text. Bug fixes include video downloader improvements, random story mode fix, updated dependencies, code optimizations, text size adjustments, enhanced Reddit credentials validation, and translator fixes. Enjoy the new features and **thanks to all contributors**!
  • Loading branch information
OpenSourceSimon authored May 28, 2023
1 parent f2d89a1 commit 0ea74e4
Show file tree
Hide file tree
Showing 24 changed files with 539 additions and 222 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/codesee-arch-diagram.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,4 @@ video_creation/data/videos.json
video_creation/data/envvars.txt

config.toml
video_creation/data/videos.json
*.exe
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM python:3.10.9-slim

RUN apt update
RUN apt-get install -y ffmpeg
RUN apt install python3-pip -y

RUN mkdir /app
Expand Down
15 changes: 14 additions & 1 deletion GUI/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@
.tooltip-inner {
max-width: 500px !important;
}
#hard-reload {
cursor: pointer;
color: darkblue;
}
#hard-reload:hover {
color: blue;
}
</style>
</head>

Expand Down Expand Up @@ -132,11 +139,17 @@
Theme by &copy; Bootstrap. <a
href="https://github.com/elebumm/RedditVideoMakerBot/blob/master/README.md#developers-and-maintainers"
target="_blank">Developers and Maintainers</a></p>
<p class="mb-0">If your data is not refreshing, try to hard reload(Ctrl + F5) and visit your local
<p class="mb-0">If your data is not refreshing, try to hard reload(Ctrl + F5) or click <a id="hard-reload">this</a> and visit your local

<strong>{{ file }}</strong> file.
</p>
</div>
</footer>
<script>
document.getElementById("hard-reload").addEventListener("click", function () {
window.location.reload(true);
});
</script>
</body>

</html>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ In its current state, this bot does exactly what it needs to do. However, improv
I have tried to simplify the code so anyone can read it and start contributing at any skill level. Don't be shy :) contribute!

- [ ] Creating better documentation and adding a command line interface.
- [ ] Allowing the user to choose background music for their videos.
- [x] Allowing the user to choose background music for their videos.
- [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 between any subreddit.
Expand Down
46 changes: 46 additions & 0 deletions TTS/elevenlabs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import random

from elevenlabs import generate, save

from utils import settings

voices = [
"Adam",
"Antoni",
"Arnold",
"Bella",
"Domi",
"Elli",
"Josh",
"Rachel",
"Sam",
]


class elevenlabs:
def __init__(self):
self.max_chars = 2500
self.voices = voices

def run(self, text, filepath, random_voice: bool = False):
if random_voice:
voice = self.randomvoice()
else:
voice = str(
settings.config["settings"]["tts"]["elevenlabs_voice_name"]
).capitalize()

if settings.config["settings"]["tts"]["elevenlabs_api_key"]:
api_key = settings.config["settings"]["tts"]["elevenlabs_api_key"]
else:
raise ValueError(
"You didn't set an Elevenlabs API key! Please set the config variable ELEVENLABS_API_KEY to a valid API key."
)

audio = generate(
api_key=api_key, text=text, voice=voice, model="eleven_multilingual_v1"
)
save(audio=audio, filename=filepath)

def randomvoice(self):
return random.choice(self.voices)
30 changes: 22 additions & 8 deletions TTS/engine_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
from pathlib import Path
from typing import Tuple

# import sox
# from mutagen import MutagenError
# from mutagen.mp3 import MP3, HeaderNotFoundError
import numpy as np
import translators as ts
import translators
from moviepy.audio.AudioClip import AudioClip
from moviepy.audio.fx.volumex import volumex
from moviepy.editor import AudioFileClip
Expand All @@ -17,7 +14,9 @@
from utils.console import print_step, print_substep
from utils.voice import sanitize_text

DEFAULT_MAX_LENGTH: int = 50 # video length variable

DEFAULT_MAX_LENGTH: int = 50 # Video length variable, edit this on your own risk. It should work, but it's not supported



class TTSEngine:
Expand Down Expand Up @@ -55,9 +54,20 @@ def add_periods(
self,
): # adds periods to the end of paragraphs (where people often forget to put them) so tts doesn't blend sentences
for comment in self.reddit_object["comments"]:
# remove links
regex_urls = r"((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z]){2,6}([a-zA-Z0-9\.\&\/\?\:@\-_=#])*"
comment["comment_body"] = re.sub(regex_urls, " ", comment["comment_body"])
comment["comment_body"] = comment["comment_body"].replace("\n", ". ")
comment["comment_body"] = re.sub(r"\bAI\b", "A.I", comment["comment_body"])
comment["comment_body"] = re.sub(
r"\bAGI\b", "A.G.I", comment["comment_body"]
)
if comment["comment_body"][-1] != ".":
comment["comment_body"] += "."
comment["comment_body"] = comment["comment_body"].replace(". . .", ".")
comment["comment_body"] = comment["comment_body"].replace(".. . ", ".")
comment["comment_body"] = comment["comment_body"].replace(". . ", ".")
comment["comment_body"] = re.sub(r'\."\.', '".', comment["comment_body"])

def run(self) -> Tuple[int, int]:
Path(self.path).mkdir(parents=True, exist_ok=True)
Expand All @@ -66,7 +76,7 @@ def run(self) -> Tuple[int, int]:
self.add_periods()
self.call_tts("title", process_text(self.reddit_object["thread_title"]))
# processed_text = ##self.reddit_object["thread_post"] != ""
idx = None
idx = 0

if settings.config["settings"]["storymode"]:
if settings.config["settings"]["storymodemethod"] == 0:
Expand Down Expand Up @@ -141,7 +151,11 @@ def split_post(self, text: str, idx):
print("OSError")

def call_tts(self, filename: str, text: str):
self.tts_module.run(text, filepath=f"{self.path}/{filename}.mp3")
self.tts_module.run(
text,
filepath=f"{self.path}/{filename}.mp3",
random_voice=settings.config["settings"]["tts"]["random_voice"],
)
# try:
# self.length += MP3(f"{self.path}/{filename}.mp3").info.length
# except (MutagenError, HeaderNotFoundError):
Expand Down Expand Up @@ -172,6 +186,6 @@ def process_text(text: str, clean: bool = True):
new_text = sanitize_text(text) if clean else text
if lang:
print_substep("Translating Text...")
translated_text = ts.google(text, to_language=lang)
translated_text = translators.google(text, to_language=lang)
new_text = sanitize_text(translated_text)
return new_text
48 changes: 25 additions & 23 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python
import math
import sys
from logging import error
from os import name
from pathlib import Path
from subprocess import Popen
from typing import NoReturn

from prawcore import ResponseException
from utils.console import print_substep
Expand All @@ -15,16 +15,17 @@
from utils.id import id
from utils.version import checkversion
from video_creation.background import (
download_background,
chop_background_video,
download_background_video,
download_background_audio,
chop_background,
get_background_config,
)
from video_creation.final_video import make_final_video
from video_creation.screenshot_downloader import get_screenshots_of_reddit_posts
from video_creation.voices import save_text_to_mp3
from utils.ffmpeg_install import ffmpeg_install

__VERSION__ = "3.1"
__VERSION__ = "3.2"

print(
"""
Expand All @@ -38,7 +39,7 @@
)
# Modified by JasonLovesDoggo
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. You can find solutions to many common problems in the [Documentation](): https://reddit-video-maker-bot.netlify.app/"
"### Thanks for using this tool! Feel free to contribute to this project on GitHub! If you have any questions, feel free to join my Discord server or submit a GitHub issue. You can find solutions to many common problems in the documentation: https://reddit-video-maker-bot.netlify.app/"
)
checkversion(__VERSION__)

Expand All @@ -50,9 +51,13 @@ def main(POST_ID=None) -> None:
length, number_of_comments = save_text_to_mp3(reddit_object)
length = math.ceil(length)
get_screenshots_of_reddit_posts(reddit_object, number_of_comments)
bg_config = get_background_config()
download_background(bg_config)
chop_background_video(bg_config, length, reddit_object)
bg_config = {
"video": get_background_config("video"),
"audio": get_background_config("audio"),
}
download_background_video(bg_config["video"])
download_background_audio(bg_config["audio"])
chop_background(bg_config, length, reddit_object)
make_final_video(number_of_comments, length, reddit_object, bg_config)


Expand All @@ -65,28 +70,26 @@ def run_many(times) -> None:
Popen("cls" if name == "nt" else "clear", shell=True).wait()


def shutdown():
try:
redditid
except NameError:
print("Exiting...")
exit()
else:
def shutdown() -> NoReturn:
if "redditid" in globals():
print_markdown("## Clearing temp files")
cleanup(redditid)
print("Exiting...")
exit()

print("Exiting...")
sys.exit()


if __name__ == "__main__":
if sys.version_info.major != 3 or sys.version_info.minor != 10:
print("Hey! Congratulations, you've made it so far (which is pretty rare with no Python 3.10). Unfortunately, this program only works on Python 3.10. Please install Python 3.10 and try again.")
ffmpeg_install() # install ffmpeg if not installed
sys.exit()
ffmpeg_install()
directory = Path().absolute()
config = settings.check_toml(
f"{directory}/utils/.config.template.toml", "config.toml"
f"{directory}/utils/.config.template.toml", f"{directory}/config.toml"
)
config is False and exit()
config is False and sys.exit()

if (
not settings.config["settings"]["tts"]["tiktok_sessionid"]
or settings.config["settings"]["tts"]["tiktok_sessionid"] == ""
Expand All @@ -95,7 +98,7 @@ def shutdown():
"TikTok voice requires a sessionid! Check our documentation on how to obtain one.",
"bold red",
)
exit()
sys.exit()
try:
if config["reddit"]["thread"]["post_id"]:
for index, post_id in enumerate(
Expand All @@ -114,13 +117,12 @@ def shutdown():
except KeyboardInterrupt:
shutdown()
except ResponseException:
# error for invalid credentials
print_markdown("## Invalid credentials")
print_markdown("Please check your credentials in the config.toml file")

shutdown()
except Exception as err:
config["settings"]["tts"]["tiktok_sessionid"] = "REDACTED"
config["settings"]["tts"]["elevenlabs_api_key"] = "REDACTED"
print_step(
f"Sorry, something went wrong with this version! Try again, and feel free to report this issue at GitHub or the Discord community.\n"
f"Version: {__VERSION__} \n"
Expand Down
18 changes: 4 additions & 14 deletions reddit/subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,10 @@ def get_subreddit_threads(POST_ID: str):
if submission is None:
return get_subreddit_threads(POST_ID) # submission already done. rerun

if settings.config["settings"]["storymode"]:
if not submission.selftext:
print_substep("You are trying to use story mode on post with no post text")
exit()
else:
# Check for the length of the post text
if len(submission.selftext) > (
settings.config["settings"]["storymode_max_length"] or 2000
):
print_substep(
f"Post is too long ({len(submission.selftext)}), try with a different post. ({settings.config['settings']['storymode_max_length']} character limit)"
)
exit()
elif not submission.num_comments:
elif (
not submission.num_comments
and settings.config["settings"]["storymode"] == "false"
):
print_substep("No comments found. Skipping.")
exit()

Expand Down
35 changes: 18 additions & 17 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
boto3==1.24.24
botocore==1.27.24
gTTS==2.2.4
boto3==1.26.142
botocore==1.29.142
gTTS==2.3.2
moviepy==1.0.3
playwright==1.23.0
praw==7.6.1
playwright==1.34.0
praw==7.7.0
prawcore~=2.3.0
pytube==12.1.0
requests==2.28.1
rich==13.3.1
requests==2.31.0
rich==13.3.5
toml==0.10.2
translators==5.3.1
translators==5.7.6
pyttsx3==2.90
Pillow~=9.4.0
tomlkit==0.11.4
Flask==2.2.2
Pillow==9.5.0
tomlkit==0.11.8
Flask==2.3.2
clean-text==0.6.0
unidecode==1.3.2
spacy==3.4.1
torch==1.12.1
transformers==4.25.1
ffmpeg-python==0.2.0
unidecode==1.3.6
spacy==3.5.3
torch==2.0.1
transformers==4.29.2
ffmpeg-python==0.2.0
elevenlabs==0.2.16
yt-dlp==2023.3.4
Loading

0 comments on commit 0ea74e4

Please sign in to comment.