youtube-dl driver for node
Switch branches/tags
Nothing to show
Pull request Compare This branch is 294 commits behind przemyslawpluta:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


youtubedl = require('youtube-dl');

###Downloading videos

dl ='',
  // optional arguments passed to youtube-dl

// will be called when the download starts
dl.on('download', function(data) {
  console.log('Download started');
  console.log('Video size: ' + data.size);

// will be called during download progress of a video
dl.on('progress', function(data) {
  process.stdout.write(data.eta + ' ' + data.percent + '% at ' + data.speed + '\r');

// catches any errors
dl.on('error', function(err) {
  throw err;

// called when youtube-dl finishes
dl.on('end', function(data) {
  console.log('\nDownload finished!');
  console.log('Time Taken: ' + data.timeTaken);
  console.log('Time Taken in ms: ' + data.timeTakenms);
  console.log('Average Speed: ' + data.averageSpeed);
  console.log('Average Speed in Bytes: ' + data.averageSpeedBytes);

This example can be found in the example folder, and will produce an output that looks like the following when ran.

Download started
Video size: 918.31k
00:00 100.0% at 206.12k/s
Download finished!
Time Taken: 7 seconds, 27 ms
Time Taken in ms: 7027
Average Speed: 333.74KB/s
Average Speed in Bytes: 341750.78

###Getting video information'',
  // called when video page is downloaded and info extracted
  function(err, info) {
    if (err)
      throw err;
    console.log('title: ' + info.title);
    console.log('url: ' + info.url);
    console.log('thumbnail: ' + info.thumbnail);
    console.log('description: ' + info.description);
  // optional arguments passed to youtube-dl
  // ['--username=user', '--password=hunter2']

Running that will produce something like

title: Ace Rimmer to the Rescue
description: An old Red Dwarf eposide where Ace Rimmer saves the Princess Bonjella.

For more usage info on youtube-dl and the arguments you can pass to it, do youtube-dl -h or go to the youtube-dl documentation.


npm install youtube-dl

This will install this node module along with the latest version of youtube-dl into your module folder. It will also create a symlink to youtube-dl so you run it from the command line.

API Change

Note that the API has changed in version 1.1.0. It now uses emitters to handle the download, progress, and finished events. I'm sorry for any of the invonvenience this may have caused but I'm new at this node.js thing and I just found out emitters are the best way to do this.

Issues and the Future

I haven't tested this with playlists yet because I haven't needed to use them. But my guess is they probably work with the download function but not the info function.