A pure Javascript streaming youtube video downloader.

npm install ytdl
47 downloads in the last day
216 downloads in the last week
490 downloads in the last month

node-ytdl Build Status

Yet another youtube downloading module. This time written with only Javascript and a more node-friendly streaming interface.


var fs = require('fs');
var ytdl = require('ytdl');



ytdl(url, options)

Attempts to download a video from the given url. Returns a readable stream. options can have the following keys

  • quality - Video quality to download. Can be an itag value value, highest, or lowest. Defaults to highest.
  • filter - You can give a filtering function that gets called with each format available. Used to decide what format to download. This function is given the format object as its first argument, and should return true if the format is preferable.
// Example with `filter` option.
ytdl(url, { filter: function(format) { return format.container === 'mp4'; } })

options can also have any request options.

The returned readable stream emits these additional events.

Event: 'info'

  • Object - Info.
  • Object - Format.

Emitted when the a video's info hash is fetched. Along with the chosen format metadata to download. format.url might be different if start was given. format.size will also be available.

Info and format may look like this.

ytdl.getInfo(url, [options], callback(err, info))

Use this if you only want to get metainfo from a video.

options gets passed to the request(), it can also have a downloadURL property set to true if you want ytdl to include the download url instead of the regular one. In some cases, a signature needs to be deciphered, and will require ytdl to make additional requests.


A memory cache is used to store information about recently retrieved videos. This is used to prevent double requests on videos that you want to retrieve the info of, and then download.


npm install ytdl


ytdl can be used from the command line too. Install with the -g flag to use it.

ytdl > cat.flv

And it streams!

Usage: ytdl <url> [options]

url     URL to the video.

   -v, --version                  Print program version.
   -q ITAG, --quality ITAG        Video quality to download. Default: highest
   -r INT-INT, --range INT-INT    Byte range to download. ie 10355705-12452856
   -o FILE, --output FILE         Where to save the file. Default: stdout
   --filter-container REGEXP      Filter in format container.
   --unfilter-container REGEXP    Filter out format container.
   --filter-resolution REGEXP     Filter in format resolution.
   --unfilter-resolution REGEXP   Filter out format resolution.
   --filter-encoding REGEXP       Filter in format encoding.
   --unfilter-encoding REGEXP     Filter out format encoding.
   -i, --info                     Print video info without downloading


Tests are written with mocha

npm test



npm loves you