refactor: background credit is now a variable

pull/861/head
Callum Leslie 3 years ago
parent 436266033e
commit f5560cae69
No known key found for this signature in database
GPG Key ID: D382C4AFEECEAA90

@ -38,8 +38,8 @@ def main(POST_ID=None):
length = math.ceil(length)
download_screenshots_of_reddit_posts(reddit_object, number_of_comments)
download_background()
chop_background_video(length)
make_final_video(number_of_comments, length, reddit_object)
credit = chop_background_video(length)
make_final_video(number_of_comments, length, reddit_object, credit)
def run_many(times):

@ -34,7 +34,7 @@ def check_done(
return redditobj
def save_data(filename: str, reddit_title: str, reddit_id: str):
def save_data(filename: str, reddit_title: str, reddit_id: str, credit: str):
"""Saves the videos that have already been generated to a JSON file in video_creation/data/videos.json
Args:
@ -50,9 +50,7 @@ def save_data(filename: str, reddit_title: str, reddit_id: str):
payload = {
"id": reddit_id,
"time": str(int(time.time())),
"background_credit": settings.config["settings"]["background_credit"]
if "background_credit" in settings.config["settings"]
else "",
"background_credit": credit,
"reddit_title": reddit_title,
"filename": filename,
}

@ -1,5 +1,5 @@
import random
from os import listdir, environ
from os import listdir
from pathlib import Path
from random import randrange
from typing import Tuple
@ -55,7 +55,7 @@ def download_background():
print_substep("Background videos downloaded successfully! 🎉", style="bold green")
def chop_background_video(video_length: int):
def chop_background_video(video_length: int) -> str:
"""Generates the background footage to be used in the video and writes it to assets/temp/background.mp4
Args:
@ -63,7 +63,7 @@ def chop_background_video(video_length: int):
"""
print_step("Finding a spot in the backgrounds video to chop...✂️")
choice = random.choice(listdir("assets/backgrounds"))
environ["background_credit"] = choice.split("-")[0]
credit = choice.split("-")[0]
background = VideoFileClip(f"assets/backgrounds/{choice}")
@ -81,3 +81,4 @@ def chop_background_video(video_length: int):
new = video.subclip(start_time, end_time)
new.write_videofile("assets/temp/background.mp4")
print_substep("Background video chopped successfully!", style="bold green")
return credit

@ -20,13 +20,13 @@ from rich.console import Console
from utils.cleanup import cleanup
from utils.console import print_step, print_substep
from utils.videos import save_data
from utils import settings
console = Console()
W, H = 1080, 1920
def make_final_video(number_of_clips: int, length: int, reddit_obj: dict):
def make_final_video(number_of_clips: int, length: int, reddit_obj: dict, background_credit: str):
"""Gathers audio clips, gathers all screenshots, stitches them together and saves the final video to assets/temp
Args:
@ -37,7 +37,7 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict):
print_step("Creating the final video 🎥")
VideoFileClip.reW = lambda clip: clip.resize(width=W)
VideoFileClip.reH = lambda clip: clip.resize(width=H)
opacity = os.getenv("OPACITY")
opacity = settings.config["settings"]["opacity"]
background_clip = (
VideoFileClip("assets/temp/background.mp4")
.without_audio()
@ -91,9 +91,9 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict):
title = re.sub(r"[^\w\s-]", "", reddit_obj["thread_title"])
idx = re.sub(r"[^\w\s-]", "", reddit_obj["thread_id"])
filename = f"{title}.mp4"
subreddit = os.getenv("SUBREDDIT")
subreddit = settings.config["reddit"]["thread"]["subreddit"]
save_data(filename, title, idx)
save_data(filename, title, idx, credit)
if not exists(f"./results/{subreddit}"):
print_substep("The results folder didn't exist so I made it")
@ -118,5 +118,5 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict):
print_substep("See result in the results folder!")
print_step(
f'Reddit title: {reddit_obj["thread_title"]} \n Background Credit: {os.getenv("background_credit")}'
f'Reddit title: {reddit_obj["thread_title"]} \n Background Credit: {background_credit}'
)

Loading…
Cancel
Save