diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 24150a0..6d5fa7a 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -62,6 +62,7 @@ def get_subreddit_threads(): try: content["thread_url"] = submission.url content["thread_title"] = submission.title + content["thread_post"] = submission.selftext content["comments"] = [] for top_level_comment in submission.comments: diff --git a/video_creation/final_video.py b/video_creation/final_video.py index fe10b2a..93bac6f 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -40,6 +40,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")) + try: + audio_clips.insert(1, AudioFileClip(f"assets/mp3/posttext.mp3")) + except: + OSError() audio_concat = concatenate_audioclips(audio_clips) audio_composite = CompositeAudioClip([audio_concat]) @@ -53,14 +57,24 @@ def make_final_video(number_of_clips): .resize(width=W - 100) .set_opacity(float(opacity)), ) - image_clips.insert( - 0, - ImageClip(f"assets/png/title.png") - .set_duration(audio_clips[0].duration) - .set_position("center") - .resize(width=W - 100) - .set_opacity(float(opacity)), - ) + if os.path.exists(f"assets/mp3/posttext.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) + .set_opacity(float(opacity)), + ) + else: + image_clips.insert( + 0, + ImageClip(f"assets/png/title.png") + .set_duration(audio_clips[0].duration) + .set_position("center") + .resize(width=W - 100) + .set_opacity(float(opacity)), + ) image_concat = concatenate_videoclips(image_clips).set_position( ("center", "center") ) diff --git a/video_creation/voices.py b/video_creation/voices.py index e8d8e43..c0df8b7 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -21,6 +21,16 @@ def save_text_to_mp3(reddit_obj): tts.save(f"assets/mp3/title.mp3") length += MP3(f"assets/mp3/title.mp3").info.length + try: + Path(f"assets/mp3/posttext.mp3").unlink() + except OSError as e: + pass + + 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 if length > 50: