#!/usr/bin/env python3 """Utility to register a manually generated ALS file in the MusiaIA project metadata store.""" import argparse import json import os import uuid from pathlib import Path PROJECTS_DIR = Path('/home/ren/musia/output/projects') PROJECTS_DIR.mkdir(parents=True, exist_ok=True) def main(): parser = argparse.ArgumentParser(description='Register an ALS project for the MusiaIA dashboard.') parser.add_argument('--user', required=True, help='User ID (must match the one used in the UI)') parser.add_argument('--name', required=True, help='Project name to display') parser.add_argument('--file', required=True, help='Path to the ALS file') parser.add_argument('--genre', default='Unknown', help='Genre label (optional)') parser.add_argument('--bpm', type=int, default=120, help='BPM value (optional)') parser.add_argument('--key', default='C', help='Key signature (optional)') parser.add_argument('--project-id', help='Optional custom project ID (otherwise auto)') args = parser.parse_args() file_path = Path(args.file).expanduser().resolve() if not file_path.exists(): raise SystemExit(f'ALS file not found: {file_path}') project_id = args.project_id or str(uuid.uuid4())[:8] metadata = { 'id': project_id, 'user_id': args.user, 'name': args.name, 'genre': args.genre, 'bpm': args.bpm, 'key': args.key, 'file_path': str(file_path), 'download_url': f'/api/download/{project_id}' } metadata_path = PROJECTS_DIR / f'{project_id}.json' with open(metadata_path, 'w', encoding='utf-8') as fh: json.dump(metadata, fh) print(f'Registered {file_path} as project {project_id}') print(f'Metadata: {metadata_path}') if __name__ == '__main__': main()