Our LMS records live classes. When they lived on Bunny/Mux, the download button was one API call:

const url = await bunny.generateDownloadUrl(resource.key); // signed, expires return { status: 'ready', url }; 

Done. Easiest feature in the codebase.

Then I moved the less important live sessions to YouTube (unlisted) and got the requirement: same button.

Sure. How hard can it be.

Problem 1: YouTube won't give you your own video

There's no API for it, and Studio doesn't give you a usable high quality copy either. So the answer is yt-dlp. For anything decent, YouTube serves video and audio as separate streams, so yt-dlp pulls both and ffmpeg muxes them into one MP4.

That's not a 200ms request anymore. A 47 min class takes about a minute, a 3 hour one about 5. So now the button needs ffmpeg, workers, disk and a job queue. All of it sitting on the API server forever, for a button someone clicks a few times a week. (pathetic)

Problem 2: where does that thing live

I already had a self hosted Coolify box in our office, exposed through a Cloudflare Tunnel. Our hardware, always on, cost is basically zero. So the heavy stuff goes there and the API just talks to it.

Problem 3: someone already built it (the first one lied)

The first open source server I tried returned 0 byte files for every live archive. YouTube refused the stream URLs it got, and it turned that into an empty file instead of an error. Fun.

The second one, yt-dlp-host, worked. It's a small task API: POST /get_video queues a job, GET /status/:id reports it, and the file is served at /files/:id/:name. It runs as three containers on Coolify: the API, a worker (MAX_WORKERS=2), and an nginx in front. The nginx is there because yt-dlp-host sends inline, and a cross origin link would just play the video in the tab:

location /files/ { proxy_pass http://api:5000; proxy_buffering off; proxy_hide_header Content-Disposition; add_header Content-Disposition attachment; } 

The flow

Browser ──GET /resources/:id/download──▶ API ──POST /get_video──▶ yt-dlp-host ▲ { status: 'preparing' } │ (office box) │ ... every 5s ... └──GET /status/:id────▶ └── { status: 'ready', url } ◀── "completed" ◀────────────────────┘ Browser downloads the MP4 straight from the worker. Deleted after 2h. 

The endpoint just answers "where are we" on every call:

async prepare(resource) { const taskId = resource.meta.downloadTaskId; if (taskId) { const task = await ytDlpHost.getTask(taskId); if (task.state === 'completed') return { status: 'ready', url: task.fileUrl }; if (task.state === 'pending') return { status: 'preparing' }; if (task.state === 'error') { await forgetTask(resource); throw new BadGateway(task.error); } // 'missing': the worker already cleaned it up, start again } const newTaskId = await ytDlpHost.startVideoTask(watchUrl, { video_format: 'bestvideo[height<=1080][vcodec^=avc1]', // H.264, plays everywhere audio_format: 'bestaudio[ext=m4a]', output_format: 'mp4', }); await saveTask(resource, newTaskId); return { status: 'preparing' }; } 

A few details that took longer than the code:

  • The task id lives on the resource, so two admins clicking the same class share one file instead of making two.
  • No video bytes go through our API. The task id is random enough that the file link can't be guessed, so the browser downloads it directly.
  • Only finished recordings. If YouTube is still processing the archive, yt-dlp happily gives you a truncated file.
  • yt-dlp breaks whenever YouTube changes something. The fix is a no-cache rebuild of the service. So now I have a pet.
  • "Cost is zero" until the office power goes out and the firewall comes back blocking the tunnel's port.

What the business sees

clicks button → "Preparing download…" → video downloads

"Nice. That was always there right?"

Yes. Yes it was.

Every dev has one of these. The feature where the hardest part was making sure nobody noticed anything changed. What's yours?