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 1/3] 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: From 1764d54e5ddbfb6c42dbd0b0e733ce532da9f8f3 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 2/3] added name_normalize to fix bugs with forbidden chars in videoname --- video_creation/final_video.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 07b0ffc..27a351d 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -21,8 +21,8 @@ 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) + name = re.sub(r'(\D+)/(\D+)', r'\1 or\ \2', name) + name = re.sub(r'(\d+)/(\d+)', r'\1 of\ \2', name) return name From 30ad5a510d9767f4d08821f0c45dc6b2352ecb67 Mon Sep 17 00:00:00 2001 From: Drugsosos <44712637+Drugsosos@users.noreply.github.com> Date: Fri, 10 Jun 2022 20:17:34 +0300 Subject: [PATCH 3/3] fixes in regex in name_normalize --- video_creation/final_video.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 27a351d..f2acf74 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -21,8 +21,11 @@ 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) + name = re.sub(r'( [w,W]\s?\/\s?[o,O,0])', r' without', name) + name = re.sub(r'( [w,W]\s?\/)', r' with', name) + name = re.sub(r'([0-9]+)\s?\/\s?([0-9]+)', r'\1 of \2', name) + name = re.sub(r'(\w+)\s?\/\s?(\w+)', r'\1 or \2', name) + name = re.sub(r'\/', r'', name) return name