Skip to content

Commit 3eff3e4

Browse files
authored
Merge pull request #1093 from elebumm/develop
2.4
2 parents 2cfd20b + 8463794 commit 3eff3e4

24 files changed

+353
-123
lines changed

CONTRIBUTING.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# Contributing to Reddit Video Maker Bot 🎥
23

34
Thanks for taking the time to contribute! ❤️
@@ -105,6 +106,25 @@ Enhancement suggestions are tracked as [GitHub issues](https://github.com/elebum
105106

106107
You development environment should follow the requirements stated in the [README file](README.md). If you are not using the specified versions, **please reference this in your pull request**, so reviewers can test your code on both versions.
107108

109+
#### Setting up your development repository
110+
111+
These steps are only specified for beginner developers trying to contribute to this repository.
112+
If you know how to make a fork and clone, you can skip these steps.
113+
114+
Before contributing, follow these steps (if you are a beginner)
115+
116+
- Create a fork of this repository to your personal account
117+
- Clone the repo to your computer
118+
- Make sure that you have all dependencies installed
119+
- Run `python main.py` to make sure that the program is working
120+
- Now, you are all setup to contribute your own features to this repo!
121+
122+
Even if you are a beginner to working with python or contributing to open source software,
123+
don't worry! You can still try contributing even to the documentation!
124+
125+
("Setting up your development repository" was written by a beginner developer themselves!)
126+
127+
108128
#### Making your first PR
109129

110130
When making your PR, follow these guidelines:
@@ -114,7 +134,7 @@ When making your PR, follow these guidelines:
114134
- You link any issues that are resolved or fixed by your changes. (this is done by typing "Fixes #\<issue number\>") in your pull request
115135
- Where possible, you have used `git pull --rebase`, to avoid creating unnecessary merge commits
116136
- You have meaningful commits, and if possible, follow the commit style guide of `type: explanation`
117-
- Here are the commit types:
137+
- Here are the commit types:
118138
- **feat** - a new feature
119139
- **fix** - a bug fix
120140
- **docs** - a change to documentation / commenting

GUI.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Import the server module
2+
import http.server
3+
import webbrowser
4+
# Set the hostname
5+
HOST = "localhost"
6+
# Set the port number
7+
PORT = 4000
8+
9+
# Define class to display the index page of the web server
10+
class PythonServer(http.server.SimpleHTTPRequestHandler):
11+
def do_GET(self):
12+
if self.path == '/GUI':
13+
self.path = 'index.html'
14+
return http.server.SimpleHTTPRequestHandler.do_GET(self)
15+
16+
# Declare object of the class
17+
webServer = http.server.HTTPServer((HOST, PORT), PythonServer)
18+
# Print the URL of the webserver, new =2 opens in a new tab
19+
print(f"Server started at http://{HOST}:{PORT}/GUI/")
20+
webbrowser.open(f'http://{HOST}:{PORT}/GUI/', new = 2)
21+
print("Website opened in new tab")
22+
print("Press Ctrl+C to quit")
23+
try:
24+
# Run the web server
25+
webServer.serve_forever()
26+
except KeyboardInterrupt:
27+
# Stop the web server
28+
webServer.server_close()
29+
print("The server is stopped.")
30+
exit()

GUI/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
video += '<div class="d-flex justify-content-between align-items-center">';
150150
video += '<div class="btn-group">';
151151
video += '<a href="https://www.reddit.com/r/'+value.subreddit+'/comments/'+value.id+'/" class="btn btn-sm btn-outline-secondary" target="_blank">View</a>';
152-
video += '<a href="results/'+value.subreddit+'/'+value.filename+'" class="btn btn-sm btn-outline-secondary" download>Download</a>';
152+
video += '<a href="http://localhost:4000/results/'+value.subreddit+'/'+value.filename+'" class="btn btn-sm btn-outline-secondary" download>Download</a>';
153153
video += '</div>';
154154
video += '<div class="btn-group">';
155155
video += '<button type="button" data-toggle="tooltip" id="copy" data-original-title="Copy to clipboard" class="btn btn-sm btn-outline-secondary" data-clipboard-text="'+getCopyData(value.subreddit, value.reddit_title, value.filename, value.background_credit)+'"><i class="bi bi-card-text"></i></button>';

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,22 @@ On MacOS and Linux (debian, arch, fedora and centos, and based on those), you ca
5151
This can also be used to update the installation
5252

5353
4. Run `python main.py`
54-
5. Visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps), and set up an app that is a "script".
54+
5. Visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps), and set up an app that is a "script". Paste any URL in redirect URL. Ex:google.com
5555
6. The bot will ask you to fill in your details to connect to the Reddit API, and configure the bot to your liking
5656
7. Enjoy 😎
5757
8. If you need to reconfigure the bot, simply open the `config.toml` file and delete the lines that need to be changed. On the next run of the bot, it will help you reconfigure those options.
5858

5959
(Note if you got an error installing or running the bot try first rerunning the command with a three after the name e.g. python3 or pip3)
6060

