from __future__ import annotations import argparse from pathlib import Path from .exact import exact_dedupe from .l2 import acoustic_dedupe from .scanner import scan from .watcher import watch def main() -> None: parser = argparse.ArgumentParser(prog="am-deduper") sub = parser.add_subparsers(dest="cmd", required=True) def add_common(sp): sp.add_argument("root", type=Path) sp.add_argument("--db", type=Path, default=None) sp.add_argument("--dry-run", action="store_true", help="report actions without changing files") add_common(sub.add_parser("scan")) add_common(sub.add_parser("dedupe")) add_common(sub.add_parser("reconcile")) watch_parser = sub.add_parser("watch") watch_parser.add_argument("root", type=Path) watch_parser.add_argument("--db", type=Path, default=None) watch_parser.add_argument("--l2", action="store_true", help="enable acoustic matching in the watcher") args = parser.parse_args() db = args.db or (Path("/data/dedupe.db") if args.cmd != "watch" and str(args.root).startswith("/music/") else args.root / ".dedupe" / "dedupe.db") if args.cmd == "watch": watch(args.root, db, l2=args.l2) return indexed = scan(args.root, db) print(f"indexed={indexed} db={db}") if args.cmd == "scan": return exact = exact_dedupe(db, args.root, dry_run=args.dry_run) print(f"exact_hardlinked={len(exact)} dry_run={args.dry_run}") l2 = acoustic_dedupe(db, args.root, dry_run=args.dry_run) print(f"l2={l2} dry_run={args.dry_run}")