A production-ready IPTV proxy system with automatic failover, source recovery, and Xtream Codes support.
NEW: This project now features a high-performance Go (Golang) implementation alongside the original Python version. The Go version is highly recommended for production due to its massive concurrency improvements, reduced CPU/Memory usage, and seamless buffer handling.
- Multi-Source Failover: Automatically tries multiple IPTV sources when one fails
- Automatic Fallback: Shows a "channel unavailable" video when all sources fail
- Source Recovery: Periodically checks failed sources and automatically switches back when they recover
- Xtream Codes Support: Full API integration with Xtream providers
- TVHeadend Integration: Monitors active subscriptions and manages streams efficiently
- Smart Retries: Immediately retries failed sources up to 3 times before falling back.
- H264 Error Handling: Gracefully handles corrupted video frames
- Timestamp Correction: Prevents freezing and audio/video desync
- Packet Validation: Discards corrupt packets instead of crashing
- REST API: Full control via HTTP endpoints
- Real-time Monitoring: Track active streams, clients, and fallback status
- Web Interface: Optional UI for easy management (
index.html) - Configurable: All settings adjustable via JSON config or API. Includes IP/Domain whitelist.
- FFmpeg is required on the system for both versions.
The Go version is distributed as a single, standalone executable.
- Download the latest release for your architecture from the Releases page.
- Place the binary in your preferred directory.
- Create your configuration file:
cp config.example.json config.json
- Run the proxy:
./proxy_server_linux_amd64
(To build from source, run go build -o proxy_server in the repository root.)
- Ensure Python 3.7+ is installed.
- Install required packages:
pip install flask requests
- Run the proxy:
python3 proxy.py
{
"sources": {
"source_id": [
"http://server:port/live/user/pass/{channel_id}.ts"
]
},
"fallback_mode": false,
"auto_fallback": true,
"allowed_ips": ["127.0.0.1", "192.168.1.5"],
"allowed_domains": ["tvh.yourdomain.com"]
}Note: If both allowed_ips and allowed_domains are empty or omitted, the proxy operates in public mode and accepts all connections.
Network Settings:
- Stream proxy port:
9000 - REST API port:
9005
TVHeadend Settings:
url- TVHeadend server URLusername- TVHeadend usernamepassword- TVHeadend password
Access streams via:
http://your-server:9000/{source_id}/{channel_id}.ts
GET /api/status: Returns active streams, clients, fallback count, and uptimeGET /api/config,POST /api/config: Manage configurationGET /api/sources,POST /api/sources,DELETE /api/sources/{source_id}: Manage sourcesDELETE /api/streams/{source_id}:{channel_id}: Stop a streamPOST /api/fallback: Toggle manual fallback modePOST /api/auto-fallback: Toggle automatic fallbackGET /api/xtream/providers...: Various endpoints for Xtream API integration
Create /etc/systemd/system/iptv-proxy.service:
[Unit]
Description=IPTV Stream Proxy
After=network.target
[Service]
Type=simple
User=your-user
WorkingDirectory=/path/to/tvheadend
ExecStart=/path/to/tvheadend/proxy_server_linux_amd64
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetEnable and start:
sudo systemctl enable iptv-proxy
sudo systemctl start iptv-proxyFeel free to submit issues and enhancement requests!