From 6985c4da415102783478387c26e967cd60344ca5 Mon Sep 17 00:00:00 2001 From: Drugsosos <44712637+Drugsosos@users.noreply.github.com> Date: Thu, 9 Jun 2022 02:01:12 +0300 Subject: [PATCH] added name_normalize to fix bugs with forbidden chars in videoname --- video_creation/final_video.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index a12f2d6..07b0ffc 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -17,6 +17,15 @@ import os W, H = 1080, 1920 +def name_normalize( + name: str +) -> str: + name = re.sub(r'[?\\"%*:|<>]', '', name) + name = re.sub(r'(\D+)/(\D+)', r'\1\ or\ \2', name) + name = re.sub(r'(\d+)/(\d+)', r'\1\ of\ \2', name) + return name + + def make_final_video(number_of_clips): # Calls opacity from the .env @@ -83,7 +92,7 @@ def make_final_video(number_of_clips): final_video_path = "assets/" if os.getenv("FINAL_VIDEO_PATH"): final_video_path = os.getenv("FINAL_VIDEO_PATH") - filename = (re.sub('[?\"%*:|<>]', '', (final_video_path + reddit.subreddit.submission.title + ".mp4"))) + filename = final_video_path + name_normalize(reddit.subreddit.submission.title) + ".mp4" try: final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k") except: