Advanced Usage

This section covers more complex scenarios and configuration options for ytdlp-nodejs.

Raw Arguments

Sometimes you may need to use a specific yt-dlp flag that isn't explicitly typed in ytdlp-nodejs. You can use the addArgs method or rawArgs option to pass any argument directly to the executable.

1// Using fluent builder API
2const result = await ytdlp
3  .download(url)
4  .format({ filter: 'mergevideo', quality: '1080p', type: 'mp4' })
5  .addArgs('--match-filter', 'duration > 60')
6  .run();
7
8// Using downloadAsync
9await ytdlp.downloadAsync(url, {
10  rawArgs: ['--match-filter', 'duration > 60'],
11});

JavaScript Runtime

Some extractors (like YouTube) require a JavaScript runtime to decrypt signatures. ytdlp-nodejs defaults to using the node runtime, but you can change this if needed.

1await ytdlp.execAsync(url, {
2  jsRuntime: 'deno', // or 'phantomjs', 'none'
3});

Supported runtimes: node, deno, phantomjs.

Custom Binaries

If you want to use a specific version of yt-dlp or ffmpeg that is already installed on your system:

1const ytdlp = new YtDlp({
2  binaryPath: '/path/to/custom/yt-dlp',
3  ffmpegPath: '/path/to/custom/ffmpeg',
4});

Proxy Configuration

You can route traffic through a proxy:

1// Using fluent builder API
2const result = await ytdlp
3  .download(url)
4  .proxy('http://user:pass@proxyhost:port')
5  .run();
6
7// Using downloadAsync
8await ytdlp.downloadAsync(url, {
9  proxy: 'http://user:pass@proxyhost:port',
10});

For age-gated content or premium accounts, you can provide cookies.

From Browser

Use cookies from a browser where you are logged in:

1// Using fluent builder API
2const result = await ytdlp
3  .download(url)
4  .cookiesFromBrowser('chrome') // or 'firefox', 'edge'
5  .run();
6
7// Using downloadAsync
8await ytdlp.downloadAsync(url, {
9  cookiesFromBrowser: 'chrome',
10});

From File

Use a Netscape-formatted cookies file:

1// Using fluent builder API
2const result = await ytdlp.download(url).cookies('/path/to/cookies.txt').run();
3
4// Using downloadAsync
5await ytdlp.downloadAsync(url, {
6  cookies: '/path/to/cookies.txt',
7});

Debugging

To see exactly what yt-dlp command is being executed, enable command logging:

1await ytdlp.execAsync(url, {
2  debugPrintCommandLine: true,
3  verbose: true,
4});

This will print the full command to the console (stderr).