While this may not work for YouTube specifically, I wanted to highlight an easier approach that works well for youtube-dl
to download from a site that requires login (and uses cookies to track the session).
Edit: Unfortunately YouTube is dependent on cookies set across multiple domains, so this approach probably will not work there.
youtube-dl has an option called --add-header
:
--add-header FIELD:VALUE Specify a custom HTTP header and its value, separated by a colon ':'. You can use this option
multiple times
Cookies are ultimately just submitted to the server as HTTP headers, so all you have to do is set the Cookie
header on the request. This method is also quite a bit easier than extracting a cookie jar from a modern browser, especially since those tend to be encrypted and people often turn to questionable 3rd party tools to extract that data.
Here is a usage example:
youtube-dl --add-header "Cookie:COOKIE_STRING_EXTRACTED_FROM_BROWSER" "https://website-that-hosts.example/the-video-you-want"
To extract the value of the cookie header:
- Open the website you wish to download from
- Log in
- Open your browser's network inspector
- Reload the page
- Find the very first request made to that website and click on it, then view the headers for the request
Copy the entire string value of the Cookie
header, highlighted in this image:
Paste that value into the example command above to replace COOKIE_STRING_EXTRACTED_FROM_BROWSER
(inside the quotes)
This works well to download full episodes from sites that require cable provider login.
-2 XXXXXXXXX
)