YtDlp Class

The main entry point for the library.

1import { YtDlp } from 'ytdlp-nodejs';

Constructor

1new YtDlp(options?: YtDlpOptions)

Options

  • binaryPath (string): Custom path to yt-dlp executable.
  • ffmpegPath (string): Custom path to ffmpeg executable.

Methods

download

Returns a fluent builder for downloading videos. Chain methods to configure and call .run() to execute.

1download(url: string, options?: FormatOptions): Download

Example

1const result = await ytdlp
2  .download('https://youtube.com/watch?v=...')
3  .filter('mergevideo')
4  .quality('1080p')
5  .type('mp4')
6  .output('./downloads')
7  .embedThumbnail()
8  .on('progress', (p) => console.log(p.percentage_str))
9  .run();
10
11console.log('Files:', result.filePaths);

Builder Methods

Category Methods
Format .format(), .quality(), .type()
Output .output(), .setOutputTemplate()
Audio .extractAudio(), .audioFormat(), .audioQuality()
Embed .embedThumbnail(), .embedSubs(), .embedMetadata()
Subtitles .writeSubs(), .writeAutoSubs(), .subLangs()
Network .proxy(), .rateLimit(), .cookies()
Events .on('progress'), .on('error'), .on('finish')
Execute .run() - returns Promise<DownloadFinishResult>

downloadAsync

Downloads a video asynchronously with callback-style progress.

1downloadAsync(url: string, options?: FormatOptions): Promise<DownloadResult>

Options extended properties:

  • onProgress: Callback for download progress.
  • format: Format options object.
  • output: Custom output template.

stream

Creates a readable stream from a video URL.

1stream(url: string, options?: FormatOptions): PipeResponse

Returns an object with pipe and pipeAsync methods.

getInfoAsync

Fetches metadata for a video or playlist.

1getInfoAsync(url: string, options?: InfoOptions): Promise<VideoInfo | PlaylistInfo>

getFormatsAsync

Gets available formats for a video.

1getFormatsAsync(url: string, options?: ArgsOptions): Promise<FormatsResult>

getDirectUrlsAsync

Gets direct media URLs for a video.

1getDirectUrlsAsync(url: string, options?: ArgsOptions): Promise<string[]>

getThumbnailsAsync

Gets all thumbnails for a video.

1getThumbnailsAsync(url: string): Promise<VideoThumbnail[]>

checkInstallationAsync

Checks if binaries are installed.

1checkInstallationAsync(options?: { ffmpeg?: boolean }): Promise<boolean>

updateYtDlpAsync

Updates the yt-dlp binary.

1updateYtDlpAsync(): Promise<UpdateResult>