#!/usr/bin/env python3 """ Test the actual production version running on port 6544 to see exactly how downloads work in the version that was successful. """ import socketio import time import json import os import glob def test_production_download(): """Test the production version's complete download flow""" print("šŸŽ­ TESTING ACTUAL PRODUCTION VERSION") print("=" * 60) print("Testing the REAL production version (port 6544) that worked for weeks") print("This will show us exactly how downloads should work!") print() # Create a Socket.IO client sio = socketio.Client() # Track the process search_results = None download_updates = [] download_completed = False @sio.event def connect(): print("āœ… Connected to production version") @sio.event def disconnect(): print("āŒ Disconnected from production version") @sio.event def search_results(data): nonlocal search_results search_results = data print(f"šŸ” Search results received: {len(data.get('results', []))} items") if data.get('results'): first = data['results'][0] print(f" šŸ“€ First result: '{first.get('name')}' by '{first.get('artist')}'") print(f" šŸ†” Spotify ID: {first.get('id', 'MISSING!')}") print(f" šŸ”— URL: {first.get('url')}") @sio.event def update_status(data): nonlocal download_updates, download_completed download_updates.append(data) print(f"šŸ“„ Download status update:") 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}") if status in ['Complete', 'Failed', 'Error', 'completed', 'failed']: download_completed = True print(f" šŸŽÆ Download finished with status: {status}") @sio.event def download_progress(data): nonlocal download_updates download_updates.append(data) print(f"šŸ“ˆ Download progress: {data}") try: # Step 1: Connect print("šŸ”Œ Step 1: Connecting to production version...") sio.connect('http://localhost:6544') time.sleep(2) # Step 2: Search print("\nšŸ” Step 2: Searching for 'you lloyd'...") sio.emit('search', {'query': 'you lloyd', 'type': 'track'}) time.sleep(4) if not search_results or not search_results.get('results'): print("āŒ No search results - cannot proceed") return False # Step 3: Get download target info target_song = search_results['results'][0] song_name = target_song.get('name', 'Unknown') artist_name = target_song.get('artist', 'Unknown') print(f"\nšŸŽÆ Step 3: Target song selected:") print(f" Song: {song_name}") print(f" Artist: {artist_name}") print(f" ID: {target_song.get('id', 'MISSING!')}") # Step 4: Check current files before download print(f"\nšŸ“ Step 4: Checking existing files before download...") music_dir = "/Volumes/Jellyfin Media/Music" # Look for existing files with this artist/song existing_files_before = [] if os.path.exists(music_dir): # Search for files containing the artist name search_pattern = f"{music_dir}/**/*{artist_name}*" existing_files_before = glob.glob(search_pattern, recursive=True) print(f" Found {len(existing_files_before)} existing files with '{artist_name}' in path") # Step 5: Trigger download using the production version's expected format print(f"\nšŸ”½ Step 5: Triggering download...") # Try different download event names that the production version might use download_events = ['download', 'download_item', 'start_download'] for event_name in download_events: print(f" šŸ“¤ Trying event: {event_name}") download_request = { 'url': target_song.get('url'), 'type': 'track', 'name': song_name, 'artist': artist_name, 'id': target_song.get('id') } sio.emit(event_name, download_request) time.sleep(2) # Wait to see if this event works if download_updates: print(f" āœ… Event '{event_name}' triggered a response!") break else: print(" āŒ No download events triggered a response") # Step 6: Wait for download completion print(f"\nā³ Step 6: Waiting for download to complete...") print(" (This may take 30-60 seconds for a real download)") for i in range(90): # Wait up to 90 seconds time.sleep(1) if i % 10 == 0: # Print progress every 10 seconds print(f" ā° Waiting... {i+1}/90 seconds") if download_completed: break # Step 7: Check for new files print(f"\nšŸ“ Step 7: Checking for new files after download...") if os.path.exists(music_dir): # Search for files containing the artist name search_pattern = f"{music_dir}/**/*{artist_name}*" existing_files_after = glob.glob(search_pattern, recursive=True) new_files = [f for f in existing_files_after if f not in existing_files_before] print(f" Files before: {len(existing_files_before)}") print(f" Files after: {len(existing_files_after)}") print(f" New files: {len(new_files)}") if new_files: print(f" šŸŽ‰ NEW FILES CREATED:") for new_file in new_files: file_size = os.path.getsize(new_file) if os.path.exists(new_file) else 0 print(f" šŸ“„ {new_file}") print(f" Size: {file_size:,} bytes ({file_size/1024/1024:.1f} MB)") return True else: print(f" āŒ No new files found") else: print(f" āŒ Music directory doesn't exist: {music_dir}") return download_completed or len(download_updates) > 0 except Exception as e: print(f"šŸ’„ Error during production test: {e}") return False finally: if sio.connected: sio.disconnect() if __name__ == "__main__": print("šŸš€ PRODUCTION VERSION TEST") print("Testing the actual working production version") print("=" * 80) success = test_production_download() print("\n" + "=" * 80) if success: print("āœ… PRODUCTION TEST SUCCESS!") print(" The production version shows how downloads should work.") else: print("āŒ PRODUCTION TEST FAILED") print(" Need to investigate the production version setup.") print("\nThis test shows the exact behavior we need to replicate in the current version.")