Config Files and Cookies
Typing the same options forever is what config files are for. Cookies are the other half of this chapter because they live in the same place — a setting you make once — and because they carry a risk the options do not.
The config file
A config file is a text file of long
options, one per line, exactly as they
would appear on the command line. The
lab's, kept in the repo as
yt-dlp-lab/yt-dlp.conf:
# Lab config file for yt-dlp — every line is one long option,
# exactly as it would appear on the command line.
--format 1
--output archive-test/%(title)s.%(ext)s
--download-archive archive-test/archive.txt
--socket-timeout 60
Run with it explicitly —
yt-dlp --config-location yt-dlp.conf <URL>
— and the command line needs nothing else: format, naming and archive all come from the file. Transcript t13 is the lab doing this twice against a small archive.org clip: a download the first time, an archive skip the second. Options typed on the command line override the same options in the file, so a config is a set of defaults, not a straitjacket.
yt-dlp also reads config from standard
places without being asked: a per-user
file (such as ~/.config/yt-dlp/config)
and — the part that surprises people — a
file named yt-dlp.conf in the folder
you are standing in.
The lab's accident, kept on purpose
After the config test above, later lab
commands ran in the same folder — the
TED merge (t11) and the playlist
download (t12). Both silently inherited
the archive option from that folder's
yt-dlp.conf, and both duly recorded
themselves. The archive grew to:
archiveorg big-buck-bunny-720-10s-5-mb-1
tedtalk 66
peertube gaGB17Qu1F5tXZyXN6idEQ
and the next innocent format listing was
refused with "has already been recorded
in the archive" — for a video that had
never been near the config test. Nothing
was broken; a default was doing its job
invisibly. The lessons generalise beyond
yt-dlp: know where a tool reads defaults
from, and when a command behaves as if
you had passed options you didn't,
suspect a config file before suspecting
the tool. The escape hatches are
--ignore-config (no config files at
all) and --no-config for the per-folder
ones; chapter 14 lists the symptom.
Cookies
Some pages will not talk to a downloader until it presents the cookies of a logged-in browser session — the site's proof that a person with an account asked. yt-dlp accepts them two ways:
yt-dlp --cookies-from-browser firefox <URL>
yt-dlp --cookies cookies.txt <URL>
Both are documented only in this guide: the lab used no cookies at all, and chapter 10 records the site that stayed shut without them. If you use them, understand what you are holding:
- A cookie file is a session key, close kin to a password. Anyone holding it can act as you on that site until it expires. Keep it private, keep it out of shared folders and version control, and delete it when done.
--cookies-from-browserreads the browser's own store; the browser may need to be closed first, and on some systems the store is locked down by the OS — the project's wiki tracks the current state.- Sites may treat cookie-powered downloading as a terms-of-service issue, and accounts have been limited over it. Your account, your call — made with open eyes.