Skip to content

Instantly share code, notes, and snippets.

@YoRyan
Last active June 4, 2026 03:08
Show Gist options
  • Select an option

  • Save YoRyan/49af08946835129f22cbfd6e7f7df312 to your computer and use it in GitHub Desktop.

Select an option

Save YoRyan/49af08946835129f22cbfd6e7f7df312 to your computer and use it in GitHub Desktop.
Obtain cookies.txt for yt-dlp without external software or browser extensions. Tested with a Firefox private browsing session.
// This work is marked CC0 1.0 Universal.
// To view a copy of this mark, visit https://creativecommons.org/publicdomain/zero/1.0/
// 1. Watch a video
// 2. Open the network inspector, and pick a request to the www.youtube.com domain
// 3. Copy the value of the Cookie: request header and store it into a string
// variable named "cookies" on the JavaScript console
// cookies = "name=value; ..."
// 4. Run the code below to obtain the contents of cookies.txt
// 5. Pass it to yt-dlp with yt-dlp --cookies /path/to/cookies.txt
const lines = cookies
.split("; ")
.map(c => {
const [, name, value] = c.match(/^([^=]+)=(.*)$/);
return [
".youtube.com",
"TRUE",
"/",
"TRUE",
Number.MAX_SAFE_INTEGER,
name,
value
].join("\t");
})
.join("\n");
console.log("# Netscape HTTP Cookie File\n" + lines);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment