Skip to content

Commit 0ea74e4

Browse files
Version 3.2
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**!
1 parent f2d89a1 commit 0ea74e4

24 files changed

+539
-222
lines changed

.github/workflows/codesee-arch-diagram.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,4 @@ video_creation/data/videos.json
244244
video_creation/data/envvars.txt
245245

246246
config.toml
247-
video_creation/data/videos.json
247+
*.exe

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM python:3.10.9-slim
22

33
RUN apt update
4+
RUN apt-get install -y ffmpeg
45
RUN apt install python3-pip -y
56

67
RUN mkdir /app

GUI/layout.html

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@
5656
.tooltip-inner {
5757
max-width: 500px !important;
5858
}
59+
#hard-reload {
60+
cursor: pointer;
61+
color: darkblue;
62+
}
63+
#hard-reload:hover {
64+
color: blue;
65+
}
5966
</style>
6067
</head>
6168

@@ -132,11 +139,17 @@
132139
Theme by &copy; Bootstrap. <a
133140
href="https://github.com/elebumm/RedditVideoMakerBot/blob/master/README.md#developers-and-maintainers"
134141
target="_blank">Developers and Maintainers</a></p>
135-
<p class="mb-0">If your data is not refreshing, try to hard reload(Ctrl + F5) and visit your local
142+
<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
143+
136144
<strong>{{ file }}</strong> file.
137145
</p>
138146
</div>
139147
</footer>
148+
<script>
149+
document.getElementById("hard-reload").addEventListener("click", function () {
150+
window.location.reload(true);
151+
});
152+
</script>
140153
</body>
141154

142155
</html>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ In its current state, this bot does exactly what it needs to do. However, improv
7070
I have tried to simplify the code so anyone can read it and start contributing at any skill level. Don't be shy :) contribute!
7171

7272
- [ ] Creating better documentation and adding a command line interface.
73-
- [ ] Allowing the user to choose background music for their videos.
73+
- [x] Allowing the user to choose background music for their videos.
7474
- [x] Allowing users to choose a reddit thread instead of being randomized.
7575
- [x] Allowing users to choose a background that is picked instead of the Minecraft one.
7676
- [x] Allowing users to choose between any subreddit.

TTS/elevenlabs.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import random
2+
3+
from elevenlabs import generate, save
4+
5+
from utils import settings
6+
7+
voices = [
8+
"Adam",
9+
"Antoni",
10+
"Arnold",
11+
"Bella",
12+
"Domi",
13+
"Elli",
14+
"Josh",
15+
"Rachel",
16+
"Sam",
17+
]
18+
19+
20+
class elevenlabs:
21+
def __init__(self):
22+
self.max_chars = 2500
23+
self.voices = voices
24+
25+
def run(self, text, filepath, random_voice: bool = False):
26+
if random_voice:
27+
voice = self.randomvoice()
28+
else:
29+
voice = str(
30+
settings.config["settings"]["tts"]["elevenlabs_voice_name"]
31+
).capitalize()
32+
33+
if settings.config["settings"]["tts"]["elevenlabs_api_key"]:
34+
api_key = settings.config["settings"]["tts"]["elevenlabs_api_key"]
35+
else:
36+
raise ValueError(
37+
"You didn't set an Elevenlabs API key! Please set the config variable ELEVENLABS_API_KEY to a valid API key."
38+
)
39+
40+
audio = generate(
41+
api_key=api_key, text=text, voice=voice, model="eleven_multilingual_v1"
42+
)
43+
save(audio=audio, filename=filepath)
44+
45+
def randomvoice(self):
46+
return random.choice(self.voices)

TTS/engine_wrapper.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
from pathlib import Path
44
from typing import Tuple
55

6-
# import sox
7-
# from mutagen import MutagenError
8-
# from mutagen.mp3 import MP3, HeaderNotFoundError
96
import numpy as np
10-
import translators as ts
7+
import translators
118
from moviepy.audio.AudioClip import AudioClip
129
from moviepy.audio.fx.volumex import volumex
1310
from moviepy.editor import AudioFileClip
@@ -17,7 +14,9 @@
1714
from utils.console import print_step, print_substep
1815
from utils.voice import sanitize_text
1916

20-
DEFAULT_MAX_LENGTH: int = 50 # video length variable
17+
18+
DEFAULT_MAX_LENGTH: int = 50 # Video length variable, edit this on your own risk. It should work, but it's not supported
19+
2120

