diff --git a/main.py b/main.py index b88f7d4..a332113 100644 --- a/main.py +++ b/main.py @@ -98,7 +98,8 @@ class MediaGrader: def is_video(self, file_path: Path) -> bool: """Check if file is a video""" - return file_path.suffix.lower() in self.extensions + video_extensions = [".mp4", ".avi", ".mov", ".mkv", ".gif"] + return file_path.suffix.lower() in video_extensions def calculate_frame_delay(self) -> int: """Calculate frame delay in milliseconds based on playback speed""" @@ -122,8 +123,10 @@ class MediaGrader: self.current_cap.release() if self.is_video(file_path): + # Suppress OpenCV error messages for unsupported codecs self.current_cap = cv2.VideoCapture(str(file_path)) if not self.current_cap.isOpened(): + print(f"Warning: Could not open video file {file_path.name} (unsupported codec)") return False self.total_frames = int(self.current_cap.get(cv2.CAP_PROP_FRAME_COUNT)) self.current_frame = 0 @@ -364,13 +367,13 @@ class MediaGrader: destination = grade_dir / f"{stem}_{counter}{suffix}" counter += 1 + # Track this move for undo functionality BEFORE making changes + self.undo_history.append((str(destination), str(current_file), self.current_index)) + try: shutil.move(str(current_file), str(destination)) print(f"Moved {current_file.name} to grade {grade}") - # Track this move for undo functionality - self.undo_history.append((str(destination), str(current_file), self.current_index)) - self.media_files.pop(self.current_index) if self.current_index >= len(self.media_files): @@ -382,6 +385,8 @@ class MediaGrader: except Exception as e: print(f"Error moving file: {e}") + # Remove the undo entry since the move failed + self.undo_history.pop() return True