"""MusicIndexer pipeline CLI. Everything is incremental and DB-backed (see Env.database_url). Typical flow: python main.py ingest # load prefetched data into the DB (upsert) python main.py enrich # resolve recording MBIDs (resumable, cached) python main.py match # print present/missing summary ./gui.sh # browse what you're missing `enrich` only queries MusicBrainz for still-unresolved tracks, so re-running it just continues where it stopped. """ import argparse import json from src.db.database import init_db def cmd_init(args): init_db() print("Database initialized.") def cmd_ingest(args): init_db() from src.ingest.ingest import ingest_all results = ingest_all() for source, (new, updated) in results.items(): print(f"{source:8} +{new} new, {updated} updated") def cmd_enrich(args): init_db() from src.enrich.mbid import resolve_mbids, unresolved_count print(f"unresolved before: {unresolved_count(args.source)}") stats = resolve_mbids(limit=args.limit, source=args.source) print(f"resolved this run: {stats}") print(f"unresolved after: {unresolved_count(args.source)}") def cmd_match(args): from src.match.matcher import summary print(json.dumps(summary(), indent=2)) def build_parser(): parser = argparse.ArgumentParser(prog="musicindexer", description=__doc__) sub = parser.add_subparsers(dest="cmd", required=True) sub.add_parser("init", help="create database tables") sub.add_parser("ingest", help="load prefetched JSON into the DB (upsert)") enrich = sub.add_parser("enrich", help="resolve MBIDs for unresolved tracks") enrich.add_argument("--limit", type=int, default=None, help="cap how many tracks to resolve this run") enrich.add_argument("--source", choices=["spotify", "itunes", "local"], default=None, help="restrict to one source") sub.add_parser("match", help="print present/missing summary") return parser def main(): args = build_parser().parse_args() handlers = { "init": cmd_init, "ingest": cmd_ingest, "enrich": cmd_enrich, "match": cmd_match, } handlers[args.cmd](args) if __name__ == "__main__": main()