fix(backend): pass YouTube cookies to yt-dlp to beat the datacenter bot check

YouTube now returns "Sign in to confirm you're not a bot" for yt-dlp from
datacenter IPs, blocking downloads, search and link-resolve. When a cookies file
is present (YTDLP_COOKIES, default /data/youtube-cookies.txt) every yt-dlp call
passes --cookies so it authenticates. Checked at call time (drop the file in, no
code change); absent → unchanged behaviour. Applied to the download cascade, the
YTM search probe, and the importer resolve.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
HoneyandClaude Opus 4.8 committed 2026-08-17 12:02:26 +02:00
1 parent e82dec7e01
commit 0990dfadb5
4 files changed
+25 -1

No files matched your search

+3
View File
@@ -533,6 +533,9 @@ app.post('/api/youtube/resolve', async (req, res) => {
execFile(CONFIG.ytdlpBin, [
'--dump-json', '--flat-playlist', '--no-warnings',
'--playlist-items', '1-50',
// Cookies (if present) let yt-dlp past YouTube's datacenter-IP bot check. Domain-scoped, so
// harmless for non-YouTube links. No file → runs as before.
...((CONFIG.cookiesFile && fs.existsSync(CONFIG.cookiesFile)) ? ['--cookies', CONFIG.cookiesFile] : []),
url,
], { timeout: 45000, maxBuffer: 20 * 1024 * 1024 }, (err, out, stderr) => {
if (err && !out?.trim()) return reject(new Error(stderr?.trim() || err.message));