import socketio import time import sys def test_download_progress(): # Connect to the backend sio = socketio.Client() @sio.event def connect(): print('Connected to backend') # Send a download request sio.emit('download', { 'url': 'https://open.spotify.com/track/4uLU6hMCjMI75M1A2tKUQ3', 'name': 'Test Track', 'type': 'track', 'artist': 'Test Artist' }) print('Download request sent') @sio.event def disconnect(): print('Disconnected from backend') @sio.event def update_status(data): print(f'Progress update received: {data}') history = data.get('history', []) if history: latest = history[-1] print(f"Status: {latest.get('status')}, Progress: {latest.get('progress')}%") # Check if download is complete if latest.get('status') == 'Complete': print('Download completed successfully!') sio.disconnect() sys.exit(0) elif latest.get('status') == 'Failed': print('Download failed!') sio.disconnect() sys.exit(1) try: sio.connect('http://localhost:5140') sio.wait() except Exception as e: print(f'Connection error: {e}') if __name__ == '__main__': test_download_progress()