61+
If you want to read more detailed guide about the bot, please refer to the [documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/)
62+
6163
## Video
6264

6365
https://user-images.githubusercontent.com/66544866/173453972-6526e4e6-c6ef-41c5-ab40-5d275e724e7c.mp4
6466

6567
## Contributing & Ways to improve 📈
6668

67-
In its current state, this bot does exactly what it needs to do. However, lots of improvements can be made.
69+
In its current state, this bot does exactly what it needs to do. However, improvements can always be made!
6870

6971
I have tried to simplify the code so anyone can read it and start contributing at any skill level. Don't be shy :) contribute!
7072

TTS/GTTS.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class GTTS:
1010
def __init__(self):
11-
self.max_chars = 0
11+
self.max_chars = 5000
1212
self.voices = []
1313

1414
def run(self, text, filepath):

TTS/aws_polly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
class AWSPolly:
2828
def __init__(self):
29-
self.max_chars = 0
29+
self.max_chars = 3000
3030
self.voices = voices
3131

3232
def run(self, text, filepath, random_voice: bool = False):

TTS/engine_wrapper.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from utils.voice import sanitize_text
1414
from utils import settings
1515

16-
DEFUALT_MAX_LENGTH: int = 50 # video length variable
16+
DEFAULT_MAX_LENGTH: int = 50 # video length variable
1717

1818

1919
class TTSEngine:
@@ -35,13 +35,15 @@ def __init__(
3535
tts_module,
3636
reddit_object: dict,
3737
path: str = "assets/temp/mp3",
38-
max_length: int = DEFUALT_MAX_LENGTH,
38+
max_length: int = DEFAULT_MAX_LENGTH,
39+
last_clip_length: int = 0,
3940
):
4041
self.tts_module = tts_module()
4142
self.reddit_object = reddit_object
4243
self.path = path
4344
self.max_length = max_length
4445
self.length = 0
46+
self.last_clip_length = last_clip_length
4547

4648
def run(self) -> Tuple[int, int]:
4749

@@ -55,24 +57,24 @@ def run(self) -> Tuple[int, int]:
5557

5658
print_step("Saving Text to MP3 files...")
5759

58-
self.call_tts("title", self.reddit_object["thread_title"])
59-
if (
60-
self.reddit_object["thread_post"] != ""
61-
and settings.config["settings"]["storymode"] == True
62-
):
63-
self.call_tts("posttext", self.reddit_object["thread_post"])
60+
self.call_tts("title", process_text(self.reddit_object["thread_title"]))
61+
processed_text = process_text(self.reddit_object["thread_post"])
62+
if processed_text != "" and settings.config["settings"]["storymode"] == True:
63+
self.call_tts("posttext", processed_text)
6464

6565
idx = None
6666
for idx, comment in track(enumerate(self.reddit_object["comments"]), "Saving..."):
6767
# ! Stop creating mp3 files if the length is greater than max length.
6868
if self.length > self.max_length:
69+
self.length -= self.last_clip_length
70+
idx -= 1
6971
break
7072
if (
7173
len(comment["comment_body"]) > self.tts_module.max_chars
7274
): # Split the comment if it is too long
7375
self.split_post(comment["comment_body"], idx) # Split the comment
7476
else: # If the comment is not too long, just call the tts engine
75-
self.call_tts(f"{idx}", comment["comment_body"])
77+
self.call_tts(f"{idx}", process_text(comment["comment_body"]))
7678

7779
print_substep("Saved Text to MP3 files successfully.", style="bold green")
7880
return self.length, idx
@@ -88,11 +90,12 @@ def split_post(self, text: str, idx: int):
8890
offset = 0
8991
for idy, text_cut in enumerate(split_text):
9092
# print(f"{idx}-{idy}: {text_cut}\n")
91-
if not text_cut or text_cut.isspace():
93+
new_text = process_text(text_cut)
94+
if not new_text or new_text.isspace():
9295
offset += 1
9396
continue
9497

95-
self.call_tts(f"{idx}-{idy - offset}.part", text_cut)
98+
self.call_tts(f"{idx}-{idy - offset}.part", new_text)
9699
split_files.append(AudioFileClip(f"{self.path}/{idx}-{idy - offset}.part.mp3"))
97100

