A Python-based media streaming proxy service that handles multiple channel streams and redirects YouTube/streaming URLs to direct playback links.
Proxy ACE is an asynchronous HTTP proxy server built with aiohttp that:
- Streams IPTV channels - Provides HTTP streaming access to IPTV channels via
/ace/{channel}endpoint - Resolves streaming URLs - Uses
yt-dlpto extract direct playable URLs from YouTube and other streaming services - Manages multiple clients - Handles concurrent client connections with queue-based buffering
- Hot-reloading configuration - Watches
channels.jsonfor changes and syncs automatically - Reconnection logic - Implements exponential backoff retry strategy for upstream connection failures
Create a virtual environment:
python3 -m venv venvActivate it:
source venv/bin/activateInstall dependencies:
pip install -r requirements.txtCheck installed packages:
pip list{
"ace": {
"channel_name": "stream_id_or_hash"
},
"yt-dlp": {
"channel_name": "https://url.to.stream"
}
}- ace section: IPTV channel stream IDs (processed through ACE proxy)
- yt-dlp section: Direct URLs to streaming services (YouTube, X/Twitter, etc.)
python -m proxy_ace.proxy_aceServer listens on port 8081 (configurable in proxy_ace.py)
To run this project as a systemd service, create a unit file:
sudo nano /etc/systemd/system/proxy-ace.servicePaste the following:
[Unit]
Description=My Python Stream Script
After=network.target
[Service]
Type=simple
GuessMainPID=no
WorkingDirectory=/path/to/project
ExecStart=/path/to/project/venv/bin/python -m proxy_ace.proxy_ace
Restart=always
User=daniil
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.targetThen enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable proxy-ace
sudo systemctl start proxy-aceCheck logs:
journalctl -u proxy-ace -f- proxy_ace.py - Main application server with signal handling and file watcher for config changes
- handler.py - HTTP request handlers for client streaming and URL redirection
- producer.py - Upstream connection manager that fetches streams and distributes to clients
- config.py - Configuration loader and
yt-dlpintegration for URL extraction - models.py - Data models for channels, clients, and redirects
- channels.json - Configuration file with channel definitions
Channel- Contains stream URL, connected clients, producer task, and synchronization primitivesRedirectChannel- Maps original URL to extracted playable URL for streaming servicesClient- Represents a connected client with response stream and data queue
GET /ace/{channel}
Returns HLS/MPEG-TS stream for the specified channel. Fails with 404 if channel not found.
GET /yt_dlp/{channel}
Returns 302 redirect to the direct playable URL extracted by yt-dlp. Falls back to placeholder channel if channel not found.
Key dependencies:
aiohttp- Async HTTP server and clientyt-dlp- YouTube and streaming service URL extractionwatchdog- File system monitoring for config changesasyncio- Async/await concurrency
- Queue-based buffering (max 25,000 items per client)
- Auto-drops slow clients when queue fills
- Proper cleanup on disconnection
- Automatic producer task creation per channel
- Stops producer when no active clients
- Handles upstream reconnection with exponential backoff
- Timeout handling with configurable delays
- Automatic config sync on file changes (debounced)
- Full sync every hour
- Graceful handling of missing channels
- Supports adding/removing channels without restart
- Comprehensive logging for debugging
- Automatic client disconnection on errors
- Producer retry logic (up to 3 attempts with exponential backoff)
- Signal handling for graceful shutdown (SIGTERM, SIGINT)
The application logs:
- Client connections/disconnections
- Stream status (started, finished, errors)
- Queue overflow events
- URL extraction progress
- Configuration sync events
- Queue Management - Slow clients are dropped to prevent memory buildup
- Process Pooling -
yt-dlpruns in separate processes to avoid blocking - Async I/O - All network operations are non-blocking
- Resource Cleanup - Proper cleanup of tasks, processes, and connections