Stable implementation of the watermark

NOT DESIGNED FOR PRODUCTION USE
pull/998/head
Jason 2 years ago
parent 839eb6fc2f
commit bc215f8b32

@ -13,7 +13,7 @@ from utils.console import print_step, print_substep
from utils.voice import sanitize_text from utils.voice import sanitize_text
from utils import settings from utils import settings
DEFAULT_MAX_LENGTH: int = 10 # video length variable DEFAULT_MAX_LENGTH: int = 5 # video length variable todo change
class TTSEngine: class TTSEngine:

@ -2,6 +2,9 @@
import math import math
from subprocess import Popen from subprocess import Popen
from os import name from os import name
from prawcore import ResponseException
from reddit.subreddit import get_subreddit_threads from reddit.subreddit import get_subreddit_threads
from utils.cleanup import cleanup from utils.cleanup import cleanup
from utils.console import print_markdown, print_step from utils.console import print_markdown, print_step
@ -57,8 +60,14 @@ def run_many(times):
Popen("cls" if name == "nt" else "clear", shell=True).wait() Popen("cls" if name == "nt" else "clear", shell=True).wait()
def shutdown():
print_markdown("## Clearing temp files")
cleanup()
exit()
if __name__ == "__main__": 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() config is False and exit()
try: try:
if config["settings"]["times_to_run"]: if config["settings"]["times_to_run"]:
@ -75,6 +84,12 @@ if __name__ == "__main__":
else: else:
main() main()
except KeyboardInterrupt: except KeyboardInterrupt:
print_markdown("## Clearing temp files") shutdown()
cleanup() except ResponseException:
exit() # error for invalid credentials
print_markdown("## Invalid credentials")
print_markdown("Please check your credentials in the config.toml file")
shutdown()
# todo error

@ -167,4 +167,4 @@ If you see any prompts, that means that you have unset/incorrectly set variables
if __name__ == "__main__": if __name__ == "__main__":
check_toml(".config.template.toml", "config.toml") check_toml("utils/.config.template.toml", "config.toml")

@ -18,7 +18,6 @@ class Video:
path = "./assets/temp/png/watermark.png" path = "./assets/temp/png/watermark.png"
width = int(fontsize * len(text)) width = int(fontsize * len(text))
height = int(fontsize * len(text) / 2) height = int(fontsize * len(text) / 2)
white = (255, 255, 255) white = (255, 255, 255)
transparent = (0, 0, 0, 0) transparent = (0, 0, 0, 0)
@ -35,10 +34,15 @@ class Video:
im.save(path) im.save(path)
return ImageClip(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 = self._create_watermark(text, opacity=opacity, fontsize=fontsize)
img_clip = img_clip.set_opacity(opacity).set_duration(duration) 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 # Overlay the img clip on the first video clip
self.video = CompositeVideoClip([self.video, img_clip]) self.video = CompositeVideoClip([self.video, img_clip])

Loading…
Cancel
Save