Skip to content

fazi-gondal/FastAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Social Media Downloader API

A powerful FastAPI-based video downloader supporting Instagram, TikTok, YouTube, and 1000+ platforms β€” with zero-disk streaming, server-side proxy, and real-time progress tracking.

✨ Features

  • πŸŽ₯ Multi-Platform Support: Download from Instagram, TikTok, YouTube, Facebook, Twitter/X, and 1000+ sites via yt-dlp
  • 🚫 TikTok Without Watermark: HD no-watermark downloads powered by the TikWM API
  • 🎬 Instagram HD Quality: Download Instagram Reels/Posts in 720p+
  • πŸ“Š Real-Time Progress: Live download progress via XHR (web) and expo-file-system (mobile)
  • πŸ“± Mobile Ready: Zero-change React Native/Expo integration β€” works out of the box
  • 🌐 CORS Enabled: Works with web browsers, mobile apps, and Expo Go
  • πŸ”„ Server-Side Stream Proxy: Bypasses TikTok CDN blocking on mobile & mobile web
  • πŸͺ Cookie Support: Bypass YouTube bot detection
  • πŸ—‘οΈ Auto Cleanup: Automatic temp file cleanup after download
  • 🎨 Modern UI: Glassmorphism dark-mode web interface with live progress bar
  • ☁️ Production Ready: Deployed on Render with zero-disk-storage streaming
  • πŸ“₯ Force Download: Content-Disposition: attachment triggers Save-As on all platforms
  • πŸ“ˆ Native Progress: Content-Length headers forwarded from CDN for native mobile progress bars
  • ⚑ Optimized: Single TikWM API call per request (no double fetches)

πŸš€ Quick Start

Installation

git clone https://github.com/fazi-gondal/FastAPI.git
cd FastAPI
pip install -r requirements.txt
python main.py

Server starts at http://localhost:8000

Requirements

  • Python 3.11+
  • FastAPI, uvicorn, httpx, yt-dlp, aiofiles

πŸ“‹ Usage

Web Interface

  1. Open http://localhost:8000
  2. Paste a TikTok, Instagram, YouTube, or any supported video URL
  3. Hit Get Video β€” metadata loads automatically
  4. Download starts with real-time progress bar

API Integration

See API.md for full API documentation.

// Fetch metadata
const res = await fetch('/api/metadata', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ url: 'https://www.tiktok.com/@user/video/123' })
});
const { data } = await res.json();
// { title, thumbnail, duration, uploader, platform }

React Native / Expo Integration

See REACT_NATIVE_INTEGRATION.md for the complete guide.

npx expo install expo-file-system expo-media-library axios

🌐 Deployment

Render (Recommended)

  1. Push to GitHub
  2. Connect repo on Render
  3. Set:
    • Build: pip install -r requirements.txt
    • Start: uvicorn main:app --host 0.0.0.0 --port $PORT

Production URL: https://fastapi-u8bm.onrender.com

See DEPLOYMENT.md for Koyeb and other platforms.

πŸ“Š API Endpoints

Endpoint Method Description
/api/metadata POST Get video title, thumbnail, duration, uploader
/api/get-direct-url POST Resolve download URL (proxy or CDN)
/api/stream GET Server-side proxy stream β€” for TikTok & CDN-blocked platforms
/api/tiktok/info GET Full TikWM data: hdplay, play, wmplay, cover, author, music_info
/api/proxy-stream POST Lightweight CDN proxy (POST variant)
/api/server-stream POST yt-dlp server-download + stream (DASH/merged)
/api/download/start POST Start background download, returns ID
/api/download/progress/{id} GET SSE progress stream
/api/download/file/{id} GET Serve completed download file
/api/thumbnail GET CORS proxy for CDN thumbnails

πŸ” Download Flow Architecture

TikTok (no-watermark HD)

Web/Mobile  β†’  POST /api/get-direct-url
Backend     β†’  TikWM API (hd=1) β€” single call
Backend     ←  { direct_url: "/api/stream?url=...&direct_url=<cdn>" }
Web/Mobile  β†’  GET /api/stream?url=...&direct_url=<cdn>  (fast path, no 2nd API call)
Backend     β†’  Proxy TikWM CDN bytes β†’ Client (with Content-Length)

Instagram

Web/Mobile  β†’  POST /api/get-direct-url  β†’  yt-dlp extracts URL
Backend     ←  { direct_url: "/api/stream?url=..." }
Client      β†’  GET /api/stream  β†’  yt-dlp CDN β†’ Client

YouTube / Twitter / Others

Web/Mobile  β†’  POST /api/get-direct-url  β†’  yt-dlp extracts CDN URL
Backend     ←  { direct_url: "https://cdn.example.com/...", force_backend_stream: true }
Client      β†’  GET /api/stream  β†’  Proxied stream β†’ Client

