Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
Rounds: yt-dlp "Download audio from URL" for references (#2120)
Approved: 2026-07-04
Goal
Add the deferred convenience path from #2106: on a round reference (e.g. a
layered TikTok performance), let the user paste a URL and have PortOS download +
extract its audio via yt-dlp, landing the file in the uploads dir so it can be
attached and analyzed like an uploaded/mic-captured recording. Upload and mic
capture remain the primary paths; this is best-effort.
Key discovery — reuse, don't rebuild
The yt-dlp + audio-extraction + SSE-progress machinery already exists for the
YouTube track import (#1945): server/lib/ytdlp.js (findYtDlp),
server/services/trackYoutubeImport.js, server/lib/sseUtils.js,
server/lib/killWithEscalation.js. #2120's operation is nearly identical,
differing only in:
- URL scope — any public http(s) URL + SSRF guard (not YouTube-only).
- Output — land in
PATHS.uploadsand return afilename(not the music library + a Track record).
Design (approved decisions)
- Progress UX: SSE streaming progress (mirrors the LoRA/track import), not a blocking spinner.
- URL scope: any public http(s) URL;
assertPublicHttpUrl(url, { blockPrivate: true })fromsafeUrlFetch.jsrejects private/loopback/metadata hosts. yt-dlp decides what it can actually extract; a failure degrades to a clear error. - Reuse strategy: extract the shared yt-dlp download core and refactor the track import to use it (DRY; the track path has test coverage so the refactor is verifiable).
Components
server/services/ytdlpAudioImport.js(new, shared core) — binary discovery/assert, arg construction,--progress-templateparsing, spawn, cancel-aware exit classification, temp cleanup. Returns{ outcome, outPath, title, reason }; SSE + post-processing stay with the caller.trackYoutubeImport.jsrefactored to call it.server/lib/fileUtils.js— newimportFileToUploads(tempPath, originalName)(copyFile+unlink cross-device-safe,uuid8-sanitizedName, mirrors the/api/uploadsnaming). Registered in the lib barrel + README.server/services/roundReferenceAudioImport.js(new) — SSRF-guardedstartReferenceAudioImport(url)job that runs the core, lands the mp3 viaimportFileToUploads, and streams{ type:'complete', filename }. Plus attach/cancel SSE helpers.server/routes/rounds.js—POST /reference-audio/import,GET /reference-audio/import/:jobId/events,POST /reference-audio/import/:jobId/cancel(placed before/:id).- Client —
apiRounds.jswrappers, auseReferenceAudioImporthook (mirrorsuseYoutubeTrackImport), and a "Download from URL" control inReferenceAudioAttach(ReferenceAnalysis.jsx) that setsaudioFilenamevia the existingonUpdatepath on completion.
Bounds / safety
execFile/spawnwith a fixed arg array (no shell) — the yt-dlp binary is the only command, args never interpolate through a shell.--max-filesize/--match-filters duration<=…cap resource use (its own uploads-appropriate bounds).- Binary-missing →
409/500with an actionable "install yt-dlp/ffmpeg" message.
Tests
- Shared core: URL/arg invariants; happy path + failure with mocked
spawn. roundReferenceAudioImport: SSRF rejection; happy path lands a filename.- Rounds route: kickoff + SSE attach + cancel.
- Re-run
trackYoutubeImport.test.js(no regression) andlib/index.test.js(barrel).