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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): gate the yt-dlp upgrade hint on the source site
[._.]/ Adam Eivyaa7300d048f2
diff --git a/server/services/ytdlpAudioImport.js b/server/services/ytdlpAudioImport.jsindex eb39b958f7..650629a51f 100644--- a/server/services/ytdlpAudioImport.js+++ b/server/services/ytdlpAudioImport.js@@ -99,7 +99,7 @@ export async function downloadAudioToTempMp3({url,];- const exit = await runYtDlp({ ytDlp, args, onProgress, registerProcess });+ const exit = await runYtDlp({ ytDlp, args, url, onProgress, registerProcess });if (exit.canceled) {await cleanupYtDlpTemp(tempPrefix);@@ -114,6 +114,7 @@ export async function downloadAudioToTempMp3({// the prose and appends whatever yt-dlp did print, which outranks the guess.const reason = exit.code === 0? describeYtDlpFailure(exit.code, exit.output, {+ url,fallback: `no audio was produced — the source may be longer than ${Math.round(maxDurationSec / 60)} minutes or its audio larger than ${Math.round(maxBytes / 1024 / 1024)}MB, or it may be otherwise unavailable`,}): exit.reason; // always populated for a non-zero exit (see runYtDlp)diff --git a/server/services/ytdlpRun.js b/server/services/ytdlpRun.jsindex f5744e52aa..87d3e754be 100644--- a/server/services/ytdlpRun.js+++ b/server/services/ytdlpRun.js@@ -22,6 +22,7 @@import { spawn } from '../lib/childProcess.js';import { safeChildProcessOptions } from '../lib/processEnv.js';import { createLineReader, createOutputTail } from '../lib/streamLines.js';+import { isYoutubeVideoUrl } from '../lib/youtubeUrl.js';/*** The wire protocol between our `--progress-template`/`--print` flags and the@@ -69,10 +70,16 @@ export const ytdlpMarkerArgs = (postprocessStage) => [* message alone, so name the remedy rather than leaving the user to re-try.** Every alternative below must be diagnostic of THAT class, or the hint sends- * the user to the one action that cannot help. Deliberately excluded: a bare- * `Forbidden` (any site's 403 — the x.com login-wall/rate-limit path returns- * one, and `HTTP Error 403` already covers the YouTube case) and `Sign in to- * confirm` (YouTube's bot check, whose remedy is cookies, not an upgrade).+ * the user to the one action that cannot help. Excluded for that reason: `Sign+ * in to confirm`, YouTube's bot check, whose remedy is cookies rather than an+ * upgrade.+ *+ * The message alone is NOT enough to decide, though — these importers also pull+ * from x.com/Twitter (login-walled and rate-limited posts return a plain 403)+ * and, on the reference-audio path, from any public URL. So the hint is gated on+ * the SOURCE as well: `describeYtDlpFailure` applies it only when the URL is a+ * YouTube video. A caller that passes no URL gets no hint — silence beats+ * pointing the user at an upgrade that cannot help.*/const STALE_YTDLP_SIGNATURE = /HTTP Error 403|PO Token|nsig|Failed to extract any player response/i;@@ -91,13 +98,17 @@ const STALE_YTDLP_HINT = 'the installed yt-dlp is likely out of date for YouTube* a run that exited 0 and still produced nothing: only the caller knows which* of its bounds was tripped. yt-dlp's own words outrank a guess, so they are* appended to it whenever there are any.+ * @param {string} [o.url] The source URL, which decides whether the+ * stale-player hint applies at all (see `STALE_YTDLP_SIGNATURE`). Omit it and+ * the hint is never added.*/-export function describeYtDlpFailure(code, output, { fallback } = {}) {+export function describeYtDlpFailure(code, output, { fallback, url } = {}) {const said = (output || '').trim();const base = fallback? [fallback, said].filter(Boolean).join(' — yt-dlp said: '): (said ? `yt-dlp failed: ${said}` : `yt-dlp exited ${code}`);- return STALE_YTDLP_SIGNATURE.test(said) ? `${base} — ${STALE_YTDLP_HINT}` : base;+ const stalePlayer = isYoutubeVideoUrl(url) && STALE_YTDLP_SIGNATURE.test(said);+ return stalePlayer ? `${base} — ${STALE_YTDLP_HINT}` : base;}/**@@ -106,6 +117,9 @@ export function describeYtDlpFailure(code, output, { fallback } = {}) {* @param {object} opts* @param {string} opts.ytDlp yt-dlp binary path.* @param {string[]} opts.args Fully-built argv (marker args included).+ * @param {string} [opts.url] The source URL, forwarded to+ * `describeYtDlpFailure` so a YouTube-only remedy is never suggested for a+ * failure from another site. Omitting it only costs the hint.* @param {function} opts.onProgress ({ percent, stage }) => void — SSE-agnostic.* @param {function} opts.registerProcess (proc|null) => void — lets the caller wire cancel.* @returns {Promise<{ canceled:boolean, code:number|null, signal:string|null, reason:string|null, title:string, output:string }>}@@ -115,7 +129,7 @@ export function describeYtDlpFailure(code, output, { fallback } = {}) {* `describeYtDlpFailure`) — and null on a clean exit. `output` is the raw tail* of non-marker output, for callers that compose their own reason.*/-export async function runYtDlp({ ytDlp, args, onProgress, registerProcess }) {+export async function runYtDlp({ ytDlp, args, url, onProgress, registerProcess }) {const proc = spawn(ytDlp, args, safeChildProcessOptions({ stdio: ['ignore', 'pipe', 'pipe'] }));registerProcess(proc);@@ -174,7 +188,7 @@ export async function runYtDlp({ ytDlp, args, onProgress, registerProcess }) {// Exit 0 keeps `reason: null` — the caller owns the "exited 0 but produced// nothing" case, where the bound that was tripped is knowable only to it. A// spawn failure has no output to explain it, so its own message stands.- const reason = code === 0 ? null : (exit.reason ?? describeYtDlpFailure(code, output));+ const reason = code === 0 ? null : (exit.reason ?? describeYtDlpFailure(code, output, { url }));return { canceled: false, code, signal: exit.signal ?? null, reason, title, output };}diff --git a/server/services/ytdlpRun.test.js b/server/services/ytdlpRun.test.jsindex 16c7b1093c..982eef0589 100644--- a/server/services/ytdlpRun.test.js+++ b/server/services/ytdlpRun.test.js@@ -49,35 +49,46 @@ describe('ytdlpMarkerArgs', () => {});});+const YT_URL = 'https://youtu.be/aaaaaaaaaaa';+const X_URL = 'https://x.com/someone/status/1234567890';+const FORBIDDEN = 'ERROR: unable to download video data: HTTP Error 403: Forbidden';+describe('describeYtDlpFailure', () => {it('names the stale-binary remedy for the YouTube gating class', () => {// A 403 on media URLs is what a yt-dlp that has fallen behind YouTube's// player handshake reports for a video the browser plays fine; without the// hint the user has a real message and still no next step.- const reason = describeYtDlpFailure(1, 'ERROR: unable to download video data: HTTP Error 403: Forbidden');+ const reason = describeYtDlpFailure(1, FORBIDDEN, { url: YT_URL });expect(reason).toContain('HTTP Error 403: Forbidden');expect(reason).toMatch(/yt-dlp -U/);});it('leaves an unrelated failure without the upgrade hint', () => {- const reason = describeYtDlpFailure(1, 'ERROR: Video unavailable');+ const reason = describeYtDlpFailure(1, 'ERROR: Video unavailable', { url: YT_URL });expect(reason).toBe('yt-dlp failed: ERROR: Video unavailable');expect(reason).not.toMatch(/yt-dlp -U/);});- // Two failures that LOOK like the stale-player class and are not. Advising an- // upgrade for either sends the user to the one action that cannot help, so the- // exclusions are pinned rather than left to the regex's shape.+ // Failures that LOOK like the stale-player class and are not. Advising an+ // upgrade for any of them sends the user to the one action that cannot help,+ // so each exclusion is pinned rather than left to the regex's shape.it('does not advise an upgrade for YouTube\'s bot check, whose remedy is cookies', () => {- const reason = describeYtDlpFailure(1, 'ERROR: Sign in to confirm you are not a bot');+ const reason = describeYtDlpFailure(1, 'ERROR: Sign in to confirm you are not a bot', { url: YT_URL });expect(reason).not.toMatch(/yt-dlp -U/);});- it('does not advise an upgrade for a non-YouTube 403', () => {- const reason = describeYtDlpFailure(1, 'ERROR: unable to download: Forbidden (rate-limited)');+ // The message alone can't decide this one: x.com returns a plain 403 for a+ // login-walled or rate-limited post, which no yt-dlp upgrade fixes.+ it('does not advise an upgrade for the same 403 from a non-YouTube source', () => {+ const reason = describeYtDlpFailure(1, FORBIDDEN, { url: X_URL });+ expect(reason).toContain('HTTP Error 403: Forbidden');expect(reason).not.toMatch(/yt-dlp -U/);});+ it('withholds the hint when the caller passed no URL at all', () => {+ expect(describeYtDlpFailure(1, FORBIDDEN)).not.toMatch(/yt-dlp -U/);+ });+it('falls back to the exit code when there is no output', () => {expect(describeYtDlpFailure(2, ' ')).toBe('yt-dlp exited 2');});@@ -93,7 +104,7 @@ describe('describeYtDlpFailure', () => {});it('still names the upgrade remedy when the printed cause is the gating class', () => {- const reason = describeYtDlpFailure(0, 'ERROR: HTTP Error 403: Forbidden', { fallback: 'no video was produced' });+ const reason = describeYtDlpFailure(0, FORBIDDEN, { fallback: 'no video was produced', url: YT_URL });expect(reason).toMatch(/yt-dlp -U/);});});@@ -175,6 +186,20 @@ describe('runYtDlp — exit classification', () => {expect(result.reason).not.toBe('yt-dlp exited 1');});+ // Pins that the URL actually reaches describeYtDlpFailure — without the+ // forwarding, both of these would report the same reason.+ it('forwards the source URL, so the hint follows the site and not just the message', async () => {+ const child = () => fakeChild({ code: 1, script: [['stderr', `${FORBIDDEN}\n`]] });++ spawn.mockReturnValue(child());+ const youtube = await runYtDlp({ ...baseArgs, url: YT_URL });+ expect(youtube.reason).toMatch(/yt-dlp -U/);++ spawn.mockReturnValue(child());+ const x = await runYtDlp({ ...baseArgs, url: X_URL });+ expect(x.reason).not.toMatch(/yt-dlp -U/);+ });+it('flushes an unterminated final stderr line into the failure reason', async () => {// yt-dlp's ERROR line is frequently the last thing written, with no newline.spawn.mockReturnValue(fakeChild({ code: 1, script: [['stderr', 'ERROR: Video unavailable']] }));diff --git a/server/services/ytdlpVideoImport.js b/server/services/ytdlpVideoImport.jsindex 747404ee2d..7520ac9dad 100644--- a/server/services/ytdlpVideoImport.js+++ b/server/services/ytdlpVideoImport.js@@ -109,7 +109,7 @@ export async function downloadVideoToDir({url,];- const exit = await runYtDlp({ ytDlp, args, onProgress, registerProcess });+ const exit = await runYtDlp({ ytDlp, args, url, onProgress, registerProcess });if (exit.canceled) {await cleanupProducedFiles(filePrefix, outDir);@@ -126,6 +126,7 @@ export async function downloadVideoToDir({// yt-dlp actually printed, which outranks the guess.const reason = exit.code === 0? describeYtDlpFailure(exit.code, exit.output, {+ url,fallback: `no video was produced — it may be longer than ${Math.round(maxDurationSec / 60)} minutes or larger than ${Math.round(maxBytes / 1024 / 1024 / 1024)}GB, or (for x.com) login-walled, rate-limited, or otherwise unavailable`,}): exit.reason; // always populated for a non-zero exit (see runYtDlp)