diff --git a/.gitignore b/.gitignore index 793db5d..5f4915a 100644 --- a/.gitignore +++ b/.gitignore @@ -231,7 +231,6 @@ fabric.properties # Android studio 3.1+ serialized cache file .idea/caches/build_file_checksums.ser -assets/ out .DS_Store .setup-done-before diff --git a/assets/subOverlay/instagram.mov b/assets/subOverlay/instagram.mov new file mode 100644 index 0000000..42fe263 Binary files /dev/null and b/assets/subOverlay/instagram.mov differ diff --git a/assets/subOverlay/tiktok.mov b/assets/subOverlay/tiktok.mov new file mode 100644 index 0000000..df7e500 Binary files /dev/null and b/assets/subOverlay/tiktok.mov differ diff --git a/assets/subOverlay/youtube.mov b/assets/subOverlay/youtube.mov new file mode 100644 index 0000000..c43e34b Binary files /dev/null and b/assets/subOverlay/youtube.mov differ diff --git a/main.py b/main.py index 8a0755d..5cbba63 100755 --- a/main.py +++ b/main.py @@ -18,6 +18,8 @@ from video_creation.background import ( chop_background_video, get_background_config, ) + +from video_creation.subOverlay import download_suboverlay 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 @@ -50,6 +52,7 @@ def main(POST_ID=None): download_screenshots_of_reddit_posts(reddit_object, number_of_comments) bg_config = get_background_config() download_background(bg_config) + download_suboverlay() # Check for suboverlay and download if not found! chop_background_video(bg_config, length, reddit_object) make_final_video(number_of_comments, length, reddit_object, bg_config) diff --git a/utils/.config.template.toml b/utils/.config.template.toml index adbaed0..31c1027 100644 --- a/utils/.config.template.toml +++ b/utils/.config.template.toml @@ -22,7 +22,8 @@ times_to_run = { optional = false, default = 1, example = 2, explanation = "Used opacity = { optional = false, default = 0.9, example = 0.8, explanation = "Sets the opacity of the comments when overlayed over the background", type = "float", nmin = 0, nmax = 1, oob_error = "The opacity HAS to be between 0 and 1", input_error = "The opacity HAS to be a decimal number between 0 and 1" } transition = { optional = true, default = 0.2, example = 0.2, explanation = "Sets the transition time (in seconds) between the comments. Set to 0 if you want to disable it.", type = "float", nmin = 0, nmax = 2, oob_error = "The transition HAS to be between 0 and 2", input_error = "The opacity HAS to be a decimal number between 0 and 2" } storymode = { optional = true, type = "bool", default = false, example = false, options = [true, false,], explanation = "Only read out title and post content, not yet implemented" } - +sub_overlay = { optional = true, type = "bool", default = false, example = false, options = [true, false], explanation = "This will add a subscribe animation overlay to the end of the video" } +sub_overlay_name = { optional = true, default = "youtube", options = ["youtube", "tiktok", "instagram"], explanation = "Choose which overlay you would like"} [settings.background] background_choice = { optional = true, default = "minecraft", example = "rocket-league", options = ["minecraft", "gta", "rocket-league", "motor-gta", "csgo-surf", "cluster-truck", ""], explanation = "Sets the background for the video based on game name" } diff --git a/utils/video.py b/utils/video.py index 5566cd1..4ef4914 100644 --- a/utils/video.py +++ b/utils/video.py @@ -1,12 +1,15 @@ from __future__ import annotations from ast import Str import re +import math from typing import Tuple +from utils import settings from PIL import ImageFont, Image, ImageDraw, ImageEnhance from moviepy.video.VideoClip import VideoClip, ImageClip from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip +from moviepy.video.io.VideoFileClip import VideoFileClip class Video: @@ -56,3 +59,17 @@ class Video: # Overlay the img clip on the first video clip self.video = CompositeVideoClip([self.video, img_clip]) return self.video + + def add_overlay(self): + # Get duration for the entire video to place the overlay at the correct time + video_duration = self.video.duration + + overlayName = settings.config["settings"]["sub_overlay_name"] + + subOverlayClip = VideoFileClip((f"assets/subOverlay/{overlayName}.mov"), has_mask=True) + subOverlayClip.set_pos('center') + + placeTime = math.floor(video_duration - subOverlayClip.duration) - 3 + + self.video = CompositeVideoClip([self.video, subOverlayClip.set_start(placeTime)]) + return self.video diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 743e561..150fd5e 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -143,6 +143,11 @@ def make_final_video( final = Video(final).add_watermark( text=f"Background credit: {background_config[2]}", opacity=0.4, redditid=reddit_obj ) + + # Add an overlay + if settings.config["settings"]["sub_overlay"]: + final = Video(final).add_overlay() + final.write_videofile( f"assets/temp/{id}/temp.mp4", fps=30, diff --git a/video_creation/subOverlay.py b/video_creation/subOverlay.py new file mode 100644 index 0000000..39d99fd --- /dev/null +++ b/video_creation/subOverlay.py @@ -0,0 +1,38 @@ +import requests + +from os import makedirs +from os import path +from fileinput import filename +from utils.console import print_step, print_substep +from utils import settings +from pathlib import Path + +# Checks if suboverlay is a thing, if not it downloads the file +# Uses Google Drive Direct Link to store the file +def download_suboverlay(): + if settings.config["settings"]["sub_overlay"]: + URL = "https://drive.google.com/u/0/uc?id=16ajH0maciiWgWNgA-PNh29GZe9xqZmZR&export=download" + fileName = "youtube" + + if settings.config["settings"]["sub_overlay_name"] == "tiktok": + URL = "https://drive.google.com/u/0/uc?id=1N7tmEacL5GSUpVukxwza7OL7ihfAdShq&export=download" + fileName = "tiktok" + + if settings.config["settings"]["sub_overlay_name"] == "instagram": + URL = "https://drive.google.com/u/0/uc?id=19Yvuuojba8ixIP8whs0QEqw9gTer4T20&export=download" + fileName = "instagram" + + if Path(f"assets/subOverlay/{fileName}.mov").is_file(): + return + + #Generate path and folders + if not path.isdir(f'assets/subOverlay'): + makedirs(f'assets/subOverlay') + + print_step("We need to download the subscribe overlay, this only needs to be done once!") + print_substep("Downloading subscribe overlay please wait....") + + subOverlayFile = requests.get(URL, verify=False) + open(f'assets/subOverlay/{fileName}.mov', 'wb').write(subOverlayFile.content) + + print_substep("Subscribe overlay has been downloaded!", style="bold green")