some changes to see merge conflicts

pull/879/head
Jason 2 years ago
parent 0b6e6a4c14
commit bd52b4fe8b

@ -8,12 +8,12 @@ from utils.console import print_markdown, print_step
from utils import settings
# from utils.checker import envUpdate
from video_creation.background import download_background, chop_background_video
from video_creation.background import download_background, chop_background_video, get_background_config
from video_creation.final_video import make_final_video
from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts
from video_creation.voices import save_text_to_mp3
VERSION = "2.2.2"
VERSION = "2.2.8"
print(
"""
@ -36,6 +36,7 @@ def main(POST_ID=None):
reddit_object = get_subreddit_threads(POST_ID)
length, number_of_comments = save_text_to_mp3(reddit_object)
length = math.ceil(length)
bg_config = get_background_config()
download_screenshots_of_reddit_posts(reddit_object, number_of_comments)
download_background()
credit = chop_background_video(length)

@ -8,8 +8,56 @@ from moviepy.editor import VideoFileClip
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from pytube import YouTube
from utils import settings
from utils.console import print_step, print_substep
# Supported Background. Can add/remove background video here....
# <key>-<value> : key -> used as keyword for TOML file. value -> background configuration
# Format (value):
# 1. Youtube URI
# 2. filename
# 3. Citation (owner of the video)
# 4. Position of image clips in the background. See moviepy reference for more information. (https://zulko.github.io/moviepy/ref/VideoClip/VideoClip.html#moviepy.video.VideoClip.VideoClip.set_position)
background_options = {
"motor-gta": ( # Motor-GTA Racing
"https://www.youtube.com/watch?v=vw5L4xCPy9Q",
"bike-parkour-gta.mp4",
"Achy Gaming",
lambda t: ('center', 480 + t)
),
"rocket-league": ( # Rocket League
"https://www.youtube.com/watch?v=2X9QGY__0II",
"rocket_league.mp4",
"Orbital Gameplay",
"top"
),
"minecraft": ( # Minecraft parkour
"https://www.youtube.com/watch?v=n_Dv4JMiwK8",
"parkour.mp4",
"bbswitzer",
"center"
),
"gta": ( # GTA Stunt Race
"https://www.youtube.com/watch?v=qGa9kWREOnE",
"gta-stunt-race.mp4",
"Achy Gaming",
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]:
"""Generates a random interval of time to be used as the background of the video.

@ -3,7 +3,7 @@ import multiprocessing
import os
import re
from os.path import exists
from typing import Dict
from typing import Dict, Tuple, Any
import translators as ts
from moviepy.editor import (
@ -32,7 +32,7 @@ def name_normalize(name: str) -> str:
name = re.sub(r'[?\\"%*:|<>]', "", name)
name = re.sub(r"( [w,W]\s?\/\s?[o,O,0])", r" without", name)
name = re.sub(r"( [w,W]\s?\/)", r" with", name)
name = re.sub(r"([0-9]+)\s?\/\s?([0-9]+)", r"\1 of \2", name)
name = re.sub(r"(\d+)\s?\/\s?(\d+)", r"\1 of \2", name)
name = re.sub(r"(\w+)\s?\/\s?(\w+)", r"\1 or \2", name)
name = re.sub(r"\/", r"", name)
@ -46,15 +46,13 @@ def name_normalize(name: str) -> str:
return name
def make_final_video(
number_of_clips: int, length: int, reddit_obj: dict, background_credit: str
):
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
Args:
number_of_clips (int): Index to end at when going through the screenshots
length (int): Length of the video
reddit_obj (dict): The reddit object that contains the posts to read.
background_config Tuple[str, str, str, Any]: The background config to use.
"""
print_step("Creating the final video 🎥")
VideoFileClip.reW = lambda clip: clip.resize(width=W)
@ -85,7 +83,6 @@ def make_final_video(
0,
ImageClip("assets/temp/png/title.png")
.set_duration(audio_clips[0].duration)
.set_position("center")
.resize(width=W - 100)
.set_opacity(new_opacity),
)
@ -94,7 +91,6 @@ def make_final_video(
image_clips.append(
ImageClip(f"assets/temp/png/comment_{i}.png")
.set_duration(audio_clips[i + 1].duration)
.set_position("center")
.resize(width=W - 100)
.set_opacity(new_opacity)
)
@ -109,9 +105,9 @@ def make_final_video(
# .set_opacity(float(opacity)),
# )
# else:
image_concat = concatenate_videoclips(image_clips).set_position(
("center", "center")
)
img_clip_pos = background_config[3]
image_concat = concatenate_videoclips(
image_clips).set_position(img_clip_pos)
image_concat.audio = audio_composite
final = CompositeVideoClip([background_clip, image_concat])
title = re.sub(r"[^\w\s-]", "", reddit_obj["thread_title"])
@ -120,7 +116,7 @@ def make_final_video(
filename = f"{name_normalize(title)}.mp4"
subreddit = settings.config["reddit"]["thread"]["subreddit"]
save_data(filename, title, idx, background_credit)
save_data(filename, title, idx, background_config[2])
if not exists(f"./results/{subreddit}"):
print_substep("The results folder didn't exist so I made it")
@ -148,5 +144,5 @@ def make_final_video(
print_substep("See result in the results folder!")
print_step(
f'Reddit title: {reddit_obj["thread_title"]} \n Background Credit: {background_credit}'
f'Reddit title: {reddit_obj["thread_title"]} \n Background Credit: {background_config[2]}'
)

Loading…
Cancel
Save