import json import os from pathlib import Path def add_supports(file_path): """Add supportsAnymex and supportsTsumi to JSON files""" try: with open(file_path, 'r', encoding='utf-8') as f: data = json.load(f) # Check if this is a nested object (like in index.json) if isinstance(data, dict): modified = False # Check if it's a single source entry if 'supportsDartotsu' in data or 'supportsSora' in data: if data.get('supportsDartotsu') == True and 'supportsAnymex' not in data: data['supportsAnymex'] = True modified = True if data.get('supportsSora') == True and 'supportsTsumi' not in data: data['supportsTsumi'] = True modified = True # Check if it's index.json with multiple entries else: for key, value in data.items(): if isinstance(value, dict): if 'supportsDartotsu' in value: if value.get('supportsDartotsu') == True and 'supportsAnymex' not in value: value['supportsAnymex'] = True modified = True if 'supportsSora' in value: if value.get('supportsSora') == True and 'supportsTsumi' not in value: value['supportsTsumi'] = True modified = True if modified: with open(file_path, 'w', encoding='utf-8') as f: json.dump(data, f, indent=2, ensure_ascii=False) return True, "Modified" else: return False, "No changes needed" except Exception as e: return False, f"Error: {str(e)}" # Get the script directory script_dir = Path(__file__).parent # Process all JSON files print("Processing JSON files...") print("=" * 60) # Process index.json index_file = script_dir / "index.json" if index_file.exists(): success, msg = add_supports(index_file) print(f"index.json: {msg}") # Process all subdirectory JSON files for json_file in script_dir.rglob("*.json"): # Skip index.json as we already processed it if json_file.name == "index.json" and json_file.parent == script_dir: continue success, msg = add_supports(json_file) if success: print(f"✓ {json_file.relative_to(script_dir)}: {msg}") print("=" * 60) print("Done!")