Skip to content

node-migrator-bot/node-youtube-dl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

youtube-dl Build Status

Download videos from youtube in node.js using youtube-dl.

Usage

Downloading videos

var youtubedl = require('youtube-dl');
var dl = youtubedl.download('http://www.youtube.com/watch?v=90AiXO1pAiA',
  './videos',
  // optional arguments passed to youtube-dl
  ['--max-quality=18']);

// will be called when the download starts
dl.on('download', function(data) {
  console.log('Download started');
  console.log('filename: ' + data.filename);
  console.log('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('Filename: ' + data.filename);
  console.log('Size: ' + data.size);
  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!
Filename: 90AiXO1pAiA.mp4
Size: 918.31k
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

var youtubedl = require('youtube-dl');
youtubedl.info('http://www.youtube.com/watch?v=WKsjaOqDXgg',
  
  // 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);
    console.log('filename: ' + info.filename);
  }
  
  // optional arguments passed to youtube-dl
  // ['--username=user', '--password=hunter2']
  );

Running that will produce something like

title: Ace Rimmer to the Rescue
url: http://v2.lscache2.c.youtube.com/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor%2Coc%3AU0hPSFFQVF9FSkNOOV9JSlhJ&fexp=904410%2C907048%2C910100&algorithm=throttle-factor&itag=34&ipbits=0&burst=40&sver=3&signature=4093330AC1A5B0CAF8709A0416A4B593A75BB892.21F2F12C418003492D9877E1570DC7AEE6DBEEBA&expire=1303156800&key=yt1&ip=0.0.0.0&factor=1.25&id=58ab2368ea835e08
thumbnail: http://i4.ytimg.com/vi/WKsjaOqDXgg/default.jpg
description: An old Red Dwarf eposide where Ace Rimmer saves the Princess Bonjella.
filename: WKsjaOqDXgg.webm

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.

Install

npm install youtube-dl

Use the -g option if you want npm to add a symlink to youtube-dl so it can be used in command line.

Tests

Tests are written with vows

npm test

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.

License

MIT

About

youtube-dl driver for node

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.5%
  • Python 0.5%