Authentication
Some content requires authentication to access. ytdlp-nodejs supports multiple authentication methods.
Using Browser Cookies
The easiest way to authenticate is to use cookies from a browser where you're already logged in:
1await ytdlp.downloadAsync(url, {
2 cookiesFromBrowser: 'chrome', // or 'firefox', 'edge', 'safari', 'opera', 'brave'
3});
Browser Profiles
For browsers with multiple profiles:
1await ytdlp.downloadAsync(url, {
2 cookiesFromBrowser: 'chrome:Profile 1',
3});
Using Cookie Files
You can export cookies to a Netscape-format file and use it:
1await ytdlp.downloadAsync(url, {
2 cookies: '/path/to/cookies.txt',
3});
Exporting Cookies
Use a browser extension like "Get cookies.txt" to export your cookies.
Username & Password
For sites that support direct authentication:
1await ytdlp.downloadAsync(url, {
2 username: 'your_username',
3 password: 'your_password',
4});
Two-Factor Authentication
1await ytdlp.downloadAsync(url, {
2 username: 'your_username',
3 password: 'your_password',
4 twofactor: '123456', // 2FA code
5});
Video Password
For password-protected videos (like Vimeo):
1await ytdlp.downloadAsync(url, {
2 videoPassword: 'video_password',
3});
API Keys
Some extractors require API keys:
1await ytdlp.downloadAsync(url, {
2 rawArgs: ['--extractor-args', 'youtube:api_key=YOUR_API_KEY'],
3});
Age-Restricted Content
For age-restricted YouTube videos, use browser cookies from a logged-in account:
1await ytdlp.downloadAsync(url, {
2 cookiesFromBrowser: 'chrome',
3 // Alternatively, add age gate bypass
4 rawArgs: ['--extractor-args', 'youtube:skip=dash'],
5});
Troubleshooting Authentication
"Sign in to confirm you're not a bot"
This YouTube error requires valid cookies:
1await ytdlp.downloadAsync(url, {
2 cookiesFromBrowser: 'chrome',
3 // Force fresh cookies
4 noCacheDir: true,
5});
Cookie Permission Errors
On some systems, you may need elevated permissions to access browser cookies. Run your script with appropriate permissions or use a cookie file instead.