Authentication and Cookies in yt-dlp
yt-dlp supports various methods of authentication, allowing you to access content that requires login. This guide covers different authentication methods and the use of cookies.
Basic Authentication
Username and Password
For sites that require a simple login:
yt-dlp -u USERNAME -p PASSWORD URL
If you omit the password, yt-dlp will prompt you to enter it securely:
yt-dlp -u USERNAME URL
Two-Factor Authentication
For accounts with 2FA enabled:
yt-dlp -u USERNAME -p PASSWORD -2 TWOFACTOR URL
Netrc File
You can store login info in a .netrc
file:
- Create a file named
.netrc
in your home directory. - Add entries in the format:
machine HOSTNAME login USERNAME password PASSWORD
- Use the
--netrc
option:
yt-dlp --netrc URL
Using Cookies
Passing Cookies Directly
Use the --cookies
option to pass a cookies file:
yt-dlp --cookies /path/to/cookies.txt URL
Extracting Cookies from Browsers
yt-dlp can extract cookies directly from your browser:
yt-dlp --cookies-from-browser BROWSER[:PROFILE_PATH] URL
Replace BROWSER
with chrome
, firefox
, opera
, safari
, etc.
Example:
yt-dlp --cookies-from-browser firefox URL
Site-Specific Authentication
YouTube
For YouTube, you can use OAuth:
- Run:
yt-dlp --auth-oauth CREDENTIALS_FILE
- Follow the prompts to authenticate.
- yt-dlp will save the token for future use.
Other Platforms
Some platforms may require specific authentication methods. Check the yt-dlp documentation for platform-specific instructions.
Handling Private Content
To access private videos or playlists:
- Log in to your account in a web browser.
- Export the cookies (use a browser extension or
--cookies-from-browser
). - Use the cookies file with yt-dlp:
yt-dlp --cookies cookies.txt PRIVATE_VIDEO_URL
Tips for Authentication
- Use
--verbose
to see detailed information about the authentication process. - For security, avoid passing passwords directly in the command line; use
netrc
or prompt instead. - Regularly update your cookies file if you're accessing frequently changing private content.
- Be cautious when sharing scripts or commands that include authentication information.
Troubleshooting Authentication Issues
- Ensure your login credentials are correct.
- Check if the site requires a specific User-Agent:
yt-dlp --user-agent "Mozilla/5.0 ..." --cookies cookies.txt URL
- Some sites may block yt-dlp; try using
--add-header
to mimic a browser request. - If using cookies, ensure they're fresh and not expired.
Important Notes
- Keep your authentication information secure.
- Be aware of the terms of service for the sites you're accessing.
- Some sites may have anti-bot measures that could be triggered by frequent requests.
Authentication in yt-dlp allows you to access a wide range of content that requires login. By understanding these methods, you can effectively use yt-dlp for both public and private media while maintaining security and respecting site policies.