Updated doc comments, added typing in function declaration
This commit is contained in:
2 files changed
+43
-24
No files matched your search
@@ -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] + "..."
|
||||
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user