Merge remote-tracking branch 'origin/develop' into develop

pull/879/head
Jason 2 years ago
commit f0b0d01643

@ -14,7 +14,7 @@ REDDIT_CLIENT_SECRET="" #fFAGRNJru1FTz70BzhT3Zg
REDDIT_USERNAME="" #asdfghjkl REDDIT_USERNAME="" #asdfghjkl
#EXPLANATION the username of your reddit account #EXPLANATION the username of your reddit account
#RANGE 3:20 #RANGE 3:20
#MATCH_REGEX [_0-9a-zA-Z]+$ #MATCH_REGEX [-_0-9a-zA-Z]+$
#OOB_ERROR A username HAS to be between 3 and 20 characters #OOB_ERROR A username HAS to be between 3 and 20 characters
REDDIT_PASSWORD="" #fFAGRNJru1FTz70BzhT3Zg REDDIT_PASSWORD="" #fFAGRNJru1FTz70BzhT3Zg

@ -32,21 +32,19 @@ The only original thing being done is the editing and gathering of all materials
## Requirements ## Requirements
- Python 3.7+ - Python 3.9+
- Playwright (this should install automatically in installation) - Playwright (this should install automatically in installation)
## Installation 👩‍💻 ## Installation 👩‍💻
1. Clone this repository 1. Clone this repository
2. **Automatic Install**: Run `python main.py` and type 'yes' to activate the setup assistant. 2. Run `pip install -r requirements.txt`
3. Run `pip install -r requirements.txt` 3. Run `playwright install` and `playwright install-deps`. (if this fails try adding python -m to the front of the command)
4. Run `playwright install` and `playwright install-deps`. (if this fails try adding python -m to the front of the command) 4. Run `python main.py`
5. Run `python main.py` (unless you chose automatic install, then the installer will automatically run main.py)
required\*\*), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". required\*\*), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script".
6. Enjoy 😎 5. Enjoy 😎
(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) (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)

@ -4,9 +4,9 @@ from typing import Tuple
import re import re
from os import getenv from os import getenv
import sox # import sox
from mutagen import MutagenError # from mutagen import MutagenError
from mutagen.mp3 import MP3, HeaderNotFoundError # from mutagen.mp3 import MP3, HeaderNotFoundError
import translators as ts import translators as ts
from rich.progress import track from rich.progress import track
from moviepy.editor import AudioFileClip, CompositeAudioClip, concatenate_audioclips from moviepy.editor import AudioFileClip, CompositeAudioClip, concatenate_audioclips
@ -94,12 +94,10 @@ class TTSEngine:
def call_tts(self, filename: str, text: str): def call_tts(self, filename: str, text: str):
self.tts_module.run(text=process_text(text), filepath=f"{self.path}/{filename}.mp3") self.tts_module.run(text=process_text(text), filepath=f"{self.path}/{filename}.mp3")
try: # try:
try: # self.length += MP3(f"{self.path}/{filename}.mp3").info.length
self.length += MP3(f"{self.path}/{filename}.mp3").info.length # except (MutagenError, HeaderNotFoundError):
except (MutagenError, HeaderNotFoundError): # self.length += sox.file_info.duration(f"{self.path}/{filename}.mp3")
self.length += sox.file_info.duration(f"{self.path}/{filename}.mp3")
except Exception: # last resort backup
clip = AudioFileClip(f"{self.path}/{filename}.mp3") clip = AudioFileClip(f"{self.path}/{filename}.mp3")
self.length += clip.duration self.length += clip.duration

@ -1,5 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
import math
from subprocess import Popen from subprocess import Popen
from os import getenv, name from os import getenv, name
from dotenv import load_dotenv from dotenv import load_dotenv
@ -35,6 +35,7 @@ def main(POST_ID=None):
cleanup() cleanup()
reddit_object = get_subreddit_threads(POST_ID) reddit_object = get_subreddit_threads(POST_ID)
length, number_of_comments = save_text_to_mp3(reddit_object) length, number_of_comments = save_text_to_mp3(reddit_object)
length = math.ceil(length)
download_screenshots_of_reddit_posts(reddit_object, number_of_comments) download_screenshots_of_reddit_posts(reddit_object, number_of_comments)
download_background() download_background()
chop_background_video(length) chop_background_video(length)

