Fixed a bug: an error if the thread has no selftext
Had to implement a few checks for the thread having selftext and for selftext tts file to exist
This commit is contained in:
1 parent
2fbb369f8a
commit
2ef606fe29
2 files changed
+26
-12
No files matched your search
@@ -8,7 +8,7 @@ from moviepy.editor import (
|
||||
CompositeVideoClip,
|
||||
)
|
||||
from utils.console import print_step
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
W, H = 1080, 1920
|
||||
|
||||
@@ -29,7 +29,10 @@ def make_final_video(number_of_clips):
|
||||
for i in range(0, number_of_clips):
|
||||
audio_clips.append(AudioFileClip(f"assets/mp3/{i}.mp3"))
|
||||
audio_clips.insert(0, AudioFileClip(f"assets/mp3/title.mp3"))
|
||||
audio_clips.insert(1, AudioFileClip(f"assets/mp3/posttext.mp3"))
|
||||
try:
|
||||
audio_clips.insert(1, AudioFileClip(f"assets/mp3/posttext.mp3"))
|
||||
except:
|
||||
OSError()
|
||||
audio_concat = concatenate_audioclips(audio_clips)
|
||||
audio_composite = CompositeAudioClip([audio_concat])
|
||||
|
||||
@@ -42,13 +45,23 @@ def make_final_video(number_of_clips):
|
||||
.set_position("center")
|
||||
.resize(width=W - 100),
|
||||
)
|
||||
image_clips.insert(
|
||||
0,
|
||||
ImageClip(f"assets/png/title.png")
|
||||
.set_duration(audio_clips[0].duration + audio_clips[1].duration)
|
||||
.set_position("center")
|
||||
.resize(width=W - 100),
|
||||
)
|
||||
|
||||
if Path(f"assets/mp3/posttext.mp3").is_file(): #audio_clips[1] == AudioFileClip(f"assets/mp3/0.mp3"):
|
||||
image_clips.insert(
|
||||
0,
|
||||
ImageClip(f"assets/png/title.png")
|
||||
.set_duration(audio_clips[0].duration + audio_clips[1].duration)
|
||||
.set_position("center")
|
||||
.resize(width=W - 100),
|
||||
)
|
||||
else:
|
||||
image_clips.insert(
|
||||
0,
|
||||
ImageClip(f"assets/png/title.png")
|
||||
.set_duration(audio_clips[0].duration)
|
||||
.set_position("center")
|
||||
.resize(width=W - 100),
|
||||
)
|
||||
image_concat = concatenate_videoclips(image_clips).set_position(
|
||||
("center", "center")
|
||||
)
|
||||
|
||||
@@ -21,9 +21,10 @@ def save_text_to_mp3(reddit_obj):
|
||||
tts.save(f"assets/mp3/title.mp3")
|
||||
length += MP3(f"assets/mp3/title.mp3").info.length
|
||||
|
||||
tts = gTTS(text=reddit_obj["thread_post"], lang="en", slow=False)
|
||||
tts.save(f"assets/mp3/posttext.mp3")
|
||||
length += MP3(f"assets/mp3/posttext.mp3").info.length
|
||||
if reddit_obj["thread_post"] != "":
|
||||
tts = gTTS(text=reddit_obj["thread_post"], lang="en", slow=False)
|
||||
tts.save(f"assets/mp3/posttext.mp3")
|
||||
length += MP3(f"assets/mp3/posttext.mp3").info.length
|
||||
|
||||
for idx, comment in track(enumerate(reddit_obj["comments"]), "Saving..."):
|
||||
# ! Stop creating mp3 files if the length is greater than 50 seconds. This can be longer, but this is just a good starting point
|
||||
|
||||
Reference in new issue
Block a user