A Flask-based TikTok video downloader API deployed on Google Cloud Run with Ubuntu 22.04 and Python 3.12.
- π₯ Download TikTok videos in various formats
- π Web interface and REST API
- π± Mobile-friendly responsive design
- βοΈ Cloud-native deployment on Google Cloud Run
- π³ Containerized with Docker
- π Auto-scaling and serverless
- Base Image: Ubuntu 22.04
- Python Version: 3.12
- Web Framework: Flask
- WSGI Server: Gunicorn
- Video Downloader: yt-dlp
- Platform: Google Cloud Run
- Google Cloud Account with billing enabled
- Google Cloud SDK installed and configured
- Docker installed on your local machine
- Git for version control
git clone <your-repo-url>
cd "cloud run"# Create a new project (optional)
gcloud projects create your-project-id
# Set the project
gcloud config set project your-project-id
# Enable required APIs
gcloud services enable cloudbuild.googleapis.com
gcloud services enable run.googleapis.com
gcloud services enable containerregistry.googleapis.com.\deploy.ps1 -ProjectId "your-actual-project-id"chmod +x deploy.sh
./deploy.sh your-actual-project-idgcloud builds submit --config cloudbuild.yaml# Build and push the image
docker build -t gcr.io/your-project-id/tiktok-downloader .
docker push gcr.io/your-project-id/tiktok-downloader
# Deploy to Cloud Run
gcloud run deploy tiktok-downloader \
--image gcr.io/your-project-id/tiktok-downloader \
--region us-central1 \
--platform managed \
--allow-unauthenticated \
--port 8080 \
--memory 2Gi \
--cpu 2 \
--timeout 3600 \
--max-instances 10 \
--min-instances 0 \
--concurrency 80GET /- Web interface for downloading videos
GET /api- API informationGET /health- Health checkPOST /download- Download TikTok videoPOST /metadata- Get video metadataGET /formats- Get available formats
# Download a video
curl -X POST https://your-service-url/download \
-H "Content-Type: application/json" \
-d '{"url": "https://www.tiktok.com/@username/video/1234567890"}'
# Get video metadata
curl -X POST https://your-service-url/metadata \
-H "Content-Type: application/json" \
-d '{"url": "https://www.tiktok.com/@username/video/1234567890"}'PORT: Server port (default: 8080)PYTHONUNBUFFERED: Python output buffering (set to 1)
- Memory: 2 GiB
- CPU: 2 vCPU
- Timeout: 3600 seconds (1 hour)
- Max Instances: 10
- Min Instances: 0 (scales to zero)
- Concurrency: 80 requests per instance
.
βββ app.py # Main Flask application
βββ requirements.txt # Python dependencies
βββ Dockerfile # Docker configuration
βββ .dockerignore # Docker ignore file
βββ cloudbuild.yaml # Google Cloud Build configuration
βββ deploy.sh # Bash deployment script
βββ deploy.ps1 # PowerShell deployment script
βββ README.md # This file
βββ templates/
β βββ index.html # Web interface template
βββ downloads/ # Downloaded files directory
- Flask 2.3.3 - Web framework
- yt-dlp - Video downloader
- gunicorn 21.2.0 - WSGI server
- requests - HTTP library
- Other dependencies - See requirements.txt
- β No hardcoded secrets
- β Proper error handling
- β Input validation
- β Rate limiting via Cloud Run
- β HTTPS by default
- β Container security best practices
- Cloud Logging: Automatic log collection
- Cloud Monitoring: Built-in metrics
- Health Checks:
/healthendpoint - Error Tracking: Automatic error reporting
-
403 Forbidden Errors
- The app includes proper headers and user agents to avoid TikTok blocking
- If issues persist, check TikTok's rate limiting
-
Memory Issues
- Increase memory allocation in Cloud Run settings
- Current setting: 2 GiB should handle most videos
-
Timeout Issues
- Large videos may take time to download
- Current timeout: 3600 seconds (1 hour)
-
Build Failures
- Ensure Docker is running
- Check internet connection for package downloads
- Verify Google Cloud permissions
# View recent logs
gcloud logs read --service=tiktok-downloader --limit=50
# Stream logs in real-time
gcloud logs tail --service=tiktok-downloader- Scales to Zero: No charges when not in use
- Pay per Request: Only pay for actual usage
- Efficient Resource Usage: Optimized container size
- Auto-scaling: Handles traffic spikes efficiently
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License.
For issues and questions:
- Check the troubleshooting section
- Review Google Cloud Run documentation
- Open an issue in the repository
Note: This application is for educational purposes. Please respect TikTok's terms of service and copyright laws when using this tool.