@ -1,5 +1,5 @@
boto3==1.24.12 boto3==1.24.12
botocore==1.27.12 botocore==1.27.22
gTTS==2.2.4 gTTS==2.2.4
moviepy==1.0.3 moviepy==1.0.3
mutagen==1.45.1 mutagen==1.45.1
@ -9,4 +9,4 @@ python-dotenv==0.20.0
pytube==12.1.0 pytube==12.1.0
requests==2.28.1 requests==2.28.1
rich==12.4.4 rich==12.4.4
translators==5.2.2 translators==5.3.1

@ -51,49 +51,28 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict):
audio_concat = concatenate_audioclips(audio_clips) audio_concat = concatenate_audioclips(audio_clips)
audio_composite = CompositeAudioClip([audio_concat]) audio_composite = CompositeAudioClip([audio_concat])
# Get sum of all clip lengths console.log(f"[bold green] Video Will Be: {length} Seconds Long")
total_length = sum([clip.duration for clip in audio_clips])
# round total_length to an integer
int_total_length = round(total_length)
# Output Length
console.log(f"[bold green] Video Will Be: {int_total_length} Seconds Long")
# add title to video # add title to video
image_clips = [] image_clips = []
# Gather all images # Gather all images
if opacity is None or float(opacity) >= 1: # opacity not set or is set to one OR MORE new_opacity = 1 if opacity is None or float(opacity) >= 1 else float(opacity)
image_clips.insert(
0,
ImageClip("assets/temp/png/title.png")
.set_duration(audio_clips[0].duration)
.set_position("center")
.resize(width=W - 100),
)
else:
image_clips.insert( image_clips.insert(
0, 0,
ImageClip("assets/temp/png/title.png") ImageClip("assets/temp/png/title.png")
.set_duration(audio_clips[0].duration) .set_duration(audio_clips[0].duration)
.set_position("center") .set_position("center")
.resize(width=W - 100) .resize(width=W - 100)
.set_opacity(float(opacity)), .set_opacity(new_opacity)
) )
for i in range(0, number_of_clips): for i in range(0, number_of_clips):
if opacity is None or float(opacity) >= 1: # opacity not set or is set to one OR MORE
image_clips.append(
ImageClip(f"assets/temp/png/comment_{i}.png")
.set_duration(audio_clips[i + 1].duration)
.set_position("center")
.resize(width=W - 100),
)
else:
image_clips.append( image_clips.append(
ImageClip(f"assets/temp/png/comment_{i}.png") ImageClip(f"assets/temp/png/comment_{i}.png")
.set_duration(audio_clips[i + 1].duration) .set_duration(audio_clips[i + 1].duration)
.set_position("center") .set_position("center")
.resize(width=W - 100) .resize(width=W - 100)
.set_opacity(float(opacity)), .set_opacity(new_opacity)
) )
# if os.path.exists("assets/mp3/posttext.mp3"): # if os.path.exists("assets/mp3/posttext.mp3"):
@ -129,7 +108,7 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict):
threads=multiprocessing.cpu_count(), threads=multiprocessing.cpu_count(),
) )
ffmpeg_tools.ffmpeg_extract_subclip( ffmpeg_tools.ffmpeg_extract_subclip(
"assets/temp/temp.mp4", 0, length, targetname=f"results/{subreddit}/{filename}" "assets/temp/temp.mp4", 0, final.duration, targetname=f"results/{subreddit}/{filename}"
) )
# os.remove("assets/temp/temp.mp4") # os.remove("assets/temp/temp.mp4")

Loading…
Cancel
Save