2221

2322
class TTSEngine:
@@ -55,9 +54,20 @@ def add_periods(
5554
self,
5655
): # adds periods to the end of paragraphs (where people often forget to put them) so tts doesn't blend sentences
5756
for comment in self.reddit_object["comments"]:
57+
# remove links
58+
regex_urls = r"((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z]){2,6}([a-zA-Z0-9\.\&\/\?\:@\-_=#])*"
59+
comment["comment_body"] = re.sub(regex_urls, " ", comment["comment_body"])
5860
comment["comment_body"] = comment["comment_body"].replace("\n", ". ")
61+
comment["comment_body"] = re.sub(r"\bAI\b", "A.I", comment["comment_body"])
62+
comment["comment_body"] = re.sub(
63+
r"\bAGI\b", "A.G.I", comment["comment_body"]
64+
)
5965
if comment["comment_body"][-1] != ".":
6066
comment["comment_body"] += "."
67+
comment["comment_body"] = comment["comment_body"].replace(". . .", ".")
68+
comment["comment_body"] = comment["comment_body"].replace(".. . ", ".")
69+
comment["comment_body"] = comment["comment_body"].replace(". . ", ".")
70+
comment["comment_body"] = re.sub(r'\."\.', '".', comment["comment_body"])
6171

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

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

143153
def call_tts(self, filename: str, text: str):
144-
self.tts_module.run(text, filepath=f"{self.path}/{filename}.mp3")
154+
self.tts_module.run(
155+
text,
156+
filepath=f"{self.path}/{filename}.mp3",
157+
random_voice=settings.config["settings"]["tts"]["random_voice"],
158+
)
145159
# try:
146160
# self.length += MP3(f"{self.path}/{filename}.mp3").info.length
147161
# except (MutagenError, HeaderNotFoundError):
@@ -172,6 +186,6 @@ def process_text(text: str, clean: bool = True):
172186
new_text = sanitize_text(text) if clean else text
173187
if lang:
174188
print_substep("Translating Text...")
175-
translated_text = ts.google(text, to_language=lang)
189+
translated_text = translators.google(text, to_language=lang)
176190
new_text = sanitize_text(translated_text)
177191
return new_text

main.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env python
22
import math
33
import sys
4-
from logging import error
54
from os import name
65
from pathlib import Path
76
from subprocess import Popen
7+
from typing import NoReturn
88

99
from prawcore import ResponseException
1010
from utils.console import print_substep
@@ -15,16 +15,17 @@
1515
from utils.id import id
1616
from utils.version import checkversion
1717
from video_creation.background import (
18-
download_background,
19-
chop_background_video,
18+
download_background_video,
19+
download_background_audio,
20+
chop_background,
2021
get_background_config,
2122
)
2223
from video_creation.final_video import make_final_video
2324
from video_creation.screenshot_downloader import get_screenshots_of_reddit_posts
2425
from video_creation.voices import save_text_to_mp3
2526
from utils.ffmpeg_install import ffmpeg_install
2627

27-
__VERSION__ = "3.1"
28+
__VERSION__ = "3.2"
2829

