/** * Shared yt-dlp stderr parsing. Used by both download.ts and probe.ts so the * error-extraction logic lives in one place (audit M1). */ /** Trim yt-dlp's noisy stderr down to the most useful trailing error line. */ export function cleanError(stderr: string): string { const lines = stderr .split('\n') .map((l) => l.trim()) .filter(Boolean) const errLine = [...lines].reverse().find((l) => /^error/i.test(l)) return (errLine ?? lines[lines.length - 1] ?? '').replace(/^error:\s*/i, '').trim() }