🎯 Supported Platforms

  • βœ… YouTube (with cookie support)
  • βœ… Instagram (Posts, Reels, IGTV in HD)
  • βœ… TikTok (watermark-free, HD via TikWM API)
  • βœ… Facebook
  • βœ… Twitter/X
  • βœ… Vimeo
  • βœ… Reddit
  • βœ… 1000+ more via yt-dlp

πŸ› οΈ Platform-Specific Features

TikTok

  • TikWM API: hd=1 for HD no-watermark, falls back to play (SD)
  • Zero double-calls: pre-resolved CDN URL embedded in the stream proxy URL
  • Mobile safe: server-side proxy bypasses TikTok CDN CORS blocks on all clients
  • URL formats: tiktok.com, vm.tiktok.com, vt.tiktok.com

Instagram

  • HD quality (720p+), supports Reels, Posts, IGTV
  • CORS thumbnail proxy included
  • Server-side merge for DASH streams

YouTube

  • Best video + audio quality merged (MP4)
  • Cookie support for bot detection bypass

πŸ”§ Configuration

YouTube Cookie Setup (Optional)

  1. Install Get cookies.txt
  2. Export cookies from YouTube.com
  3. Save as cookies.txt in project root
  4. Restart the server

See YOUTUBE_COOKIES.md for details.

πŸ—οΈ Project Structure

FastAPI/
β”œβ”€β”€ main.py              # FastAPI app β€” all endpoints
β”œβ”€β”€ downloader.py        # yt-dlp + TikWM download logic
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ runtime.txt
β”œβ”€β”€ Procfile
β”œβ”€β”€ static/
β”‚   β”œβ”€β”€ index.html       # Glassmorphism dark UI
β”‚   β”œβ”€β”€ style.css
β”‚   └── script.js        # XHR-based download with live progress
└── temp_downloads/      # Auto-cleaned temp files

πŸ”’ Security

  • CORS open for all origins (restrict in production as needed)
  • cookies.txt gitignored
  • Auto temp file cleanup (on startup + after serve)
  • No video data stored beyond TTL

πŸ› Troubleshooting

TikTok returning 500

  • Check server logs β€” likely a CDN token expiry (re-fetch URL)
  • Ensure httpx is up to date: pip install --upgrade httpx

YouTube Bot Detection

See YOUTUBE_COOKIES.md.

Progress Bar Stuck at 0%

TikTok CDN may not return Content-Length (chunked encoding). Progress shows received MB instead of percentage. This is normal.

Video Has No Audio (Instagram)

Use /api/server-stream β€” it runs yt-dlp to merge DASH streams with audio.

πŸ“ Changelog

v2.2.0 (2026-04-06)

  • βœ… Fixed 500 error on /api/stream: replaced invalid await client.stream() with correct await client.send(request, stream=True) (httpx API fix)
  • βœ… Eliminated double TikWM API call: pre-resolved CDN URL embedded in stream URL via direct_url query param
  • βœ… Web frontend TikTok fix: added force_backend_stream routing with XHR-based downloadViaBackendStream() and real progress bar
  • βœ… New /api/tiktok/info endpoint: returns full TikWM data object (hdplay, play, wmplay, cover, author, music_info) for React Native apps
  • βœ… New get_tiktok_info() function in downloader.py
  • βœ… No mobile app changes required β€” backend changes are fully backward-compatible

v2.1.0 (2026-04-01)

  • βœ… TikWM API integration for HD no-watermark TikTok downloads
  • βœ… Mobile stability fixes β€” resolved React Native video crashes
  • βœ… Content-Length headers for native progress bars
  • βœ… Zero-disk streaming for TikTok and Instagram
  • βœ… Content-Disposition: attachment forced on all proxied streams

v2.0.0 (2026-01-02)

  • βœ… Real-time progress tracking with SSE
  • βœ… Three-step download process
  • βœ… YouTube cookie support
  • βœ… Automatic file cleanup
  • βœ… Modern lifespan event handlers

v1.0.0 (2025-12-30)

  • βœ… Initial release β€” multi-platform support, FastAPI backend, glassmorphism UI

🀝 Contributing

PRs welcome! Please open an issue first for major changes.

πŸ“„ License

MIT License β€” see LICENSE.

πŸ‘€ Author

Fazi Gondal

πŸ™ Acknowledgments

  • yt-dlp β€” The amazing video downloader
  • TikWM β€” TikTok no-watermark API
  • FastAPI β€” Modern Python web framework
  • Expo β€” React Native development platform

Made with ❀️ by Fazi Gondal

About

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors