DEV Community

l don
l don

Posted on

api tutorial webdev showdev python opensource

I Built a Multi-Platform Video Downloader API in 2 Days

If you've ever needed to programmatically download videos from social media — for content repurposing, analytics, or automation — you know the pain. Every platform has its own quirks, most existing APIs only support one platform, and the good ones are expensive.

So I built my own. Here's what I learned.

The Problem

I needed to extract video URLs from multiple platforms:

  • YouTube Shorts (no login needed)
  • TikTok / Douyin
  • Instagram Reels
  • Bilibili

What I found on the market:

  • Single-platform APIs: great for one use case, useless if you need more
  • Expensive all-in-one tools: $50-100/month for basic access
  • Open-source tools like yt-dlp: powerful but not API-friendly

The Solution

A single API endpoint that handles 10+ platforms. Built with:

  • FastAPI — async Python, auto-generated docs
  • yt-dlp — battle-tested extraction engine
  • Docker + Render — $0 hosting for the first 50k requests
# Core extraction — dead simple
def _extract(url: str) -> dict:
    with yt_dlp.YoutubeDL({"quiet": True, "format": "best"}) as ydl:
        info = ydl.extract_info(url, download=False)
    return {
        "title": info["title"],
        "url": info["url"],
        "thumbnail": info["thumbnail"],
        # ...more metadata
    }
Enter fullscreen mode Exit fullscreen mode

API Usage

curl -X POST https://video-downloader-api-eyqj.onrender.com/extract \
  -H "Content-Type: application/json" \
  -d '{"url":"https://www.youtube.com/shorts/dQw4w9WgXcQ"}'
Enter fullscreen mode Exit fullscreen mode

Returns:

{
  "success": true,
  "data": {
    "title": "Rick Astley - Never Gonna Give You Up",
    "url": "https://manifest.googlevideo.com/...",
    "duration": 213,
    "view_count": 1786552159
  }
}
Enter fullscreen mode Exit fullscreen mode

What Works (and What Doesn't)

Platform Status Notes
YouTube Great Shorts + regular, no auth
Instagram Works Needs cookies for some content
TikTok Tricky Server IPs get blocked, exploring proxy rotation
Bilibili Works Some anti-bot measures
Douyin Works Requires browser cookies

Lessons Learned

1. yt-dlp is a beast. It handles 1800+ sites. Wrapping it in FastAPI took 30 lines of code. The real work was error handling — each platform fails differently.

2. Geo-restrictions are the silent killer. TikTok blocked my Render server IP immediately. If you're building a public API, budget for proxy infrastructure from day one.

3. Cookie support is essential. Chinese platforms (Douyin, Xiaohongshu) require fresh browser cookies. I added a X-Cookie header that accepts Netscape-format cookies exported from the browser.

4. Free hosting is possible for MVPs. Render's free tier + Docker auto-deploy means I pay $0 while validating the idea.

What's Next

  • Proxy rotation for TikTok support
  • Webhook support (notify when video is ready)
  • Direct S3 upload (store the extracted video)

Try It

The API is available on RapidAPI with a free tier (50 requests/month):

[https://rapidapi.com/ldspn115/api/multi-platform-video-downloader]

Source code on GitHub: [https://github.com/ldspn115-ctrl/video-downloader-api]


Built this in a weekend. Feedback and feature requests welcome in the comments!

Tags: #api #tutorial #webdev #showdev #python #opensource

Top comments (0)