- Add cookies support in youtube.js service - Create extract-cookies.sh script for automatic cookie extraction - Add YOUTUBE_COOKIES_PATH environment variable - Update .env.example with cookies configuration - Add comprehensive documentation (YOUTUBE_COOKIES.md, COOKIES_QUICK_START.md) - Update .gitignore to exclude cookies files for security - Pass cookiesPath option through all download functions This fixes Sign in to confirm you're not a bot errors from YouTube. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
3.8 KiB
YouTube Cookies Setup Guide
Why Do I Need Cookies?
YouTube has anti-bot protections that may block yt-dlp requests. Using cookies from your browser allows yt-dlp to authenticate as if you're logged in, bypassing these restrictions.
Quick Start
Option 1: Automatic Extraction (Recommended)
Run the helper script:
bash scripts/extract-cookies.sh
Follow the prompts to extract cookies from Chrome or Firefox.
Option 2: Using yt-dlp Directly
# For Chrome/Chromium
yt-dlp --cookies-from-browser chrome --cookies youtube-cookies.txt 'https://www.youtube.com'
# For Firefox
yt-dlp --cookies-from-browser firefox --cookies youtube-cookies.txt 'https://www.youtube.com'
# For Edge
yt-dlp --cookies-from-browser edge --cookies youtube-cookies.txt 'https://www.youtube.com'
Option 3: Browser Extension
-
Install a cookies export extension:
- Chrome/Edge: Get cookies.txt LOCALLY
- Firefox: cookies.txt
-
Go to youtube.com and log in
-
Click the extension icon and export cookies
-
Save the file as
youtube-cookies.txtin your project directory
Configuration
After extracting cookies, update your .env file:
YOUTUBE_COOKIES_PATH=/home/debian/videotomp3transcriptor/youtube-cookies.txt
Or use a relative path:
YOUTUBE_COOKIES_PATH=./youtube-cookies.txt
Verifying It Works
Test with a video:
curl -X POST http://localhost:3001/download \
-H "Content-Type: application/json" \
-d '{"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"}'
If it works without cookies errors, you're good to go!
Security Notes
⚠️ IMPORTANT:
- Never commit cookies to git: The
.gitignorefile should already excludeyoutube-cookies.txt - Keep cookies secure: They provide access to your YouTube account
- Cookies expire: You may need to re-export them periodically (typically every few weeks/months)
- Don't share cookies: Treat them like passwords
Troubleshooting
"Sign in to confirm you're not a bot"
This usually means:
- Cookies are not being used
- Cookies have expired
- Cookies file path is incorrect
Solutions:
- Check the path in
.envis correct and absolute - Re-export fresh cookies
- Verify the cookies file exists:
ls -la youtube-cookies.txt - Check logs:
pm2 logs toMP3-api
"HTTP Error 403: Forbidden"
YouTube is blocking your IP or the video is region-restricted.
Solutions:
- Try with fresh cookies
- Use a VPN if region-restricted
- Wait a bit if rate-limited
Cookies Not Working
- Make sure you're logged into YouTube in the browser before extracting
- Try extracting from a different browser
- Verify the cookies file format (should be Netscape format)
- Check file permissions:
chmod 600 youtube-cookies.txt
Cookie File Format
The cookies file should be in Netscape format and look like this:
# Netscape HTTP Cookie File
.youtube.com TRUE / TRUE 1234567890 CONSENT YES+
.youtube.com TRUE / FALSE 1234567890 VISITOR_INFO1_LIVE xxxxx
Without Cookies
The API will still work for many videos without cookies, but you may encounter:
- "Sign in to confirm you're not a bot" errors
- Rate limiting
- Blocked downloads for certain videos
For best results, always use cookies!