2930
print(
3031
"""
@@ -38,7 +39,7 @@
3839
)
3940
# Modified by JasonLovesDoggo
4041
print_markdown(
41-
"### 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/"
42+
"### 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/"
4243
)
4344
checkversion(__VERSION__)
4445

@@ -50,9 +51,13 @@ def main(POST_ID=None) -> None:
5051
length, number_of_comments = save_text_to_mp3(reddit_object)
5152
length = math.ceil(length)
5253
get_screenshots_of_reddit_posts(reddit_object, number_of_comments)
53-
bg_config = get_background_config()
54-
download_background(bg_config)
55-
chop_background_video(bg_config, length, reddit_object)
54+
bg_config = {
55+
"video": get_background_config("video"),
56+
"audio": get_background_config("audio"),
57+
}
58+
download_background_video(bg_config["video"])
59+
download_background_audio(bg_config["audio"])
60+
chop_background(bg_config, length, reddit_object)
5661
make_final_video(number_of_comments, length, reddit_object, bg_config)
5762

5863

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

6772

68-
def shutdown():
69-
try:
70-
redditid
71-
except NameError:
72-
print("Exiting...")
73-
exit()
74-
else:
73+
def shutdown() -> NoReturn:
74+
if "redditid" in globals():
7575
print_markdown("## Clearing temp files")
7676
cleanup(redditid)
77-
print("Exiting...")
78-
exit()
77+
78+
print("Exiting...")
79+
sys.exit()
7980

8081

8182
if __name__ == "__main__":
8283
if sys.version_info.major != 3 or sys.version_info.minor != 10:
8384
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.")
84-
ffmpeg_install() # install ffmpeg if not installed
85+
sys.exit()
86+
ffmpeg_install()
8587
directory = Path().absolute()
8688
config = settings.check_toml(
87-
f"{directory}/utils/.config.template.toml", "config.toml"
89+
f"{directory}/utils/.config.template.toml", f"{directory}/config.toml"
8890
)
89-
config is False and exit()
91+
config is False and sys.exit()
92+
9093
if (
9194
not settings.config["settings"]["tts"]["tiktok_sessionid"]
9295
or settings.config["settings"]["tts"]["tiktok_sessionid"] == ""
@@ -95,7 +98,7 @@ def shutdown():
9598
"TikTok voice requires a sessionid! Check our documentation on how to obtain one.",
9699
"bold red",
97100
)
98-
exit()
101+
sys.exit()
99102
try:
100103
if config["reddit"]["thread"]["post_id"]:
101104
for index, post_id in enumerate(
@@ -114,13 +117,12 @@ def shutdown():
114117
except KeyboardInterrupt:
115118
shutdown()
116119
except ResponseException:
117-
# error for invalid credentials
118120
print_markdown("## Invalid credentials")
119121
print_markdown("Please check your credentials in the config.toml file")
120-
121122
shutdown()
122123
except Exception as err:
123124
config["settings"]["tts"]["tiktok_sessionid"] = "REDACTED"
125+
config["settings"]["tts"]["elevenlabs_api_key"] = "REDACTED"
124126
print_step(
125127
f"Sorry, something went wrong with this version! Try again, and feel free to report this issue at GitHub or the Discord community.\n"
126128
f"Version: {__VERSION__} \n"

reddit/subreddit.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,10 @@ def get_subreddit_threads(POST_ID: str):
107107
if submission is None:
108108
return get_subreddit_threads(POST_ID) # submission already done. rerun
109109

110-
if settings.config["settings"]["storymode"]:
111-
if not submission.selftext:
112-
print_substep("You are trying to use story mode on post with no post text")
113-
exit()
114-
else:
115-
# Check for the length of the post text
116-
if len(submission.selftext) > (
117-
settings.config["settings"]["storymode_max_length"] or 2000
118-
):
119-
print_substep(
120-
f"Post is too long ({len(submission.selftext)}), try with a different post. ({settings.config['settings']['storymode_max_length']} character limit)"
121-
)
122-
exit()
123-
elif not submission.num_comments:
110+
elif (
111+
not submission.num_comments
112+
and settings.config["settings"]["storymode"] == "false"
113+
):
124114
print_substep("No comments found. Skipping.")
125115
exit()
126116

requirements.txt

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
boto3==1.24.24
2-
botocore==1.27.24
3-
gTTS==2.2.4
1+
boto3==1.26.142
2+
botocore==1.29.142
3+
gTTS==2.3.2
44
moviepy==1.0.3
5-
playwright==1.23.0
6-
praw==7.6.1
5+
playwright==1.34.0
6+
praw==7.7.0
77
prawcore~=2.3.0
8-
pytube==12.1.0
9-
requests==2.28.1
10-
rich==13.3.1
8+
requests==2.31.0
9+
rich==13.3.5
1110
toml==0.10.2
12-
translators==5.3.1
11+
translators==5.7.6
1312
pyttsx3==2.90
14-
Pillow~=9.4.0
15-
tomlkit==0.11.4
16-
Flask==2.2.2
13+
Pillow==9.5.0
14+
tomlkit==0.11.8
15+
Flask==2.3.2
1716
clean-text==0.6.0
18-
unidecode==1.3.2
19-
spacy==3.4.1
20-
torch==1.12.1
21-
transformers==4.25.1
22-
ffmpeg-python==0.2.0
17+
unidecode==1.3.6
18+
spacy==3.5.3
19+
torch==2.0.1
20+
transformers==4.29.2
21+
ffmpeg-python==0.2.0
22+
elevenlabs==0.2.16
23+
yt-dlp==2023.3.4

0 commit comments

Comments
 (0)