File size: 1,405 Bytes
1ac3d64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import argparse, re
from pathlib import Path

IMG_EXTS = {".jpg", ".jpeg", ".png", ".bmp", ".webp"}
NUM_RE = re.compile(r"^\d+$")  # stem must be only digits

def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--root", required=True)
    ap.add_argument("--dry_run", action="store_true", help="Only print what would be deleted")
    args = ap.parse_args()

    root = Path(args.root)
    to_delete = []

    for cls in ["real", "fake"]:
        cls_dir = root / cls
        if not cls_dir.exists():
            continue
        for vid_dir in cls_dir.iterdir():
            if not vid_dir.is_dir():
                continue
            for p in vid_dir.iterdir():
                if not p.is_file():
                    continue
                if p.suffix.lower() not in IMG_EXTS:
                    continue
                if not NUM_RE.match(p.stem):
                    to_delete.append(p)

    print(f"Found {len(to_delete)} non-numbered frames to delete.")
    for p in to_delete[:30]:
        print("DEL", p)
    if len(to_delete) > 30:
        print("...")

    if args.dry_run:
        print("Dry-run only. No files deleted.")
        return

    for p in to_delete:
        try:
            p.unlink()
        except Exception as e:
            print("FAILED", p, e)

    print("Done.")

if __name__ == "__main__":
    main()