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 import settings
DEFAULT_MAX_LENGTH: int = 10 # video length variable
DEFAULT_MAX_LENGTH: int = 5 # video length variable todo change
class TTSEngine:

@ -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

@ -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")

@ -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])

Loading…
Cancel
Save