A FastAPI-based service for downloading YouTube videos with API key authentication. Supports both traditional Python deployment and Docker containerization for easy deployment and scaling.
- π Secure API key authentication
- πΉ Download YouTube videos in various formats
- π Fast downloads using yt-dlp
- π Detailed logging
- π Health check endpoint
- π CORS support
- ποΈ File management (download & delete)
- π¦ List available files for download
- π οΈ Graceful error handling and informative responses
- π³ Docker containerization support
- π Health monitoring and metrics
- π Automatic cleanup and maintenance
- Docker Engine 20.10+ or Docker Desktop
- Docker Compose 2.0+
- At least 2GB available disk space
- Python 3.8 or higher
- Linux/Unix system (for service deployment)
- Sufficient disk space for downloads
-
Clone the repository:
git clone https://github.com/vo1dee/ytdl-service.git cd ytdl-service -
Start with Docker Compose:
# Copy environment template cp .env.example .env # Build and start the service docker-compose up -d # View logs docker-compose logs -f ytdl-service
-
Access the service:
- API: http://localhost:8000
- Health Check: http://localhost:8000/health
- API Documentation: http://localhost:8000/docs
See the Docker Deployment Guide for comprehensive Docker setup instructions, including:
- Basic development setup
- Production deployment with reverse proxy
- Multi-instance load balancing
- Docker Swarm and Kubernetes examples
-
Clone the repository:
git clone https://github.com/vo1dee/ytdl-service.git cd ytdl-service -
Create and activate virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Create required directories:
sudo mkdir -p /opt/ytdl_service/downloads sudo mkdir -p /opt/ytdl_service/logs sudo chown -R $USER:$USER /opt/ytdl_service
To run the YouTube Download Service as a systemd service, create a service file:
-
Create and edit the service file:
sudo nano /etc/systemd/system/ytdl_service.service
-
Add the following content to the file:
[Unit] Description=YouTube Download Service After=network.target [Service] Type=simple User=your_username # Replace with the user that should run the service ExecStart=/path/to/your/venv/bin/python /path/to/your/ytdl-service/download_service.py [Install] WantedBy=multi-user.target
-
Save and exit the editor.
-
Enable and start the service:
sudo systemctl enable ytdl_service sudo systemctl start ytdl_service -
Check the status of the service:
sudo systemctl status ytdl_service
POST /download
X-API-Key: your-api-key
{
"url": "https://www.youtube.com/watch?v=...",
"format": "best" # optional
}GET /files/{filename}
X-API-Key: your-api-keyGET /files
X-API-Key: your-api-keyDELETE /files/{filename}
X-API-Key: your-api-keyGET /health
X-API-Key: your-api-key- API key is auto-generated on first run
- Key location:
/opt/ytdl_service/api_key.txt - All endpoints require authentication
- CORS enabled for specified origins
Service logs are stored in /var/log/ytdl_service.log with the following information:
- Timestamp
- Request method and path
- Response status and duration
- Download progress
- Error details (if any)
- Docker Deployment Guide - Comprehensive Docker setup and deployment instructions
- Docker Examples - Practical examples for different deployment scenarios
- Volume Management and Backup Guide - Data persistence and backup strategies
- Troubleshooting Guide - Common issues and solutions
- Environment Variables - Complete configuration options
- Health Monitoring - Health check and monitoring setup
- iOS Compatibility Guide - iOS-specific download optimizations
The service includes several management scripts for easy operation:
# Build Docker image
./build.sh
# Run container
./run.sh
# Stop container
./stop.sh
# View logs
./logs.sh
# Health check
./health_check.sh# Clone and setup
git clone https://github.com/vo1dee/ytdl-service.git
cd ytdl-service
# Start development environment
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
# View logs
docker-compose logs -f ytdl-service# Clone and setup
git clone https://github.com/vo1dee/ytdl-service.git
cd ytdl-service
python -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Run service
python download_service.py
## Contributing
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## License
MIT