File size: 6,170 Bytes
0d0412d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/env python3
"""
Batch Video Visualizer and Reviewer
====================================
Visualizes all videos in a folder using visualize.py (2D/3D mode),
then prompts to keep or delete each video.

Usage:
    python src/batch_visualize_review.py --folder data/raw/forehand_lift --mode both
    python src/batch_visualize_review.py --folder data/raw/backhand_drive --mode 2d
"""

import argparse
import os
import sys
import subprocess
from pathlib import Path
from typing import List


def find_videos(folder: str) -> List[Path]:
    """Find all video files in the given folder."""
    folder_path = Path(folder)
    if not folder_path.exists():
        print(f"โŒ Folder not found: {folder}")
        sys.exit(1)
    
    video_extensions = {'.mp4', '.avi', '.mov', '.mkv', '.MP4', '.AVI', '.MOV'}
    videos = [f for f in folder_path.iterdir() 
              if f.is_file() and f.suffix in video_extensions]
    
    return sorted(videos)


def visualize_video(video_path: Path, mode: str, speed: float) -> bool:
    """
    Run visualize.py on a video.
    Returns True if visualization succeeded, False otherwise.
    """
    cmd = [
        sys.executable,  # Use current Python interpreter
        "src/research/visualize.py",
        "--video", str(video_path),
        "--mode", mode,
        "--speed", str(speed),
    ]
    
    print(f"\n{'='*70}")
    print(f"๐Ÿ“น Visualizing: {video_path.name}")
    print(f"{'='*70}")
    
    try:
        result = subprocess.run(cmd, check=False)
        return result.returncode == 0
    except KeyboardInterrupt:
        print("\nโš ๏ธ  Visualization interrupted by user")
        return False
    except Exception as e:
        print(f"โŒ Error running visualize.py: {e}")
        return False


def prompt_keep_or_delete(video_path: Path) -> str:
    """
    Prompt user to keep, delete, or skip the video.
    Returns: 'keep', 'delete', or 'quit'
    """
    while True:
        print(f"\n๐Ÿ“น {video_path.name}")
        response = input("Keep this video? [y]es / [n]o (delete) / [s]kip / [q]uit: ").strip().lower()
        
        if response in ['y', 'yes', 'k', 'keep', '']:
            return 'keep'
        elif response in ['n', 'no', 'd', 'delete']:
            return 'delete'
        elif response in ['s', 'skip']:
            return 'skip'
        elif response in ['q', 'quit', 'exit']:
            return 'quit'
        else:
            print("โŒ Invalid input. Please enter y/n/s/q")


def delete_video(video_path: Path) -> bool:
    """Delete a video file."""
    try:
        video_path.unlink()
        print(f"๐Ÿ—‘๏ธ  Deleted: {video_path.name}")
        return True
    except Exception as e:
        print(f"โŒ Failed to delete {video_path.name}: {e}")
        return False


def main():
    parser = argparse.ArgumentParser(
        description="Batch visualize videos and prompt to keep or delete each one"
    )
    parser.add_argument(
        "--folder", 
        required=True,
        help="Folder containing videos to review"
    )
    parser.add_argument(
        "--mode", 
        choices=['2d', '3d', 'both'],
        default='both',
        help="Visualization mode (default: both)"
    )
    parser.add_argument(
        "--speed",
        type=float,
        default=1.0,
        help="Playback speed multiplier (e.g., 0.5 for half speed)"
    )
    parser.add_argument(
        "--auto-delete",
        action='store_true',
        help="Skip confirmation prompt for deletion (use with caution!)"
    )
    
    args = parser.parse_args()
    
    # Find all videos
    videos = find_videos(args.folder)
    
    if not videos:
        print(f"โŒ No videos found in {args.folder}")
        sys.exit(1)
    
    print(f"\n{'='*70}")
    print(f"๐Ÿ“ Found {len(videos)} video(s) in {args.folder}")
    print(f"๐ŸŽฌ Visualization mode: {args.mode}")
    print(f"{'='*70}")
    
    # Stats
    kept = []
    deleted = []
    skipped = []
    
    # Process each video
    for i, video_path in enumerate(videos, 1):
        print(f"\n[{i}/{len(videos)}] Processing: {video_path.name}")
        
        # Visualize
        success = visualize_video(video_path, args.mode, args.speed)
        
        if not success:
            print(f"โš ๏ธ  Visualization failed or was interrupted for {video_path.name}")
            # Still ask if user wants to delete
        
        # Prompt for action
        if args.auto_delete:
            # In auto-delete mode, just keep everything unless explicitly told to delete
            print(f"โœ… Keeping: {video_path.name} (auto-delete mode)")
            kept.append(video_path.name)
            continue
        
        action = prompt_keep_or_delete(video_path)
        
        if action == 'keep':
            print(f"โœ… Keeping: {video_path.name}")
            kept.append(video_path.name)
        
        elif action == 'delete':
            confirm = input(f"โš ๏ธ  Are you sure you want to DELETE {video_path.name}? [y/N]: ").strip().lower()
            if confirm in ['y', 'yes']:
                if delete_video(video_path):
                    deleted.append(video_path.name)
            else:
                print(f"โ†ฉ๏ธ  Deletion cancelled. Keeping: {video_path.name}")
                kept.append(video_path.name)
        
        elif action == 'skip':
            print(f"โญ๏ธ  Skipped: {video_path.name}")
            skipped.append(video_path.name)
        
        elif action == 'quit':
            print("\n๐Ÿ›‘ Quitting batch review...")
            break
    
    # Summary
    print(f"\n{'='*70}")
    print("๐Ÿ“Š REVIEW SUMMARY")
    print(f"{'='*70}")
    print(f"โœ… Kept:    {len(kept)} video(s)")
    print(f"๐Ÿ—‘๏ธ  Deleted: {len(deleted)} video(s)")
    print(f"โญ๏ธ  Skipped: {len(skipped)} video(s)")
    print(f"๐Ÿ“ Total:   {len(videos)} video(s)")
    
    if deleted:
        print(f"\n๐Ÿ—‘๏ธ  Deleted files:")
        for name in deleted:
            print(f"   - {name}")
    
    print(f"{'='*70}\n")


if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        print("\n\nโš ๏ธ  Interrupted by user. Exiting...")
        sys.exit(0)