From c5faaf242b692d8c7286a738954901663db67fc5 Mon Sep 17 00:00:00 2001 From: frarol96 Date: Wed, 11 Oct 2023 20:02:18 +0000 Subject: [PATCH] Added user-defined output directory --- v2cmodules/toolbox.py | 47 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/v2cmodules/toolbox.py b/v2cmodules/toolbox.py index e5a02c2..b0d2a18 100644 --- a/v2cmodules/toolbox.py +++ b/v2cmodules/toolbox.py @@ -20,10 +20,7 @@ def fetch_ini(): with urllib.request.urlopen(config_url) as config_template: config_template = config_template.read().decode("utf-8") file.write(config_template) - tk.messagebox.showinfo( - "Reset config file", - f"Config file has been reset" - ) + tk.messagebox.showinfo("Reset config file", f"Config file has been reset") debug('DEBUG', f"Config file was reset to default") INVALID_INI = False except: @@ -56,7 +53,8 @@ def checkinifile(): 'save_output': bool, 'show_playback': bool, 'roi_size': int, - 'window_size': str + 'window_size': str, + 'user_defined_output_dir': str } expected_debug_keys = { 'debug_output': bool @@ -147,4 +145,41 @@ def toggle_show(): else: messagebox.showinfo("Info", "Video2Crops is currently processing files!") - \ No newline at end of file +# Function to create the output directory and return its path +def create_output_directory(video_filename): + debug('DEBUG', f"Creating output directory") + base_directory = user_defined_output_dir + video_filename_base, _ = os.path.splitext(os.path.basename(video_filename)) + output_folder_path = os.path.join(base_directory, video_filename_base) + + # Create the output directory if it doesn't exist + if not os.path.exists(output_folder_path): + os.makedirs(output_folder_path) + + debug('DEBUG', f"Processing file: {video_filename}") + debug('DEBUG', f"Created output directory at: {output_folder_path}") + return output_folder_path + +def truncate_path(path, pre_max=None, post_max=None): + # Split the path into components + path_components = os.path.normpath(path).split(os.path.sep) + + # Ensure the first two components are displayed in full + pre_part = os.path.sep.join(path_components[:2]) + + # Ensure the last two components are displayed in full + post_part = os.path.sep.join(path_components[-2:]) + + # Truncate the pre-portion if pre_max is specified + if pre_max is not None: + pre_part = pre_part[:pre_max] + + # Truncate the post-portion if post_max is specified + if post_max is not None: + post_part = post_part[-post_max:] + + # Combine the parts with ellipsis in between + truncated_path = f"{pre_part}...{post_part}" + + debug('DEBUG', f"Truncated the path \'{path}\' to \'{truncated_path}\'") + return truncated_path