#!/usr/bin/env python3
"""
扫一扫 + 清垃圾
遍历 /mnt/f/collections 和 /mnt/f/video，输出清单并清理空壳/小文件残片
"""
import os, shutil

SRC = ["/mnt/f/collections", "/mnt/f/video"]
MINSIZE = 50 * 1024 * 1024  # 50MB
video_exts = {'.mp4','.mkv','.avi','.mov','.wmv','.flv','.webm','.ts','.m4v','.rmvb'}

targets = []
print("=== 扫描 ===")
for base in SRC:
    if not os.path.isdir(base):
        continue
    for entry in sorted(os.listdir(base)):
        full = os.path.join(base, entry)
        if not os.path.isdir(full):
            continue
        total_sz = 0
        real_video = 0
        try:
            for dp, dn, fn in os.walk(full):
                for f in fn:
                    fp = os.path.join(dp, f)
                    try:
                        total_sz += os.path.getsize(fp)
                    except: pass
                    if os.path.splitext(f)[1].lower() in video_exts:
                        real_video += 1
        except: pass

        action = ""
        if total_sz < MINSIZE and real_video == 0:
            action = "DELETE"
        elif total_sz < MINSIZE and real_video > 0:
            action = "DELETE"
        else:
            action = "KEEP"

        print(f"  [{action:>6}] {entry}  ({total_sz/1024**2:.0f}MB, {real_video}视频)")
        
        if action == "DELETE":
            targets.append(full)

if targets:
    print(f"\n待删除: {len(targets)} 个")
    print("开始删除...")
    for d in targets:
        shutil.rmtree(d)
        print(f"  ✓ 已删: {os.path.basename(d)}")
else:
    print("\n无需清理。")
