Yet another youtube downloading module. This time written with only Javascript and a more node-friendly streaming interface.
For a CLI version of this, check out ytdl.
var fs = require('fs');
var ytdl = require('ytdl-core');
ytdl('http://www.youtube.com/watch?v=A02s8omM_hI')
.pipe(fs.createWriteStream('video.flv'));
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
, orlowest
. Defaults tohighest
.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 theformat
object as its first argument, and should return true if the format is preferable.range
- A byte range in the formINT-INT
that specifies a part of the video to download. ie 10355705-12452856.
// Example with `filter` option.
ytdl(url, { filter: function(format) { return format.container === 'mp4'; } })
.pipe(fs.createWriteStream('vide.mp4'));
options
can also have any request options.
The returned readable stream emits these additional events.
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.
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.
Once you have received metadata from a video with the getInfo
function,
you may pass that info
, along with other options
to downloadFromInfo
.
Note: Be sure to set the downloadURL
option to true
when you call getInfo
or you will receive a 403 error when you call downloadFromInfo
.
The returned readable stream emits these additional events:
Object
- Format.
Emitted when a format metadata has been chosen. format.size
will also be available.
npm install ytdl-core
Tests are written with mocha
npm test
MIT