A production-ready REST API and web interface for downloading Facebook videos with audio support. Built with FastAPI, yt-dlp, and modern web technologies for reliable video extraction and processing.
- Overview
- Features
- Live Demo
- Technical Architecture
- Installation
- Usage
- API Documentation
- Deployment
- Project Evolution
- Contributing
- License
This project provides a robust solution for downloading Facebook videos programmatically. The system handles Facebook's complex video streaming formats, including DASH streams that require audio and video merging, making it suitable for both developers and end-users.
Facebook videos often use separate audio and video streams (DASH format), making direct downloads challenging. This API automatically detects and merges these streams using FFmpeg, ensuring downloaded videos include both audio and video components.
- Video Download: Extract and download Facebook videos in multiple quality options
- Audio Merging: Automatic handling of DASH streams with audio/video synchronization
- Format Support: MP4 output with quality selection (360p, 720p, 1080p, best, worst)
- URL Flexibility: Support for various Facebook URL formats including fb.watch short links
- RESTful API: Clean HTTP API with comprehensive endpoint documentation
- Rate Limiting: Built-in protection against abuse (10 requests per 60 seconds per IP)
- Error Handling: Detailed error responses with actionable user guidance
- Web Interface: Responsive frontend for non-technical users
- Docker Support: Containerized deployment with all dependencies included
best: Highest available quality with audioworst: Lowest quality for faster downloads360p,720p,1080p: Specific resolution targets- Automatic fallback to best available quality if requested resolution unavailable
Web Interface: https://fdown.isuru.eu.org
API Documentation: https://fdown.isuru.eu.org/docs
GitHub Pages: https://sh13y.github.io/Facebook-Video-Download-API
curl -X POST "https://fdown.isuru.eu.org/info" \
-H "Content-Type: application/json" \
-d '{"url": "YOUR_FACEBOOK_VIDEO_URL"}'- FastAPI: Modern Python web framework for API development
- yt-dlp: Robust video extraction library with Facebook support
- FFmpeg: Video processing for stream merging and format conversion
- Pydantic: Data validation and serialization
- aiohttp: Asynchronous HTTP client for URL resolution
- Vanilla JavaScript: Lightweight, dependency-free frontend
- Tailwind CSS: Utility-first CSS framework for responsive design
- Responsive Design: Mobile-first approach supporting all screen sizes
- Docker: Containerization with multi-stage builds
- Render: Production hosting with automatic deployments
- GitHub Actions: CI/CD pipeline for documentation and testing
- Python 3.11 or higher
- FFmpeg installed on system
- Git for cloning the repository
# Clone the repository
git clone https://github.com/sh13y/Facebook-Video-Download-API.git
cd Facebook-Video-Download-API
# Build and run with Docker Compose
docker-compose up -d
# Access the application
# Web Interface: http://localhost:8000
# API Documentation: http://localhost:8000/docs# Clone the repository
git clone https://github.com/sh13y/Facebook-Video-Download-API.git
cd Facebook-Video-Download-API
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run the application
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000Ubuntu/Debian:
sudo apt update && sudo apt install ffmpegmacOS:
brew install ffmpegWindows: Download from FFmpeg official website or use package managers like Chocolatey.
- Navigate to the web interface at
http://localhost:8000 - Paste a Facebook video URL in the input field
- Select desired video quality
- Click "Download Video" to process and download
curl -X POST "http://localhost:8000/info" \
-H "Content-Type: application/json" \
-d '{
"url": "https://www.facebook.com/watch/?v=1234567890",
"quality": "best"
}'curl -X POST "http://localhost:8000/download" \
-H "Content-Type: application/json" \
-d '{
"url": "https://www.facebook.com/watch/?v=1234567890",
"quality": "720p"
}'The API accepts various Facebook URL formats:
https://www.facebook.com/watch/?v=1234567890
https://facebook.com/username/videos/1234567890
https://m.facebook.com/watch/?v=1234567890
https://fb.watch/ABC123/
https://www.facebook.com/reel/1234567890
Note: For fb.watch URLs, if processing fails, copy the full Facebook URL after the redirect for better reliability.
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Web interface |
| GET | /health |
Health check |
| POST | /info |
Get video information |
| POST | /download |
Download video |
| GET | /qualities |
List supported qualities |
| GET | /stream/{video_id} |
Stream video file |
Success Response:
{
"status": "success",
"video_info": {
"title": "Video Title",
"duration": 120,
"thumbnail": "https://example.com/thumb.jpg",
"uploader": "Page Name",
"view_count": 1000,
"upload_date": "20240101"
},
"download_url": "https://example.com/video.mp4",
"available_formats": [...]
}Error Response:
{
"status": "error",
"message": "Invalid Facebook URL provided",
"error_code": "INVALID_REQUEST"
}- Limit: 10 requests per 60 seconds per IP address
- Headers: Rate limit information included in response headers
- Behavior: Returns 429 status code when limit exceeded
- Fork this repository
- Connect your GitHub account to Render
- Create a new Web Service
- Connect your forked repository
- Render will automatically deploy using the included
render.yaml
# Optional: Set debug mode
DEBUG=false
# Optional: Custom port
PORT=8000# Build the image
docker build -t facebook-video-downloader .
# Run the container
docker run -p 8000:8000 facebook-video-downloaderThis project evolved through several phases, each addressing specific technical challenges and user needs:
Challenge: Basic video extraction without audio
- Implemented yt-dlp integration for Facebook video extraction
- Discovered Facebook's DASH stream architecture separating audio/video
- Solution: Integrated FFmpeg for automatic stream merging
Challenge: Making the API accessible to non-technical users
- Developed responsive web interface using Tailwind CSS
- Implemented real-time feedback and error handling
- Solution: Progressive enhancement with mobile-first design
Challenge: Supporting Facebook's diverse URL formats
- Researched Facebook's URL structure variations
- Implemented comprehensive regex patterns for URL validation
- Solution: Built URL normalization system handling redirects
Challenge: Deploying a reliable service for public use
- Implemented rate limiting and error handling
- Added comprehensive logging and monitoring
- Solution: Containerized deployment with auto-scaling capabilities
Challenge: Providing clear documentation and testing capabilities
- Created comprehensive API documentation
- Built interactive testing interface
- Solution: Multi-format documentation with live examples
| Component | Status | Description |
|---|---|---|
| Core API | Production Ready | Stable video extraction with error handling |
| Web Interface | Production Ready | Responsive design supporting all devices |
| Documentation | Complete | API docs, deployment guides, troubleshooting |
| Deployment | Automated | Docker containers with CI/CD pipeline |
| Testing | Interactive | Live API testing through documentation |
Contributions are welcome! Please read our contributing guidelines:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
# Install development dependencies
pip install -r requirements.txt
# Run tests
python -m pytest
# Run with auto-reload for development
uvicorn app.main:app --reload- Follow PEP 8 for Python code
- Use type hints for all function parameters and return values
- Write descriptive commit messages
- Include tests for new features
This project is licensed under the WTFPL (Do What The F*** You Want To Public License) - see the LICENSE file for details.
- yt-dlp: Robust video extraction library
- FastAPI: Modern Python web framework
- FFmpeg: Video processing capabilities
- Tailwind CSS: Utility-first CSS framework
Built by sh13y
For questions, issues, or contributions, please visit the GitHub repository.
curl -L https://fly.io/install.sh | shflyctl launch
flyctl deploy
# Using Netlify CLI
npm install -g netlify-cli
netlify login
netlify deploy --prod --dir=static --functions=netlify/functions"So simple, your grandma could use it!"
- Visit
http://localhost:8000(or your live demo) - Paste that Facebook video URL you've been hoarding
- Pick your quality (360p for data-savers, 1080p for perfectionists)
- Click "Download Video"
- Profit! ๐ฐ (Well, more like... enjoy your video)
"Because sometimes you need to download 1000 cat videos programmatically"
curl -X POST "http://localhost:8000/download" \
-H "Content-Type: application/json" \
-d '{
"url": "https://www.facebook.com/share/v/17GS54EKBN/",
"quality": "best"
}'{
"status": "success",
"video_info": {
"title": "Cats Being Cats for 5 Minutes Straight",
"duration": 300,
"thumbnail": "https://beautiful-cat-thumbnail.jpg",
"uploader": "CatLoversPro",
"view_count": 5000000
},
"download_url": "https://your-video-is-here.mp4",
"available_formats": ["360p", "720p", "1080p"]
}| ๐ Method | ๐ค๏ธ Endpoint | ๐ญ What It Does | ๐ Cool Factor |
|---|---|---|---|
| GET | / |
Web interface | โญโญโญโญโญ |
| POST | /download |
Download video | โญโญโญโญโญ |
| POST | /info |
Just the facts, ma'am | โญโญโญโญ |
| GET | /qualities |
Available quality options | โญโญโญ |
| GET | /health |
"Are you alive?" | โญโญ |
| GET | /docs |
Interactive API playground | โญโญโญโญโญ |
Pro tip: The /docs endpoint is where the real fun happens - interactive API testing! ๐ฎ
"Tweak it 'til it's perfect!"
Environment variables you can play with:
# Server Settings (The Basics)
HOST=0.0.0.0 # Listen everywhere
PORT=8000 # Your favorite port
DEBUG=false # Keep it cool in production
# Rate Limiting (Anti-Spam Shield)
RATE_LIMIT_REQUESTS=10 # 10 requests...
RATE_LIMIT_WINDOW=60 # ...per minute (be nice!)
# Download Settings (The Good Stuff)
DOWNLOAD_TIMEOUT=30 # 30 seconds to download or bust"We speak all dialects of Facebook!"
โ What Works:
https://www.facebook.com/user/videos/123456789/https://www.facebook.com/share/v/abc123/https://www.facebook.com/watch/?v=123456789https://fb.watch/abc123/(The short and sweet ones)
โ What Doesn't Work:
- Private videos (Sorry, no hacking here!)
- Live streams (They're... still live)
- Videos from pages you can't access (Facebook's rules, not ours)
"Every developer's favorite section!" ๐
๐ฏ Solution: We already fixed this! Facebook's sneaky DASH streaming separates video and audio.
What We Did:
- Before: Videos came out mute (like a sad mime)
- After: Perfect video+audio harmony (like a beautiful symphony)
- Magic: Our format selector automatically merges both streams
# The hero code that saved the day:
'format': 'best[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'๐ฏ Solution: Your yt-dlp needs a coffee break (aka update)
pip install --upgrade yt-dlp
# Sometimes YouTube changes their API, we adapt๐ฏ Solution: Install the video processing Swiss Army knife
# Ubuntu/Debian (The Penguins)
sudo apt install ffmpeg
# macOS (The Apple Way)
brew install ffmpeg
# Windows (The Scenic Route)
# Download from https://ffmpeg.org/download.html๐ฏ Possible Causes:
- Facebook's servers are having a bad day
- Your internet is actually from 2005
- The video is 4K and massive
- Planetary alignment is off
๐ฏ Solutions:
- Try a lower quality setting
- Check your internet connection
- Wait for Mercury to stop being in retrograde
- Consider downloading smaller videos first
Windows - Download from https://ffmpeg.org/
๐ฏ Solution: Patience, young grasshopper! Wait 60 seconds and try again. Our rate limiter protects the server from overzealous downloading sprees
๐ฏ Solution: Make sure you're using a direct video URL, not a post link
- โ
Good:
https://www.facebook.com/watch/?v=123456789 - โ Bad:
https://www.facebook.com/user/posts/123456789
Want to see what's happening under the hood?
export DEBUG=true
python -m app.main
# Now you'll see ALL the things!"How the sausage is made"
๐ Facebook-Video-Download-API/
โโโ ๐ app/
โ โโโ main.py # The FastAPI magic happens here
โ โโโ config.py # All the boring settings
โ โโโ models.py # Data structures (Pydantic models)
โ โโโ services/
โ โ โโโ video_service.py # The video downloading wizard
โ โโโ utils/
โ โโโ rate_limiter.py # The "calm down" enforcer
โ โโโ validators.py # The URL quality checker
โโโ ๐ static/
โ โโโ index.html # Pretty web interface
โ โโโ script.js # Frontend JavaScript magic
โโโ ๐ณ docker-compose.yml # One-click deployment
โโโ ๐ฆ Dockerfile # Container recipe
โโโ ๐ requirements.txt # Python shopping list
"Because sharing is caring, but having your own is cooler!"
- ๐ด Fork this repository to your GitHub
- ๐ Sign up at Render with GitHub
- โ Create a new Web Service โ Connect your forked repo
- โ๏ธ Configure these settings:
- Build Command:
pip install -r requirements.txt - Start Command:
uvicorn app.main:app --host 0.0.0.0 --port $PORT - Environment Variables:
DEBUG=false(Keep it professional)PYTHON_VERSION=3.11.9(The good stuff)
- Build Command:
- ๐ Deploy and be live in ~5 minutes!
Pro tip: Render's free tier is perfect for personal use and small projects!
"All contributions welcome - from typo fixes to feature additions!"
- ๐ด Fork the repo
- ๐ฟ Branch it (
git checkout -b feature/MyAwesomeFeature) - โจ Code your magic
- ๐พ Commit with style (
git commit -m 'Add some MyAwesomeFeature') - ๐ Push it (
git push origin feature/MyAwesomeFeature) - ๐ฏ PR it (Open a Pull Request)
Don't forget to add tests if you're feeling fancy! ๐งช
This project is licensed under WPFTL (WTFPL) - see the LICENSE file for details.
๐ TL;DR: Do whatever you want with this code! Build it, break it, sell it, frame it - we don't mind!
"Standing on the shoulders of giants (and caffeinated developers)"
- yt-dlp - The Swiss Army knife of video downloading โ๏ธ
- FastAPI - The web framework that makes APIs fun again ๐
- Tailwind CSS - Making things pretty without the CSS nightmares ๐จ
- ffmpeg - The video processing wizard behind the curtain ๐งโโ๏ธ
- Coffee โ - The real MVP
"Need help? We've got your back!"
- ๐ Found a Bug? โ GitHub Issues
- ๐ฌ Want to Chat? โ GitHub Discussions
- ๐ง Direct Contact โ GitHub Profile
- ๐ Read the Docs โ Check out our documentation files above!
Response time: Usually faster than your pizza delivery! ๐
"Our journey to GitHub stardom (one โญ at a time)"
Created by sh13y
If this project saved you from manually downloading videos one by one,
show some love with a โญ and maybe buy me a virtual tea! ๐ต
Fun Fact: This entire project was built because downloading Facebook videos
shouldn't require a PhD in Computer Science! ๐
