Today, I downloaded one video using yt-dlp. When downloading the second one, it prompted for cookies. Initially, I used `–cookies cookies.txt`, but it didn’t work. Later, I realized YouTube frequently rotates cookies, which might be the reason for the failure.
I’ll explain how I solved this using Google Chrome. As for other browsers, I don’t know. At the end, I’ll talk about other methods I tried.
I. Google Chrome
Open a new incognito (private) window
Log in to your YouTube account (preferably using a secondary account)
Open a few videos, then close them
Download the cookies.txt file. I used the Get cookies.txt LOCALLY plugin.
Now you can use the `–cookies cookies.txt` command normally.
yt-dlp --cookies cookies.txt 视频地址
This will automatically download the best default video and audio, but it will most likely be in WebM format. Since I put cookies.txt in the same directory as yt-dlp.exe, I don’t need to specify the path to cookies.txt in my command.
If you want to view detailed video information with cookies.txt, the command is the same, for example:
yt-dlp -F --cookies cookies.txt 视频地址
If you don’t want the default webm format and want to use mp4 instead:
yt-dlp --cookies "cookies.txt" -f 'bv[ext=mp4]+ba[ext=m4a]' --embed-metadata --merge-output-format mp4 视频链接 #不带封面 yt-dlp --cookies "cookies.txt" -f 'bv[ext=mp4]+ba[ext=m4a]' --embed-metadata --embed-thumbnail --merge-output-format mp4 视频链接 #携带封面
Basically, just put `–cookies “cookies.txt”` at the beginning, everything else is the same.
This method also encounters a problem: expired cookies. In that case, you have to go through the process of creating a new private login window to obtain cookies again.
After looking into it, it seems other browsers can also do this.
Another method I tried (Google Chrome): Unlocking cookies.
1. First, close Google Chrome.
2. Use a command to unlock Google Chrome’s restrictions:
"C:\Program Files\Google\Chrome\Application\chrome.exe" --disable-features=LockProfileCookieDatabase
Open the command prompt and enter the parameters above. This will reopen your browser. Then, access: chrome://version/
You will then see the parameter `–disable-features=LockProfileCookieDatabase` in the command line.
Alternatively, modify the Google Chrome shortcut. In the shortcut, add the parameter `–disable-features=LockProfileCookieDatabase` to the end of the “Target” field.
This will ensure that Google Chrome is always unlocked.
However, after performing the above operations, when I use the yt-dlp command to automatically pass cookies:
yt-dlp --cookies-from-browser chrome "视频地址" yt-dlp --cookies-from-browser chrome --cookies cookies.txt "视频地址"
Neither worked, resulting in a cookie-related issue.
Other browsers:
yt-dlp --cookies-from-browser chrome #谷歌浏览器 yt-dlp --cookies-from-browser firefox #火狐浏览器 yt-dlp --cookies-from-browser edge #edge浏览器 yt-dlp --cookies-from-browser vivaldi #vivaldi浏览器
refer to:
- https://github.com/yt-dlp/yt-dlp/issues/10927
- https://github.com/yt-dlp/yt-dlp/wiki/FAQ#how-do-i-pass-cookies-to-yt-dlp
- https://github.com/yt-dlp/yt-dlp/wiki/Extractors#exporting-youtube-cookies
- https://github.com/yt-dlp/yt-dlp/wiki/FAQ#how-do-i-pass-cookies-to-yt-dlp