Skip to content

tk120404/node-ytdl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-ytdl Build Status

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

Usage

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

ytdl('http://www.youtube.com/watch?v=A02s8omM_hI')
  .pipe(fs.createWriteStream('video.flv'));

API

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.
  • start - Where to begin downloading the video in milliseconds or in a time format ie 1m34s.
  • filter - You can give a filtering function that gets called with each format available. Used to decide what format to download.
// Example with `filter` option.
ytdl(url, { filter: function(format) { return format.container === 'mp4'; } })
  .pipe(fs.createWriteStream('vide.flv'));

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.

ytdl.getInfo(url, callback(err, info))

Use this if you only want to get metainfo from a video. info may look like this.

Install

npm install ytdl

CLI

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

ytdl http://www.youtube.com/watch?v=_HSylqgVYQI > cat.flv

And it streams!

Usage: ytdl <url> [options]

url     URL to the video.

Options:
   -v, --version                  Print program version.
   -q ITAG, --quality ITAG        Video quality to download. Default: `highest`
   -s TIME, --start TIME          Where to begin the video. ie 1m3s, 45s, 2300.
   -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.

Tests

Tests are written with mocha

npm test

License

MIT

About

Pure Javascript youtube video downloader.

Resources

License

Stars

Watchers

Forks

Packages

No packages published