Building a Self-Hosted IPTV Web App

Notes on building a personal streaming platform — FastAPI + React, ~10k channels synced from iptv-org, a signed proxy for DRM/header-gated streams, and TMDB movie enrichment.

7 min read

I built myself a personal streaming platform: something that feels like Netflix, YouTube TV, or Plex, but self-hosted and backed by free, publicly available IPTV channel data instead of a subscription. It turned into one of the more technically interesting side projects I’ve built recently, mostly because “just play the video” turned out to have a lot more edge cases than I expected.

The Idea

The iptv-org project maintains a huge, community-curated list of public IPTV streams — news, sports, entertainment, channels from all over the world. The data is there; what’s missing is a decent way to browse and watch it. Most players in this space are either bare M3U playlist apps or clunky legacy interfaces.

So I built a proper web app around it: a FastAPI backend that ingests and serves the catalog, and a React frontend that looks and feels like a real streaming service — browsing, search, favorites, a video player, and a “continue watching” style recent list.

The Stack

LayerTechnology
FrontendReact 19, Vite, TypeScript, Tailwind CSS, React Router, TanStack Query, Zustand, HLS.js
BackendFastAPI, Python 3.12, SQLAlchemy, PostgreSQL, Alembic, Pydantic, Redis
InfraDocker Compose, nginx

Nothing exotic on paper. The interesting decisions came from the nature of the content itself, not the framework choices.

~10,000 Channels, Synced Automatically

On boot, a worker pulls the entire iptv-org catalog — playlists, channel metadata, logos — parses it, and populates Postgres. It runs again on a daily schedule, so the catalog drifts along with upstream without anyone touching the server:

python -m app.workers.run_sync   # pulls ~10k channels, takes about 10 seconds

Channel and category browsing, search, and favorites all read from this local catalog rather than hitting playlist URLs live, which keeps the app fast and means a slow or dead upstream mirror doesn’t take the whole browsing experience down with it — only playback of that specific channel.

The Actual Hard Part: Not Every Stream Just Plays

This is where the project stopped being a CRUD app. Public IPTV streams are inconsistent: most are plain HLS (.m3u8), which HLS.js handles fine. But a meaningful chunk are MPEG-DASH (.mpd), and some of those are:

  • Encrypted with ClearKey DRM
  • Gated behind HTTP headers (Referer, User-Agent, Origin) that a browser can’t set on a fetch it makes directly from the page
  • Occasionally Widevine or PlayReady, which just can’t play in-browser at all and get flagged as unavailable rather than silently failing

Getting this right needed two things: a second player engine, and a proxy.

Shaka Player gets loaded on demand for DASH and ClearKey streams, alongside HLS.js for everything else. The API response tells the frontend which engine to use per stream:

{
  "url": "…",
  "kind": "dash",          // "hls" | "dash" — selects the player engine
  "clearKeys": { "<kidHex>": "<keyHex>" },
  "drmUnsupported": false  // true for Widevine/PlayReady
}

For header-gated DASH streams, the backend rewrites the manifest so every segment routes back through a stream proxy, which attaches the required headers server-side and relaxes CORS. The proxy isn’t an open relay, though — every upstream URL it’s willing to fetch has to be one the backend itself signed:

"""
* Signed tokens — every upstream URL the proxy will fetch is HMAC-signed by
  us, so the endpoint is not an open proxy: clients can't point it at
  arbitrary hosts, only at URLs the backend itself minted from the ingested
  playlist.
* DASH rewriting — injecting a proxied <BaseURL> makes the player fetch every
  segment back through the proxy (with headers + CORS), while absolute
  references are rewritten too.
"""

Without the signature check, /api/v1/proxy/... would just be a generic SSRF-shaped hole pointed at the internet. With it, the endpoint can only ever fetch URLs that came from the ingested playlist in the first place.

Adding a Private Playlist Without Breaking the Public One

Beyond the public iptv-org catalog, I wanted to be able to point the app at an extra, private M3U playlist too — without the two data sources stepping on each other during sync. The fix was tagging rows by source (iptv-org vs extra) so a sync of one never touches or deletes rows belonging to the other.

Whether a source shows up at all is then decided at query time, not at ingest time, by two env flags:

IPTV_ORG_ENABLEDEXTRA_PLAYLIST_URLCatalog shows
truesetiptv-org + extra
falsesetextra only
trueemptyiptv-org only
falseemptynothing

Turning a source off hides it from every read path — list, search, detail, related, counts, favorites — but the rows stay in the database. Flipping it back on is instant, no re-ingest needed. That distinction (ingest-time vs. query-time) turned out to matter a lot for a catalog I wanted to be able to reshape without re-downloading ~10k channels every time I changed my mind.

Movie Metadata via TMDB

For the movies section, raw playlist entries are just a name and a stream URL — not exactly Netflix-quality browsing. A separate enrichment worker matches unmatched movie entries against TMDB (The Movie Database) to backfill posters, descriptions, and ratings:

python -m app.workers.run_enrich_movies [LIMIT]

It only touches movies that haven’t been matched yet, so it’s safe to re-run on a schedule or by hand without redoing work or hammering the TMDB API for entries that already resolved.

Auth: Deliberately Minimal

This app has exactly one intended user: me. So the auth story stayed as simple as it could reasonably be — a single username/password pair from config, checked with constant-time comparison, issuing a bearer token:

valid_username = hmac.compare_digest(body.username, settings.auth_username)
valid_password = hmac.compare_digest(body.password, settings.auth_password)
if not (valid_username and valid_password):
    raise HTTPException(status_code=401, detail="Invalid username or password")
token = create_token(body.username, settings.auth_secret, ttl_seconds)

No user table, no registration flow, no password reset — all of that would be solving a problem this app doesn’t have. hmac.compare_digest instead of == is the one detail worth keeping even at this scale, since a naive string comparison on credentials leaks timing information for free.

Shipping It

The whole stack — Postgres, Redis, the FastAPI backend, and an nginx-served frontend build — is containerized with Docker Compose. On a fresh server, standing it up is:

cp backend/.env.example backend/.env   # PROXY_SECRET, EXTRA_PLAYLIST_URL, TMDB_API_KEY…
docker compose -f docker/docker-compose.yml up -d --build

The backend applies migrations and populates the catalog on first boot, so there’s no separate manual seeding step to remember.

What I Learned

A few things stuck with me:

  • “Play a video” is not one problem. HLS and DASH, DRM and no DRM, header-gated and open — each combination is its own small feature, and a real IPTV catalog will eventually contain all of them.
  • A proxy without a signature is an open door. Signing every URL the backend is willing to fetch, rather than trusting whatever the client sends, is the difference between a useful feature and an SSRF vector.
  • Separate “is this data ingested” from “is this data shown.” Tagging by source and deciding visibility at query time made toggling data sources reversible and cheap, instead of a destructive re-ingest every time.
  • Match auth complexity to the actual number of users. A single-user app doesn’t need the auth system of a multi-tenant SaaS — it needs the one part of a “real” auth system (constant-time comparison) that actually matters at any scale.

It’s a fun project to keep extending — there’s always another stream format edge case, another metadata source worth wiring in. But even in its current state, it’s already a better way to browse public IPTV than any playlist app I’d tried before.