Output Templates in yt-dlp
Output templates in yt-dlp allow you to customize the naming and organization of downloaded files. The -o
option specifies the output filename template, while -P
sets the download paths for different file types.
Basic Syntax
The simplest usage is to specify a fixed filename:
yt-dlp -o "funny_video.mp4" "https://some/video"
Fixed filename (not recommended for multiple videos).
yt-dlp -o "%(title)s [%(id)s].%(ext)s" URL
Template with video title and ID.
Template Format
Template sequences use the format: %(field_name)s
The general syntax for complex field operations is:
%(name[.keys][addition][>strf][,alternate][&replacement][|default])[flags][width][.precision][length]type
Available Fields
Basic Video Information
id
- Video identifiertitle
- Video titlefulltitle
- Video title ignoring live timestamp and generic titlealt_title
- Secondary title of the videodescription
- Video descriptiondisplay_id
- Alternative identifier for the videoext
- Video filename extension
Uploader Information
uploader
- Full name of the video uploaderuploader_id
- Nickname or id of the video uploaderuploader_url
- URL to the video uploader's profilechannel
- Full name of the channel the video is uploaded onchannel_id
- Id of the channelchannel_url
- URL of the channelchannel_follower_count
- Number of followers of the channelchannel_is_verified
- Whether the channel is verified
Date and Time
timestamp
- UNIX timestamp of when video became availableupload_date
- Video upload date in UTC (YYYYMMDD)release_timestamp
- UNIX timestamp of when video was releasedrelease_date
- Release date (YYYYMMDD) in UTCrelease_year
- Year when video/album was releasedmodified_timestamp
- UNIX timestamp of last modificationmodified_date
- Last modification date (YYYYMMDD) in UTC
Video Properties
duration
- Length of video in secondsduration_string
- Length of video (HH:mm:ss)view_count
- Number of viewsconcurrent_view_count
- Current live viewerslike_count
- Number of positive ratingsdislike_count
- Number of negative ratingsrepost_count
- Number of repostsaverage_rating
- Average rating given by userscomment_count
- Number of comments
Technical Details
width
- Video width in pixelsheight
- Video height in pixelsfps
- Frame ratetbr
- Total bitratevbr
- Video bitrateabr
- Audio bitrateasr
- Audio sample ratevcodec
- Video codecacodec
- Audio codeccontainer
- Container formatfilesize
- File size in bytesfilesize_approx
- Approximate file size
Playlist Information
playlist
- Playlist title (or ID if title unavailable)playlist_id
- Identifier of the playlistplaylist_title
- Name of the playlistplaylist_count
- Total number of items in playlistplaylist_index
- Index of video in playlist (padded with zeros)playlist_autonumber
- Position in download queueplaylist_uploader
- Full name of playlist uploaderplaylist_uploader_id
- Nickname/ID of playlist uploaderplaylist_channel
- Channel that uploaded the playlistplaylist_channel_id
- ID of channel that uploaded playlist
Series and Episodes
series
- Title of the series/programseries_id
- ID of the series/programseason
- Title of the seasonseason_number
- Number of the seasonseason_id
- ID of the seasonepisode
- Title of the episodeepisode_number
- Number of the episode within seasonepisode_id
- ID of the episode
Music and Audio
track
- Title of the tracktrack_number
- Number of track within album/disctrack_id
- ID of the trackartist
- Artist(s) of the track (comma-separated)artists
- List of artistsalbum
- Title of the albumalbum_type
- Type of the albumalbum_artist
- All artists on album (comma-separated)album_artists
- List of all album artistsgenre
- Genre(s) (comma-separated)genres
- List of genrescomposer
- Composer(s) (comma-separated)composers
- List of composersdisc_number
- Number of disc/physical medium
Other Fields
webpage_url
- URL of the video webpagewebpage_url_basename
- Basename of webpage URLwebpage_url_domain
- Domain of webpage URLoriginal_url
- Original URL given by userextractor
- Name of the extractorextractor_key
- Key name of the extractorage_limit
- Age restriction (years)live_status
- Live status (not_live, is_live, is_upcoming, was_live, post_live)is_live
- Whether video is a live streamwas_live
- Whether video was originally livelocation
- Physical location where video was filmedcategories
- List of categoriestags
- List of tagslanguage
- Language code
Field Operations
Object Traversal
Navigate through dictionaries and lists using dot notation:
%(tags.0)s
Access first tag.
%(subtitles.en.-1.ext)s
Access last subtitle.
%(id.3:7)s
Python slicing.
%(formats.:.format_id)s
Python slicing.
%(formats.:.{format_id,height})#j
Build dictionaries with specific keys.
Arithmetic Operations
Perform simple math on numeric fields:
%(playlist_index+10)03d
Add to playlist index.
%(n_entries+1-playlist_index)d
Calculate remaining items.
%(duration*2)d
Multiply duration.
Date/Time Formatting
Format date/time fields using strftime:
%(duration>%H-%M-%S)s
Format duration as HH-MM-SS.
%(upload_date>%Y-%m-%d)s
Format upload date.
%(epoch-3600>%H-%M-%S)s
Format with timezone offset.
Alternative Fields
Specify fallback values with comma separation:
%(release_date>%Y,upload_date>%Y|Unknown)s
Use release_date, fallback to upload_date, then "Unknown".
%(artist,creator,uploader|Unknown Artist)s
Use multiple alternatives.
Replacement Values
Use &
to provide replacement text when field is not empty:
%(chapters&has chapters|no chapters)s
Replace with custom text if chapters exist.
%(title&TITLE={:>20}|NO TITLE)s
Format title with custom template.
Default Values
Use |
to specify default values for empty fields:
%(uploader|Unknown)s
Default uploader if unknown.
%(language|en)s
Default language.
Format Conversions
Special conversion types beyond standard Python formatting:
%(filesize)B
Bytes conversion.
%(formats)j
Compact JSON.
%(formats)#j
Pretty-printed JSON.
%(formats)+j
Unicode JSON.
%(description)h
HTML escaping.
%(tags)l
Comma-separated list.
%(tags)#l
Newline-separated list.
%(title)q
Quote for terminal.
%(tags)#q
Split list into separate arguments.
%(filesize)D
Decimal suffixes (10M, 1.5G, etc.).
%(filesize)#D
Use 1024 as factor.
%(title)S
Sanitize for filename.
%(title)#S
Restricted sanitization.
%(title)U
NFC normalization.
%(title)#U
NFD normalization.
%(title)+U
NFKC normalization.
Output Template Examples
Basic Examples
yt-dlp -o "%(title)s [%(id)s].%(ext)s" URL
Simple filename with title and ID.
yt-dlp -o "%(uploader)s - %(title)s.%(ext)s" URL
Include uploader name.
yt-dlp -o "%(upload_date)s - %(title)s.%(ext)s" URL
Add upload date.
yt-dlp -o "%(title)s.%(ext)s" --restrict-filenames URL
Restrict filename characters.
Hierarchical Organization
yt-dlp -o "%(uploader)s/%(title)s.%(ext)s" URL
Organize by uploader.
yt-dlp -o "%(upload_date>%Y)s/%(title)s.%(ext)s" URL
Organize by upload year.
yt-dlp -o "%(uploader)s/%(upload_date>%Y)s/%(title)s [%(id)s].%(ext)s" URL
Complex hierarchy.
Playlist Organization
yt-dlp -o "%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s" PLAYLIST_URL
Organize playlist with index.
yt-dlp -o "%(uploader)s/%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s" PLAYLIST_URL
Separate playlists by uploader.
yt-dlp -o "%(playlist)s/%(chapter_number)s - %(chapter)s/%(title)s.%(ext)s" COURSE_URL
Chapter organization for courses.
Series and Episodes
yt-dlp -o "%(series)s/Season %(season_number)02d/S%(season_number)02dE%(episode_number)02d - %(episode)s.%(ext)s" URL
TV series organization.
yt-dlp -o "%(series)s/%(season_number)s - %(season)s/%(episode_number)s - %(episode)s.%(ext)s" URL
Alternative series format.
Music Organization
yt-dlp -o "%(artist)s/%(album)s/%(track_number)02d - %(track)s.%(ext)s" URL
Album organization.
yt-dlp -o "%(album_artist)s/%(album)s/%(track_number)02d - %(artist)s - %(track)s.%(ext)s" URL
Various artists compilation.
yt-dlp -o "%(artist)s - %(track)s.%(ext)s" URL
Single tracks.
Advanced Examples
yt-dlp -o "%(playlist_index&{} - |)s%(title)s.%(ext)s" URL
Conditional formatting.
yt-dlp -o "%(filesize>1000000000&Large/|Normal/)s%(title)s.%(ext)s" URL
Size-based organization.
yt-dlp -o "%(title)s [%(height)sp].%(ext)s" URL
Quality-based naming.
yt-dlp -o "%(creator,uploader,channel|Unknown)s - %(title)s.%(ext)s" URL
Multi-field fallbacks.
File Type Specific Templates
Set different templates for different file types:
yt-dlp -o "%(title)s.%(ext)s" -o "thumbnail:%(title)s/%(title)s.%(ext)s" URL
Different templates for videos and thumbnails.
yt-dlp -o "%(title)s.%(ext)s" -o "subtitle:%(title)s/subs/%(title)s.%(ext)s" URL --write-subs
Separate subtitle organization.
yt-dlp -o "videos/%(title)s.%(ext)s" -o "infojson:metadata/%(title)s.%(ext)s" URL --write-info-json
Info JSON in separate directory.
Available File Types
subtitle
- Subtitle filesthumbnail
- Thumbnail imagesdescription
- Description filesannotation
- Annotation files (deprecated)infojson
- Video metadata JSON fileslink
- Internet shortcut filespl_thumbnail
- Playlist thumbnailspl_description
- Playlist descriptionspl_infojson
- Playlist metadata JSONchapter
- Chapter files (when splitting)pl_video
- Playlist videos (when concatenating)
Path Configuration
Use -P
to set base paths for different file types:
yt-dlp -P "~/Videos" -P "subtitle:~/Videos/Subs" -P "thumbnail:~/Videos/Thumbs" URL
Set different base paths.
yt-dlp -P "~/Videos" -P "temp:/tmp/yt-dlp" URL
Temporary directory for intermediate files.
yt-dlp -P "home:~/Downloads" -o "%(title)s.%(ext)s" URL
Home directory override.
Best Practices
Filename Safety
yt-dlp -o "%(title)S.%(ext)s" --restrict-filenames URL
Use restricted filenames for cross-platform compatibility.
yt-dlp -o "%(title).100s.%(ext)s" --trim-filenames 100 URL
Limit filename length.
yt-dlp -o "%(title)s.%(ext)s" --windows-filenames URL
Avoid special characters.
Organization Strategies
yt-dlp -o "%(extractor)s/%(uploader)s/%(title)s.%(ext)s" URL
By content type.
yt-dlp -o "%(release_date>%Y,upload_date>%Y|Unknown)s/%(title)s.%(ext)s" URL
By date with fallbacks.
yt-dlp -o "%(extractor)s/%(uploader)s/%(upload_date>%Y)s/%(title)s [%(id)s].%(ext)s" URL
Comprehensive organization.
Handling Missing Fields
yt-dlp -o "%(uploader|Unknown)s/%(title|Untitled)s [%(id)s].%(ext)s" URL
Provide defaults for all important fields.
yt-dlp -o "%(uploader&%(uploader)s/|)s%(title)s.%(ext)s" URL
Use field availability checks.
Troubleshooting
Testing Templates
yt-dlp --print filename -o "your_template" URL
Print filename without downloading.
yt-dlp -j URL | jq .
Check all available fields.
yt-dlp -s -o "your_template" URL
Test template with simulation.
Common Issues
- Invalid characters: Use
%(title)S
for sanitization - Path too long: Use
--trim-filenames
or shorter templates - Missing fields: Always provide defaults with
|
- Unicode issues: Use
%(title)U
for normalization
The output template system is extremely flexible and can accommodate virtually any file organization scheme. Start simple and add complexity as needed.