From c6b285ae18c93dadfe8c53bafdbb8c03784eaf58 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Mon, 10 Nov 2025 20:06:05 +0100 Subject: [PATCH] Fix sometimes overwriting existing edited videos --- croppa/main.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/croppa/main.py b/croppa/main.py index e56e65b..058579e 100644 --- a/croppa/main.py +++ b/croppa/main.py @@ -2017,7 +2017,7 @@ class VideoEditor: # Add manual tracking position if base_pos: positions.append(base_pos) - print(f"DEBUG: Manual tracking: ({base_pos[0]:.1f}, {base_pos[1]:.1f})") + # print(f"DEBUG: Manual tracking: ({base_pos[0]:.1f}, {base_pos[1]:.1f})") # Add template matching position if template_offset: @@ -5032,16 +5032,21 @@ class VideoEditor: extension = self.video_path.suffix # Remove any existing _edited_ suffix to get clean base name - clean_base = base_name.replace("_edited", "") + clean_base = re.sub(r"_edited_\d{5}", "", base_name) - # Find next available number - counter = 1 - while True: - new_name = f"{clean_base}_edited_{counter:05d}{extension}" - output_path = directory / new_name - if not output_path.exists(): - break - counter += 1 + # Find next available number by scanning directory for existing files + pattern = re.compile(rf"^{re.escape(clean_base)}_edited_(\d{{5}})\.") + max_num = 0 + for file_path in directory.iterdir(): + if file_path.is_file(): + match = pattern.match(file_path.name) + if match: + num = int(match.group(1)) + max_num = max(max_num, num) + + counter = max_num + 1 + new_name = f"{clean_base}_edited_{counter:05d}{extension}" + output_path = directory / new_name success = self.render_video(str(output_path)) elif key == 13: # Enter