#!/usr/bin/env python3 """ Compare the working backup (port 6544) vs current broken version (port 5140) This will show us exactly how downloads should work vs how they're failing. """ import socketio import time import json def test_backend(port, name): """Test a backend and return detailed results""" print(f"\n๐Ÿงช TESTING {name} (PORT {port})") print("=" * 60) sio = socketio.Client() results = { 'connected': False, 'search_results': None, 'download_updates': [], 'errors': [] } @sio.event def connect(): results['connected'] = True print(f"โœ… Connected to {name}") @sio.event def disconnect(): print(f"โŒ Disconnected from {name}") @sio.event def search_results(data): results['search_results'] = data print(f"๐Ÿ” Search results: {len(data.get('results', []))} items") # Show first result details if data.get('results'): first = data['results'][0] print(f" First result: '{first.get('name')}' by '{first.get('artist')}'") print(f" Has ID: {'โœ…' if first.get('id') else 'โŒ'} ({first.get('id', 'MISSING')})") print(f" URL: {first.get('url', 'MISSING')}") @sio.event def update_status(data): results['download_updates'].append(data) print(f"๐Ÿ“ฅ Download update: {len(data.get('history', []))} items in history") for item in data.get('history', []): status = item.get('status', 'Unknown') name = item.get('name', 'Unknown') item_id = item.get('id', 'NO-ID') print(f" ๐Ÿ“Š {name} (ID: {item_id}): {status}") try: print(f"๐Ÿ”Œ Connecting to http://localhost:{port}...") sio.connect(f'http://localhost:{port}') time.sleep(2) if not results['connected']: print(f"โŒ Failed to connect to {name}") return results # Test search print(f"๐Ÿ” Searching for 'you lloyd' on {name}...") sio.emit('search', {'query': 'you lloyd', 'type': 'track'}) time.sleep(3) if not results['search_results']: print(f"โŒ No search results from {name}") return results # Test download print(f"๐Ÿ”ฝ Testing download on {name}...") first_result = results['search_results']['results'][0] download_request = { 'url': first_result.get('url'), 'searchResult': first_result, 'name': first_result.get('name'), 'artist': first_result.get('artist'), 'type': first_result.get('type'), 'id': first_result.get('id') } print(f"๐Ÿ“ค Sending download request for: {first_result.get('name')}") sio.emit('download', download_request) # Wait for download progress print(f"โณ Waiting for download progress on {name}...") for i in range(10): time.sleep(1) if results['download_updates']: latest = results['download_updates'][-1] for item in latest.get('history', []): if item.get('status') in ['Complete', 'Failed', 'Error']: print(f" ๐ŸŽฏ Final status: {item.get('status')}") return results print(f" โฐ Timeout on {name}") return results except Exception as e: print(f"๐Ÿ’ฅ Error testing {name}: {e}") results['errors'].append(str(e)) return results finally: if sio.connected: sio.disconnect() def compare_results(working_results, broken_results): """Compare the results and identify differences""" print("\n" + "=" * 80) print("๐Ÿ” COMPARISON ANALYSIS") print("=" * 80) print("\n๐Ÿ“Š CONNECTION:") print(f" Working (6544): {'โœ…' if working_results['connected'] else 'โŒ'}") print(f" Broken (5140): {'โœ…' if broken_results['connected'] else 'โŒ'}") print("\n๐Ÿ” SEARCH RESULTS:") working_count = len(working_results['search_results']['results']) if working_results['search_results'] else 0 broken_count = len(broken_results['search_results']['results']) if broken_results['search_results'] else 0 print(f" Working: {working_count} results") print(f" Broken: {broken_count} results") if working_results['search_results'] and broken_results['search_results']: working_first = working_results['search_results']['results'][0] broken_first = broken_results['search_results']['results'][0] print("\n๐Ÿ†” FIRST RESULT ID COMPARISON:") print(f" Working has ID: {'โœ…' if working_first.get('id') else 'โŒ'} ({working_first.get('id', 'MISSING')})") print(f" Broken has ID: {'โœ…' if broken_first.get('id') else 'โŒ'} ({broken_first.get('id', 'MISSING')})") print("\n๐Ÿ“ฅ DOWNLOAD UPDATES:") print(f" Working: {len(working_results['download_updates'])} updates") print(f" Broken: {len(broken_results['download_updates'])} updates") if working_results['download_updates']: print("\n Working download statuses:") for update in working_results['download_updates']: for item in update.get('history', []): print(f" - {item.get('name', 'Unknown')}: {item.get('status', 'Unknown')}") if broken_results['download_updates']: print("\n Broken download statuses:") for update in broken_results['download_updates']: for item in update.get('history', []): print(f" - {item.get('name', 'Unknown')}: {item.get('status', 'Unknown')}") print("\n๐ŸŽฏ KEY DIFFERENCES IDENTIFIED:") differences = [] if working_results['search_results'] and broken_results['search_results']: working_has_id = bool(working_results['search_results']['results'][0].get('id')) broken_has_id = bool(broken_results['search_results']['results'][0].get('id')) if working_has_id != broken_has_id: differences.append(f" โŒ ID field: Working {'has' if working_has_id else 'missing'} vs Broken {'has' if broken_has_id else 'missing'}") if len(working_results['download_updates']) != len(broken_results['download_updates']): differences.append(f" โŒ Download updates: Working {len(working_results['download_updates'])} vs Broken {len(broken_results['download_updates'])}") if not differences: print(" โœ… No major structural differences found") else: for diff in differences: print(diff) if __name__ == "__main__": print("๐Ÿš€ WORKING vs BROKEN COMPARISON TEST") print("This will test both versions side by side to see the differences") print("=" * 80) # Test working version (port 6544) working_results = test_backend(6544, "WORKING BACKUP") # Test broken version (port 5140) broken_results = test_backend(5140, "CURRENT BROKEN") # Compare results compare_results(working_results, broken_results) print("\n๐ŸŽ‰ COMPARISON COMPLETE!") print("Use the analysis above to identify what needs to be fixed in the current version.")