98101
CompositeAudioClip([concatenate_audioclips(split_files)]).write_audiofile(
@@ -110,13 +113,14 @@ def split_post(self, text: str, idx: int):
110113
# Path(f"{self.path}/{idx}-{i}.part.mp3").unlink()
111114

112115
def call_tts(self, filename: str, text: str):
113-
self.tts_module.run(text=process_text(text), filepath=f"{self.path}/{filename}.mp3")
116+
self.tts_module.run(text, filepath=f"{self.path}/{filename}.mp3")
114117
# try:
115118
# self.length += MP3(f"{self.path}/{filename}.mp3").info.length
116119
# except (MutagenError, HeaderNotFoundError):
117120
# self.length += sox.file_info.duration(f"{self.path}/{filename}.mp3")
118121
try:
119122
clip = AudioFileClip(f"{self.path}/{filename}.mp3")
123+
self.last_clip_length = clip.duration
120124
self.length += clip.duration
121125
clip.close()
122126
except:

TTS/pyttsx.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import random
2+
import pyttsx3
3+
from utils import settings
4+
5+
6+
class pyttsx:
7+
def __init__(self):
8+
self.max_chars = 5000
9+
self.voices = []
10+
11+
def run(
12+
self,
13+
text: str,
14+
filepath: str,
15+
random_voice=False,
16+
):
17+
voice_id = settings.config["settings"]["tts"]["python_voice"]
18+
voice_num = settings.config["settings"]["tts"]["py_voice_num"]
19+
if voice_id == "" or voice_num == "":
20+
voice_id = 2
21+
voice_num = 3
22+
raise ValueError(
23+
"set pyttsx values to a valid value, switching to defaults"
24+
)
25+
else:
26+
voice_id = int(voice_id)
27+
voice_num = int(voice_num)
28+
for i in range(voice_num):
29+
self.voices.append(i)
30+
i = +1
31+
if random_voice:
32+
voice_id = self.randomvoice()
33+
engine = pyttsx3.init()
34+
voices = engine.getProperty("voices")
35+
engine.setProperty(
36+
"voice", voices[voice_id].id
37+
) # changing index changes voices but ony 0 and 1 are working here
38+
engine.save_to_file(text, f"{filepath}")
39+
engine.runAndWait()
40+
41+
def randomvoice(self):
42+
return random.choice(self.voices)

install.sh

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,39 +68,42 @@ function install_macos(){
6868
# Function to install for arch (and other forks like manjaro)
6969
function install_arch(){
7070
echo "Installing required packages"
71-
sudo pacman -S --needed python3 tk git && python3 -m ensurepip || install_fail
71+
sudo pacman -S --needed python3 tk git && python3 -m ensurepip unzip || install_fail
7272
}
7373

7474
# Function to install for debian (and ubuntu)
7575
function install_deb(){
7676
echo "Installing required packages"
77-
sudo apt install python3 python3-dev python3-tk python3-pip git || install_fail
77+
sudo apt install python3 python3-dev python3-tk python3-pip unzip || install_fail
7878
}
7979

8080
# Function to install for fedora (and other forks)
8181
function install_fedora(){
8282
echo "Installing required packages"
83-
sudo dnf install python3 python3-tkinter python3-pip git python3-devel || install_fail
83+
sudo dnf install python3 python3-tkinter python3-pip python3-devel unzip || install_fail
8484
}
8585

8686
# Function to install for centos (and other forks based on it)
8787
function install_centos(){
8888
echo "Installing required packages"
8989
sudo yum install -y python3 || install_fail
90-
sudo yum install -y python3-tkinter epel-release python3-pip git || install_fail
90+
sudo yum install -y python3-tkinter epel-release python3-pip unzip|| install_fail
9191
}
9292

9393
function get_the_bot(){
9494
echo "Downloading the bot"
95-
git clone https://github.com/elebumm/RedditVideoMakerBot.git
95+
rm -rf RedditVideoMakerBot-master
96+
curl -sL https://github.com/elebumm/RedditVideoMakerBot/archive/refs/heads/master.zip -o master.zip
97+
unzip master.zip
98+
rm -rf master.zip
9699
}
97100

98101
#install python dependencies
99102
function install_python_dep(){
100103
# tell the user that the script is going to install the python dependencies
101104
echo "Installing python dependencies"
102105
# cd into the directory
103-
cd RedditVideoMakerBot
106+
cd RedditVideoMakerBot-master
104107
# install the dependencies
105108
pip3 install -r requirements.txt
106109
# cd out
@@ -112,7 +115,7 @@ function install_playwright(){
112115
# tell the user that the script is going to install playwright
113116
echo "Installing playwright"
114117
# cd into the directory where the script is downloaded
115-
cd RedditVideoMakerBot
118+
cd RedditVideoMakerBot-master
116119
# run the install script
117120
python3 -m playwright install
118121
python3 -m playwright install-deps
@@ -198,9 +201,9 @@ function install_main(){
198201
install_playwright
199202
fi
200203

201-
DIR="./RedditVideoMakerBot"
204+
DIR="./RedditVideoMakerBot-master"
202205
if [ -d "$DIR" ]; then
203-
printf "\nThe bot is already installed, want to run it?"
206+
printf "\nThe bot is installed, want to run it?"
204207
# if -y (assume yes) continue
205208
if [[ ASSUME_YES -eq 1 ]]; then
206209
echo "Assuming yes"
@@ -214,7 +217,7 @@ function install_main(){
214217
exit 1
215218
fi
216219
fi
217-
cd RedditVideoMakerBot
220+
cd RedditVideoMakerBot-master
218221
python3 main.py
219222
fi
220223
}

0 commit comments

Comments
 (0)