From 96d0bcfdd83a0862f3f87e3f3c6119317c4dc8de Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 1 Jun 2022 22:26:41 -0400 Subject: [PATCH] fp issue nightly backup --- reddit/subreddit.py | 2 -- video_creation/data/videos.json | 10 +++++++++- video_creation/voices.py | 27 ++++++++++++++++++++------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 9a19c55..5bf475f 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -12,8 +12,6 @@ TEXT_WHITELIST = set('abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234 def textify(text): return ''.join(filter(TEXT_WHITELIST.__contains__, text)) - - def get_subreddit_threads(): """ Returns a list of threads from the AskReddit subreddit. diff --git a/video_creation/data/videos.json b/video_creation/data/videos.json index fe51488..2a417ad 100644 --- a/video_creation/data/videos.json +++ b/video_creation/data/videos.json @@ -1 +1,9 @@ -[] +[ + { + "id": "v2kd2q", + "time": "1654128204", + "background_credit": "bbswitzer", + "reddit_title": "What movie do you absolutely love yet acknowledge is not a super wellmade movie", + "filename": "What movie do you absolutely l....mp4" + } +] \ No newline at end of file diff --git a/video_creation/voices.py b/video_creation/voices.py index ccb4a9d..5f6797b 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -1,3 +1,5 @@ +from os import remove + import sox from pathlib import Path @@ -8,6 +10,8 @@ from rich.progress import track from video_creation.TTSwrapper import TTTTSWrapper +VIDEO_LENGTH: int = 40 # secs + def save_text_to_mp3(reddit_obj): """Saves Text to MP3 files. @@ -27,18 +31,27 @@ def save_text_to_mp3(reddit_obj): length += MP3(f"assets/temp/mp3/title.mp3").info.length except HeaderNotFoundError: length = sox.file_info.duration(f"assets/temp/mp3/title.mp3") - - for idx, comment in track(enumerate(reddit_obj["comments"]), "Saving..."): + com = 0 + for comment in track((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_voices starting point - if length > 50: + if length > VIDEO_LENGTH: break - ttttsw.tts(comment["comment_body"], filename=f"assets/temp/mp3/{idx}.mp3", random_speaker=False) + ttttsw.tts(comment["comment_body"], filename=f"assets/temp/mp3/{com}.mp3", random_speaker=False) try: - length += MP3(f"assets/temp/mp3/{idx}.mp3").info.length + length += MP3(f"assets/temp/mp3/{com}.mp3").info.length + com += 1 except (HeaderNotFoundError, MutagenError, Exception): - length = sox.file_info.duration(f"assets/temp/mp3/{idx}.mp3") + try: + length += sox.file_info.duration(f"assets/temp/mp3/{com}.mp3") + com += 1 + except (OSError, IOError): + print('would have removed' + f"assets/temp/mp3/{com}.mp3" + f"assets/temp/png/comment_{com}.png") + #remove(f"assets/temp/mp3/{com}.mp3") + #remove(f"assets/temp/png/comment_{com}.png")# todo might cause odd un-syncing print_substep("Saved Text to MP3 files Successfully.", style="bold green") # ! Return the index so we know how many screenshots of comments we need to make. - return length, idx + return length, com