A YouTube session cookie file lets yt-dlp act as a logged-in user and reduces HTTP 403 errors. Cookie files are local-only credentials — never commit them to Git.
- Install a browser extension such as Get cookies.txt LOCALLY (Chrome).
- Log in to YouTube in your browser.
- Export cookies for
youtube.comto a local file (e.g.youtube.com_cookies.txt). - Copy the file into your project directory (optional):
cd "$PROJECT_ROOT"
cp ~/Downloads/youtube.com_cookies.txt ./youtube_cookies.txt
chmod 600 ./youtube_cookies.txt- Add to
.env:
YOUTUBE_COOKIES_FILE="${PROJECT_ROOT}/youtube_cookies.txt"Use an absolute path if the file lives outside the repository.
Cookie files contain session credentials. Restrict access to your user account only:
chmod 600 /path/to/youtube_cookies.txtDo not use world-readable permissions (644 or 755).
- Never commit cookie files. This repository ignores common variations:
youtube_cookies.txtyoutube.com_cookies.txtcookies.txt*.cookies.txt
- Rotate cookies periodically (every 1–2 weeks) or when 403 errors return.
- If a cookie file was ever committed, revoke the session (log out / change password) and rotate.
yt-dlp --cookies "$YOUTUBE_COOKIES_FILE" \
--extract-audio --audio-format m4a \
"https://www.youtube.com/watch?v=VIDEO_ID"| Issue | Action |
|---|---|
| File not found | Verify YOUTUBE_COOKIES_FILE path in .env |
| 403 persists | Re-export cookies; confirm YouTube login; update yt-dlp |
| Extension fails | Try an alternate cookies.txt exporter |