How to Export Safari Cookies for Yt‑Dlp in Minutes
If you’ve ever tried to download a video from a site that hides behind a login, you know the frustration of a “403 Forbidden” error. The culprit is often a missing cookie – a tiny piece of data Safari stores after you sign in. yt‑dlp can use those cookies, but Safari doesn’t expose them with a simple “Export” button. Below is a quick, no‑frills guide that walks you through pulling the cookies out of Safari and feeding them to yt‑dlp, all without leaving your Mac.
Why Safari Cookies Matter for Yt‑Dlp
Most streaming services rely on session cookies to verify that you’re a legitimate subscriber. When yt‑dlp makes a request without those cookies, the server treats it like a fresh browser session and blocks the download. By handing yt‑dlp a copy of the same cookie file Safari uses, you essentially convince the server that the request comes from your logged‑in browser.
What You’ll Need
- macOS 11 (Big Sur) or later
- Safari (obviously) – logged into the service you want to download from
- Terminal access – the built‑in app is fine
- A small helper script or the
sqlite3command‑line tool (pre‑installed on macOS) - yt‑dlp installed via
brew,pip, or a pre‑compiled binary
Step‑by‑Step: Extracting Cookies from Safari
1. Find Safari’s Cookie Store
Sizable progress often hinges on locating the right file. Safari keeps cookies in an SQLite database called Cookies.binarycookies, tucked inside your user library:
~/Library/Cookies/Cookies.binarycookiesOpen Terminal and confirm the file exists:
ls -l ~/Library/Cookies/Cookies.binarycookiesIf the path looks empty, make sure Safari is actually running and has stored at least one cookie for the target site.
2. Convert the Binary File to a Usable Format
yt‑dlp expects a Netscape‑style cookies.txt. The good news is a handy Python one‑liner does the conversion for you:
python3 - <<'PY'import sys, os, sqlite3, http.cookiejar as cookiejar
src = os.path.expanduser('~/Library/Cookies/Cookies.binarycookies')
dest = os.path.expanduser('~/Desktop/yt-dlp-cookies.txt')
# Safari’s binary format isn’t SQLite, so we use the ‘binarycookies’ package.
# Install it first if you haven’t: pip install binarycookies
import binarycookies
bc = binarycookies.BinaryCookies(src)
jar = cookiejar.MozillaCookieJar()
for page in bc.pages:
for cookie in page.cookies:
jar.set_cookie(cookie.jar_cookie())
jar.save(dest, ignore_discard=True, ignore_expires=True)
print('Cookies saved to', dest)
PY
If you prefer not to install extra packages, a third‑party utility called cookies (available via Homebrew) can perform the same job:
brew install cookiescookies export ~/Library/Cookies/Cookies.binarycookies > ~/Desktop/yt-dlp-cookies.txt
Either method drops a plain‑text cookies.txt on your Desktop, ready for yt‑dlp.
3. Pass the Cookie File to Yt‑Dlp
Now the magic happens. When you run yt‑dlp, point it at the cookie file with the --cookies flag:
yt-dlp --cookies ~/Desktop/yt-dlp-cookies.txt "https://example.com/video/123"yt‑dlp will read the stored session information and should retrieve the video just like Safari would. If you still see an authentication error, double‑check that the cookie file contains entries for the domain you’re targeting – open it in a text editor and look for lines that start with the site’s hostname.
Tips and Common Pitfalls
- Refresh Safari first. Cookies are written when you close a tab or quit the browser. If you pull the file while Safari is still running, you might get an outdated snapshot.
- Watch the expiration dates. Some services set short‑lived tokens. If yt‑dlp complains after a few hours, simply repeat the export process.
- Secure your cookie file. It grants access to your accounts, so treat it like a password. Delete it after you’re done, or store it in an encrypted folder.
- Multiple profiles? Safari doesn’t natively support separate profiles, but if you use containers like Safari Technology Preview, each version has its own
Cookies.binarycookieslocation.
Alternative: Use a Browser Extension
For those who dread the command line, the “Export Cookies” extension for Safari (available in the App Store) adds a one‑click export button. After installing, click the extension while on the target site, choose “Export as Netscape”, and save the file wherever you like. Then run yt‑dlp with the same --cookies flag as shown above.
Wrapping It Up
Getting Safari cookies into yt‑dlp isn’t a secret reserved for power users; it’s a handful of clicks or a quick script away. Once you’ve saved the cookies.txt, the rest of yt‑dlp’s feature set – format selection, subtitle download, batch processing – becomes available for any site that would otherwise block you. Keep the file safe, refresh it when needed, and enjoy a smoother downloading experience.