fixed merge conflicts and cleared up some old existing .env referances

chore: updated version num
style: improved IDE autocorrection support
chore: simplified the regex in func name_normalize
pull/879/head
Jason 2 years ago
parent 73d15fe3ad
commit 9ae01b7c19

@ -37,7 +37,7 @@ class AWSPolly:
else: else:
if not settings.config["settings"]["tts"]["aws_polly_voice"]: if not settings.config["settings"]["tts"]["aws_polly_voice"]:
return ValueError( return ValueError(
f"Please set the environment variable AWS_VOICE to a valid voice. options are: {voices}" f"Please set the TOML variable AWS_VOICE to a valid voice. options are: {voices}"
) )
voice = str( voice = str(
settings.config["settings"]["tts"]["aws_polly_voice"] settings.config["settings"]["tts"]["aws_polly_voice"]

@ -37,7 +37,7 @@ class StreamlabsPolly:
else: else:
if not settings.config["settings"]["tts"]["streamlabs_polly_voice"]: if not settings.config["settings"]["tts"]["streamlabs_polly_voice"]:
return ValueError( return ValueError(
f"Please set the environment variable STREAMLABS_VOICE to a valid voice. options are: {voices}" f"Please set the config variable STREAMLABS_VOICE to a valid voice. options are: {voices}"
) )
voice = str( voice = str(
settings.config["settings"]["tts"]["streamlabs_polly_voice"] settings.config["settings"]["tts"]["streamlabs_polly_voice"]

@ -13,7 +13,7 @@ from video_creation.final_video import make_final_video
from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts
from video_creation.voices import save_text_to_mp3 from video_creation.voices import save_text_to_mp3
VERSION = "2.2.8" VERSION = "2.2.9"
print( print(
""" """

@ -28,7 +28,7 @@ def check_done(
if video["id"] == str(redditobj): if video["id"] == str(redditobj):
if settings.config["reddit"]["thread"]["post_id"]: if settings.config["reddit"]["thread"]["post_id"]:
print_step( print_step(
"You already have done this video but since it was declared specifically in the .env file the program will continue" "You already have done this video but since it was declared specifically in the config file the program will continue"
) )
return redditobj return redditobj
print_step("Getting new post as the current one has already been done") print_step("Getting new post as the current one has already been done")
@ -48,7 +48,7 @@ def save_data(filename: str, reddit_title: str, reddit_id: str, credit: str):
with open("./video_creation/data/videos.json", "r+", encoding="utf-8") as raw_vids: with open("./video_creation/data/videos.json", "r+", encoding="utf-8") as raw_vids:
done_vids = json.load(raw_vids) done_vids = json.load(raw_vids)
if reddit_id in [video["id"] for video in done_vids]: if reddit_id in [video["id"] for video in done_vids]:
return # video already done but was specified to continue anyway in the .env file return # video already done but was specified to continue anyway in the config file
payload = { payload = {
"id": reddit_id, "id": reddit_id,
"time": str(int(time.time())), "time": str(int(time.time())),

@ -1,11 +1,8 @@
import random
from os import listdir
from pathlib import Path from pathlib import Path
import random import random
from random import randrange from random import randrange
from typing import Any, Tuple from typing import Any, Tuple
from dotenv import load_dotenv
from moviepy.editor import VideoFileClip from moviepy.editor import VideoFileClip
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
@ -48,21 +45,7 @@ background_options = {
lambda t: ('center', 480 + t) lambda t: ('center', 480 + t)
) )
} }
def get_background_config():
"""Fetch the background/s configuration"""
try:
choice = str(settings.config['settings']['background_choice']).casefold()
except AttributeError:
print_substep("No background selected. Picking random background'")
choice = None
# Handle default / not supported background using default option.
# Default : pick random from supported background.
if not choice or choice not in background_options:
choice = random.choice(list(background_options.keys()))
return background_options[choice]
def get_start_and_end_times(video_length: int, length_of_clip: int) -> Tuple[int, int]: def get_start_and_end_times(video_length: int, length_of_clip: int) -> Tuple[int, int]:
"""Generates a random interval of time to be used as the background of the video. """Generates a random interval of time to be used as the background of the video.
@ -76,12 +59,10 @@ def get_start_and_end_times(video_length: int, length_of_clip: int) -> Tuple[int
random_time = randrange(180, int(length_of_clip) - int(video_length)) random_time = randrange(180, int(length_of_clip) - int(video_length))
return random_time, random_time + video_length return random_time, random_time + video_length
def get_background_config(): def get_background_config():
"""Fetch the background/s configuration""" """Fetch the background/s configuration"""
load_dotenv()
try: try:
choice = getenv("BackgroundChoice").casefold() choice = str(settings.config['settings']['background_choice']).casefold()
except AttributeError: except AttributeError:
print_substep("No background selected. Picking random background'") print_substep("No background selected. Picking random background'")
choice = None choice = None
@ -123,8 +104,6 @@ def chop_background_video(background_config: Tuple[str, str, str, Any], video_le
print_step("Finding a spot in the backgrounds video to chop...✂️") print_step("Finding a spot in the backgrounds video to chop...✂️")
choice = f"{background_config[2]}-{background_config[1]}" choice = f"{background_config[2]}-{background_config[1]}"
environ["background_credit"] = choice.split("-")[0]
background = VideoFileClip(f"assets/backgrounds/{choice}") background = VideoFileClip(f"assets/backgrounds/{choice}")
@ -143,4 +122,4 @@ def chop_background_video(background_config: Tuple[str, str, str, Any], video_le
new = video.subclip(start_time, end_time) new = video.subclip(start_time, end_time)
new.write_videofile("assets/temp/background.mp4") new.write_videofile("assets/temp/background.mp4")
print_substep("Background video chopped successfully!", style="bold green") print_substep("Background video chopped successfully!", style="bold green")
return credit return background_config[2]

@ -49,10 +49,10 @@ def name_normalize(name: str) -> str:
def make_final_video(number_of_clips: int, length: int, reddit_obj: dict, background_config: Tuple[str, str, str, Any]): def make_final_video(number_of_clips: int, length: int, reddit_obj: dict, background_config: Tuple[str, str, str, Any]):
"""Gathers audio clips, gathers all screenshots, stitches them together and saves the final video to assets/temp """Gathers audio clips, gathers all screenshots, stitches them together and saves the final video to assets/temp
Args: Args:
number_of_clips (int): Index to end at when going through the screenshots number_of_clips (int): Index to end at when going through the screenshots'
length (int): Length of the video length (int): Length of the video
reddit_obj (dict): The reddit object that contains the posts to read. reddit_obj (dict): The reddit object that contains the posts to read.
background_config Tuple[str, str, str, Any]: The background config to use. background_config (Tuple[str, str, str, Any]): The background config to use.
""" """
print_step("Creating the final video 🎥") print_step("Creating the final video 🎥")
VideoFileClip.reW = lambda clip: clip.resize(width=W) VideoFileClip.reW = lambda clip: clip.resize(width=W)
@ -103,7 +103,7 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict, backgr
# .resize(width=W - 100) # .resize(width=W - 100)
# .set_opacity(float(opacity)), # .set_opacity(float(opacity)),
# ) # )
# else: # else: story mode stuff
img_clip_pos = background_config[3] img_clip_pos = background_config[3]
image_concat = concatenate_videoclips( image_concat = concatenate_videoclips(
image_clips).set_position(img_clip_pos) image_clips).set_position(img_clip_pos)

Loading…
Cancel
Save