#!/usr/bin/env python3 """ Quick test script for 20 random songs Simple single-threaded approach """ import sys import json import time from pathlib import Path # Add the src directory to the path sys.path.insert(0, '/app') from src.cli.main import MusicBrainzCleaner def main(): print('šŸš€ Starting quick test with 20 random songs...') # Load songs input_file = Path('data/songs.json') if not input_file.exists(): print('āŒ songs.json not found') return with open(input_file, 'r') as f: all_songs = json.load(f) print(f'šŸ“Š Total songs available: {len(all_songs):,}') # Take 20 random songs import random sample_songs = random.sample(all_songs, 20) print(f'šŸŽÆ Testing 20 random songs...') # Initialize cleaner cleaner = MusicBrainzCleaner() # Process songs found_artists = 0 found_recordings = 0 failed_songs = [] start_time = time.time() for i, song in enumerate(sample_songs, 1): print(f' [{i:2d}/20] Processing: "{song.get("artist", "Unknown")}" - "{song.get("title", "Unknown")}"') try: result = cleaner.clean_song(song) artist_found = 'mbid' in result recording_found = 'recording_mbid' in result if artist_found and recording_found: found_artists += 1 found_recordings += 1 print(f' āœ… Found both artist and recording') else: failed_songs.append({ 'original': song, 'cleaned': result, 'artist_found': artist_found, 'recording_found': recording_found, 'artist_name': song.get('artist', 'Unknown'), 'title': song.get('title', 'Unknown') }) print(f' āŒ Artist: {artist_found}, Recording: {recording_found}') except Exception as e: print(f' šŸ’„ Error: {e}') failed_songs.append({ 'original': song, 'cleaned': {'error': str(e)}, 'artist_found': False, 'recording_found': False, 'artist_name': song.get('artist', 'Unknown'), 'title': song.get('title', 'Unknown'), 'error': str(e) }) end_time = time.time() processing_time = end_time - start_time # Calculate success rates artist_success_rate = found_artists / 20 * 100 recording_success_rate = found_recordings / 20 * 100 failed_rate = len(failed_songs) / 20 * 100 print(f'\nšŸ“Š Final Results:') print(f' ā±ļø Processing time: {processing_time:.2f} seconds') print(f' šŸš€ Speed: {20/processing_time:.1f} songs/second') print(f' āœ… Artists found: {found_artists}/20 ({artist_success_rate:.1f}%)') print(f' āœ… Recordings found: {found_recordings}/20 ({recording_success_rate:.1f}%)') print(f' āŒ Failed songs: {len(failed_songs)} ({failed_rate:.1f}%)') # Show failed songs if failed_songs: print(f'\nšŸ” Failed songs:') for i, failed in enumerate(failed_songs, 1): print(f' [{i}] "{failed["artist_name"]}" - "{failed["title"]}"') print(f' Artist found: {failed["artist_found"]}, Recording found: {failed["recording_found"]}') if 'error' in failed: print(f' Error: {failed["error"]}') else: print('\nšŸŽ‰ All songs processed successfully!') if __name__ == '__main__': main()