Skip to content

Naming Your Files

A download you cannot find again is only half a download. The output template (-o) names every file from the facts the extractor reported, using %(field)s placeholders:

yt-dlp -o "%(title)s [%(id)s].%(ext)s" <URL>

The fields you will actually use:

Field What it is
%(title)s The page's title
%(id)s The site's own ID for the item
%(ext)s The chosen format's extension
%(uploader)s Who published it
%(upload_date)s Publication date, as YYYYMMDD
%(playlist_title)s The playlist's name
%(playlist_index)s Position in the playlist
%(duration_string)s Length, as 9:56

Chapter 4's command produced, from the first two and the last of these, Big Buck Bunny [bf1f3fb5-b119-4f9f-9930-8e20e892b898].mp4. Keeping the ID in the name is a habit worth copying: titles repeat and change, IDs do neither, and the ID is what the download archive (chapter 8) remembers.

Numbers that sort

Playlist positions need padding or your file manager will sort 1, 10, 11, 2:

yt-dlp -o "%(playlist_index)02d - %(title)s.%(ext)s" <playlist URL>

02d means "a number, at least two digits, zero-padded". The lab's playlist download (transcript t12) landed as 01 - OVERGROWN - Blender Feature Film (Teaser).mp4 — sorted correctly by construction. Folders work the same way: "%(playlist_title)s/%(playlist_index)02d - %(title)s.%(ext)s" files a whole playlist into a folder of its own.

See the facts before you use them

yt-dlp --skip-download \
  --print title --print id --print uploader <URL>

prints the raw values a template will see (transcript t05 shows title, duration, ID and extractor for the lab's film). Fields a site does not provide come out as NA — the lab's playlist listing was full of them for durations — and a template naming an NA field puts the letters "NA" in your filenames. Check first on a new site.

Rough edges, honestly

Titles are written by uploaders, not by filing clerks. They contain characters your filesystem dislikes, they run long, and they occasionally contain surprises — the lab's TED download is named with a fullwidth question mark (?) because that is how the title is published, and the file is none the worse for it. Two guardrails when a collection gets messy:

  • --restrict-filenames rewrites names to plain ASCII letters, digits and underscores. Ugly, and completely predictable — a fair trade for archives that move between systems.
  • --trim-filenames N caps the length.

If a file of the target name already exists, yt-dlp leaves it alone and reports the download as already done — which is the archive behaviour of chapter 8 arriving early, and the reason re-running a command is safe.