How aryaniiil/vidlink-m3u8 works
This repo is a single-service Node.js REST API (Fastify) whose main job is to:
• Accept client requests for movie/series streaming info (by TMDB IDs)
• Generate/compute an authentication token via WebAssembly (Go WASM runtime + fu.wasm)
• Call Vidlink upstream APIs to obtain stream metadata / HLS master playlists
• Optionally call TMDB for /search enrichment (requires TMDB_API_KEY)
• Return a JSON payload containing the upstream API URL, required headers, and the extracted HLS playlist/stream URLs
• Request flow (client → Fastify routes → WASM token gen → upstream fetch → response)
• External dependencies (Vidlink, TMDB, streaming CDN hosts that serve .m3u8)
File structure → architectural components
Top-level:
• server.js → Fastify HTTP server + route handlers (/movie, /series, /search, /health)
• fu.wasm → WASM binary module that performs token generation/auth logic
• wasm_exec.js → Go WASM runtime shim that lets Node execute the Go-compiled WASM
• .env → runtime configuration (PORT, TMDB_API_KEY)
• package.json / package-lock.json → Node deps / build & run scripts
• README.md → behavior, endpoint contracts, constraints (headers required, token expiry)
Architecturally, this is best modeled as one container (Node service) with an internal component boundary around “Token Generation (WASM)”.
Actors / Clients
• API Consumer (curl, browser app, backend service, etc.)
• Calls your endpoints: /movie/:movieId, /series/:tmdbId/:season/:episode, /search/:query, /health
Primary runtime container
• Node.js 18+ Process
• Fastify Server listening on PORT
• Route handlers (logical sub-components):
• Movie Stream Controller/Handler
• Series Episode Stream Controller/Handler
• Search Controller/Handler (TMDB)
• Health Handler (reports wasmInitialized)
External services (must be drawn explicitly)
• Vidlink (e.g., https://vidlink.pro/api/...)
• Upstream API used to fetch streaming data; requires token
• TMDB API (search + metadata; requires TMDB_API_KEY)
• Streaming/CDN hosts (e.g., storm.vodvidl.site, rainflare53.pro, etc.)
• These ultimately serve HLS playlists/segments, and require special headers
Client → Fastify
• HTTP GET to /movie/:id or /series/:tmdbId/:season/:episode
Fastify Route Handler → WASM Token Generator
• Call into wasm_exec.js + fu.wasm
• Output: token (time-sensitive / expiring)
Fastify Route Handler → Vidlink API
• HTTP fetch to Vidlink endpoint using generated token
• Output: upstream response that includes/points to HLS resources
Fastify Route Handler → HLS Playlist Extraction
• Parse/extract “master playlist” and quality variants
• Output: playlist text + selected stream URL(s) + required headers
Fastify → Client
• JSON response: api_url, headers, playlist, stream/sourceId, etc.
Search flow
• Client → /search/:query → Fastify → TMDB API → Fastify → Client
• TMDB_API_KEY dependency from .env
Health flow
• Client → /health → Fastify
• .env → Node/Fastify process (configuration injection: PORT, TMDB_API_KEY)
• package.json → Node process (runtime dependencies)
Architectural patterns / principles to highlight
• Single-service / modular monolith: one Node runtime hosting all routes
• Adapter boundary for WASM: Go WASM runtime (wasm_exec.js) acting as an execution adapter around fu.wasm
• Facade API pattern: your server is a façade over Vidlink + TMDB, normalizing responses and providing required headers/playlist extraction
• Time-sensitive auth: token expiration drives the need to regenerate tokens per request or cache carefully
• Rate limiting (to respect upstream constraints)
• Caching (token caching and/or response caching keyed by TMDB ID + season/episode)
• Reverse proxy (Nginx/Cloudflare) in front of Fastify (optional deployment view)
“Don’t overthink it”: split into as many components as possible (but keep truthfulness)
• Fastify routing vs business logic handlers
• Token generation (WASM) vs HTTP fetching (Vidlink/TMDB)
• Playlist parsing/extraction vs response formatting
• Client consumption of streaming hosts (since headers/403 constraints are central to the system behavior)