From bc215f8b3218a7ef1025f5c5dd1ad17c21307ec8 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 14 Jul 2022 22:35:41 -0400 Subject: [PATCH] Stable implementation of the watermark NOT DESIGNED FOR PRODUCTION USE --- TTS/engine_wrapper.py | 2 +- main.py | 27 ++++++++++++++----- .../.config.template.toml | 0 utils/settings.py | 2 +- utils/video.py | 10 ++++--- 5 files changed, 30 insertions(+), 11 deletions(-) rename .config.template.toml => utils/.config.template.toml (100%) diff --git a/TTS/engine_wrapper.py b/TTS/engine_wrapper.py index 93da092..e22c96b 100644 --- a/TTS/engine_wrapper.py +++ b/TTS/engine_wrapper.py @@ -13,7 +13,7 @@ from utils.console import print_step, print_substep from utils.voice import sanitize_text from utils import settings -DEFAULT_MAX_LENGTH: int = 10 # video length variable +DEFAULT_MAX_LENGTH: int = 5 # video length variable todo change class TTSEngine: diff --git a/main.py b/main.py index 653703c..adc478d 100755 --- a/main.py +++ b/main.py @@ -2,6 +2,9 @@ import math from subprocess import Popen from os import name + +from prawcore import ResponseException + from reddit.subreddit import get_subreddit_threads from utils.cleanup import cleanup from utils.console import print_markdown, print_step @@ -51,14 +54,20 @@ def main(POST_ID=None): def run_many(times): for x in range(1, times + 1): print_step( - f'on the {x}{("th", "st", "nd", "rd", "th", "th", "th", "th","th", "th")[x%10]} iteration of {times}' + f'on the {x}{("th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th")[x % 10]} iteration of {times}' ) # correct 1st 2nd 3rd 4th 5th.... main() Popen("cls" if name == "nt" else "clear", shell=True).wait() +def shutdown(): + print_markdown("## Clearing temp files") + cleanup() + exit() + + if __name__ == "__main__": - config = settings.check_toml(".config.template.toml", "config.toml") + config = settings.check_toml("utils/.config.template.toml", "config.toml") config is False and exit() try: if config["settings"]["times_to_run"]: @@ -68,13 +77,19 @@ if __name__ == "__main__": for index, post_id in enumerate(config["reddit"]["thread"]["post_id"].split("+")): index += 1 print_step( - f'on the {index}{("st" if index%10 == 1 else ("nd" if index%10 == 2 else ("rd" if index%10 == 3 else "th")))} post of {len(config["reddit"]["thread"]["post_id"].split("+"))}' + f'on the {index}{("st" if index % 10 == 1 else ("nd" if index % 10 == 2 else ("rd" if index % 10 == 3 else "th")))} post of {len(config["reddit"]["thread"]["post_id"].split("+"))}' ) main(post_id) Popen("cls" if name == "nt" else "clear", shell=True).wait() else: main() except KeyboardInterrupt: - print_markdown("## Clearing temp files") - cleanup() - exit() + shutdown() + except ResponseException: + # error for invalid credentials + print_markdown("## Invalid credentials") + print_markdown("Please check your credentials in the config.toml file") + + shutdown() + + # todo error diff --git a/.config.template.toml b/utils/.config.template.toml similarity index 100% rename from .config.template.toml rename to utils/.config.template.toml diff --git a/utils/settings.py b/utils/settings.py index a36f63e..a9d7726 100755 --- a/utils/settings.py +++ b/utils/settings.py @@ -167,4 +167,4 @@ If you see any prompts, that means that you have unset/incorrectly set variables if __name__ == "__main__": - check_toml(".config.template.toml", "config.toml") + check_toml("utils/.config.template.toml", "config.toml") diff --git a/utils/video.py b/utils/video.py index 61dc41c..5c89e3b 100644 --- a/utils/video.py +++ b/utils/video.py @@ -18,7 +18,6 @@ class Video: path = "./assets/temp/png/watermark.png" width = int(fontsize * len(text)) height = int(fontsize * len(text) / 2) - white = (255, 255, 255) transparent = (0, 0, 0, 0) @@ -35,10 +34,15 @@ class Video: im.save(path) return ImageClip(path) - def add_watermark(self, text, opacity=0.5, duration: int | float = 5, position: Tuple = (1, 100), fontsize=15): + def add_watermark(self, text, opacity=0.5, duration: int | float = 5, position: Tuple = (0.7, 0.9), fontsize=15): + print(len(text)) + compensation = round((position[0] / ((len(text) * (fontsize / 5) / 1.5) / 100 + position[0] * position[0])), ndigits=2) + position = (compensation, position[1]) + print(f'{compensation=}') + print(f'{position=}') img_clip = self._create_watermark(text, opacity=opacity, fontsize=fontsize) img_clip = img_clip.set_opacity(opacity).set_duration(duration) - img_clip = img_clip.set_position(("center","bottom")) # set position doesn't work for some reason # todo fix + img_clip = img_clip.set_position(position, relative=True) # set position doesn't work for some reason # fixme # Overlay the img clip on the first video clip self.video = CompositeVideoClip([self.video, img_clip])