From b38184bc32ae150651622c74fe7466f470908202 Mon Sep 17 00:00:00 2001 From: HallowedDust5 Date: Tue, 21 Jun 2022 21:59:54 -0400 Subject: [PATCH] Updated doc comments, added typing in function declaration --- video_creation/final_video.py | 67 ++++++++++++++++++++++------------- video_creation/voices.py | 2 +- 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 37b1ac2..53ad5db 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -25,7 +25,13 @@ console = Console() W, H = 1080, 1920 -def make_final_video(number_of_clips, length): +def make_final_video(number_of_clips:int, length:int): + """Gathers audio clips, gathers all screenshots, stitches them together and saves the final video to assets/temp + + Args: + number_of_clips (int): Index to end at when going through the screenshots + length (int): Length of the video + """ print_step("Creating the final video 🎥") VideoFileClip.reW = lambda clip: clip.resize(width=W) VideoFileClip.reH = lambda clip: clip.resize(width=H) @@ -104,32 +110,12 @@ def make_final_video(number_of_clips, length): image_concat.audio = audio_composite final = CompositeVideoClip([background_clip, image_concat]) - def get_video_title() -> str: - title = os.getenv("VIDEO_TITLE") or "final_video" - if len(title) <= 35: - return title - else: - return title[0:30] + "..." filename = f"{get_video_title()}.mp4" - def save_data(): - with open("./video_creation/data/videos.json", "r+") as raw_vids: - done_vids = json.load(raw_vids) - if str(subreddit.submission.id) in [video["id"] for video in done_vids]: - return # video already done but was specified to continue anyway in the .env file - payload = { - "id": str(os.getenv("VIDEO_ID")), - "time": str(int(time.time())), - "background_credit": str(os.getenv("background_credit")), - "reddit_title": str(os.getenv("VIDEO_TITLE")), - "filename": filename, - } - done_vids.append(payload) - raw_vids.seek(0) - json.dump(done_vids, raw_vids, ensure_ascii=False, indent=4) - - save_data() + + save_data(filename) + if not exists("./results"): print_substep("the results folder didn't exist so I made it") os.mkdir("./results") @@ -148,3 +134,36 @@ def make_final_video(number_of_clips, length): print_step( f"Reddit title: {os.getenv('VIDEO_TITLE')} \n Background Credit: {os.getenv('background_credit')}" ) + +def save_data(filename:str): + """Saves the videos that have already been generated to a JSON file in video_creation/data/videos.json + + Args: + filename (str): The finished video title name + """ + with open("./video_creation/data/videos.json", "r+") as raw_vids: + done_vids = json.load(raw_vids) + if str(subreddit.submission.id) in [video["id"] for video in done_vids]: + return # video already done but was specified to continue anyway in the .env file + payload = { + "id": str(os.getenv("VIDEO_ID")), + "time": str(int(time.time())), + "background_credit": str(os.getenv("background_credit")), + "reddit_title": str(os.getenv("VIDEO_TITLE")), + "filename": filename, + } + done_vids.append(payload) + raw_vids.seek(0) + json.dump(done_vids, raw_vids, ensure_ascii=False, indent=4) + +def get_video_title() -> str: + """Gets video title from env variable or gives it the name "final_video" + + Returns: + str: Video title + """ + title = os.getenv("VIDEO_TITLE") or "final_video" + if len(title) <= 35: + return title + else: + return title[0:30] + "..." \ No newline at end of file diff --git a/video_creation/voices.py b/video_creation/voices.py index 97e5917..f68c20b 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -19,7 +19,7 @@ console = Console() VIDEO_LENGTH: int = 40 # secs -def save_text_to_mp3(reddit_obj): +def save_text_to_mp3(reddit_obj:dict[str])->tuple[int,int]: """Saves text to MP3 files. Goes through the reddit_obj and generates the title MP3 file and a certain number of comments until the total amount of time exceeds VIDEO_LENGTH seconds. Args: