Skip to content

Ytdl

One YouTube session: visitor data, blocked clients, account and PO tokens belong to the instance. Use one instance per account or network identity.

new Ytdl(options?): Ytdl

Parameter Type
options? YtdlOptions

Ytdl

download(video, options?): Readable

Streams the format chooseFormat picks as a Node Readable. An unexpired info is used as is; Readable.toWeb turns the stream into a web ReadableStream.

Parameter Type
video string | VideoInfo
options? DownloadOptions

Readable


getCaptions(video, options?): Promise<string>

YouTube’s own text for one caption track, not parsed into cues. The format is CaptionFormat.Vtt unless format says otherwise. lang must equal a track’s languageCode, so de does not match de-DE. YouTube’s timedtext endpoint answers HTTP 429 after a few quick requests from one IP, which rejects with RATE_LIMITED and is not retried, so cache the text.

Parameter Type
video string | VideoInfo
options? CaptionOptions

Promise<string>


getInfo(video, options?): Promise<VideoInfo>

Video details, related videos and formats whose URLs are ready to request. A channel’s live URL, such as https://www.youtube.com/@NASA/live, looks up the stream it plays now.

Parameter Type
video string
options? LookupOptions

Promise<VideoInfo>


getPlaylist(playlist, options?): Promise<PlaylistInfo>

A playlist by ID or by a YouTube URL with a list parameter, or a channel’s uploads by channel ID or channel URL, with its entries in playlist order across pages: all of them, or the first limit. Entries YouTube marks unplayable are left out.

Parameter Type
playlist string
options? ListOptions

Promise<PlaylistInfo>


getRelated(video, options?): Promise<readonly VideoSummary[]>

The related videos getInfo returns as relatedVideos, from one next request and no player lookup. Takes the same input as getInfo.

Parameter Type
video string
options? LookupOptions

Promise<readonly VideoSummary[]>


getSuggestions(query, options?): Promise<readonly string[]>

YouTube’s autocomplete completions for query in provider order, asked in the instance’s lang and country.

Parameter Type
query string
options? LookupOptions

Promise<readonly string[]>


open(info, format): Media

One format of info, read as often as needed without another lookup. A read that re-resolves after a 403 or an expired URL refreshes Media#info, and later reads start from it.

Parameter Type
info VideoInfo
format VideoFormat

Media


search(query, options?): Promise<readonly VideoSummary[]>

Videos, or playlists with type: SearchType.Playlist, matching query in YouTube’s rank order, at most limit (20 unless set), across as many result pages as that takes. Channels, shelves and mixes are left out. Discovery requests share the instance’s visitor data and never send the cookie.

Parameter Type
query string
options? SearchOptions & object

Promise<readonly VideoSummary[]>

search(query, options): Promise<readonly PlaylistSummary[]>

Videos, or playlists with type: SearchType.Playlist, matching query in YouTube’s rank order, at most limit (20 unless set), across as many result pages as that takes. Channels, shelves and mixes are left out. Discovery requests share the instance’s visitor data and never send the cookie.

Parameter Type
query string
options SearchOptions & object

Promise<readonly PlaylistSummary[]>

search(query, options?): Promise<readonly VideoSummary[] | readonly PlaylistSummary[]>

Videos, or playlists with type: SearchType.Playlist, matching query in YouTube’s rank order, at most limit (20 unless set), across as many result pages as that takes. Channels, shelves and mixes are left out. Discovery requests share the instance’s visitor data and never send the cookie.

Parameter Type
query string
options? SearchOptions

Promise<readonly VideoSummary[] | readonly PlaylistSummary[]>