youtube-dl
Download videos from youtube and other services in node.js using youtube-dl.
If you're only interested in downloading only from youtube, you should consider using pure Javascript youtube downloading module.
Installation
With npm do:
npm install youtube-dl
(you to download youtube-dl and ffmpeg binaries)
Usage
Downloading videos
var fs = ;var youtubedl = ;youtubedlvar video =;// Will be called when the download starts.video;video;
It will produce an output that looks like the following when ran.
Got video infosaving to T-ara - Number Nine - MV - 티아라-Seku9G1kT0c.mp4100.00%
Resuming partially downloaded videos
var youtubedl = ;var fs = ;var output = 'myvideo.mp4';youtubedlvar downloaded = 0;if fsdownloaded = fssize;var video =;// Will be called when the download starts.video;video;// Will be called if download was already completed and there is nothing more to download.video;video;
It will produce an output that looks like the following when ran.
Output:
[~/nodejs/node-youtube-dl/example]$ node resume.jsDownload startedfilename: 1 1 1-179MiZSibco.mp4size: 5109213^C
[~/nodejs/node-youtube-dl/example]$ node resume.jsDownload startedfilename: 1 1 1-179MiZSibco.mp4size: 5109213resuming from: 917504remaining bytes: 4191709finished downloading
Getting video information
var youtubedl = ;var url = 'http://www.youtube.com/watch?v=WKsjaOqDXgg';youtubedl// Optional arguments passed to youtube-dl.var options = '--username=user' '--password=hunter2';youtubedl;
Running that will produce something like
id: WKsjaOqDXggtitle: Ace Rimmer to the Rescueurl: http://r5---sn-p5qlsn7e.c.youtube.com/videoplayback?ms=au&ip=160.79.125.18&cp=U0hWTFVQVl9FTENONl9NSlpDOjgtU1VsODlkVmRH&id=58ab2368ea835e08&source=youtube&expire=1377558202&factor=1.25&key=yt1&ipbits=8&mt=1377534150&itag=34&sver=3&upn=-rGWz2vYpN4&fexp=912306%2C927900%2C919395%2C926518%2C936203%2C913819%2C929117%2C929121%2C929906%2C929907%2C929922%2C929127%2C929129%2C929131%2C929930%2C925726%2C925720%2C925722%2C925718%2C929917%2C906945%2C929919%2C929933%2C912521%2C932306%2C913428%2C904830%2C919373%2C930803%2C908536%2C904122%2C938701%2C936308%2C909549%2C900816%2C912711%2C904494%2C904497%2C900375%2C906001&sparams=algorithm%2Cburst%2Ccp%2Cfactor%2Cid%2Cip%2Cipbits%2Citag%2Csource%2Cupn%2Cexpire&mv=m&burst=40&algorithm=throttle-factor&signature=ABD3A847684AD9B39331E567568D3FA0DCFA4776.7895521E130A042FB3625A17242CE3C02A4460B7&ratebypass=yesthumbnail: https://i1.ytimg.com/vi/WKsjaOqDXgg/hqdefault.jpgdescription: An old Red Dwarf eposide where Ace Rimmer saves the Princess Bonjella.filename: Ace Rimmer to the Rescue-WKsjaOqDXgg.flvformat id: 34
You can use an array of urls to produce an array of response objects with matching array index (e.g. the 1st response object will match the first url etc...)
var youtubedl = ;youtubedlvar url1 = 'http://www.youtube.com/watch?v=WKsjaOqDXgg';var url2 = 'https://vimeo.com/6586873';youtubedl;
Downloading subtitles
var youtubedl = ;var url = 'https://youtu.be/PizwcirYuGY';youtubedlvar options =// Write automatic subtitle file (youtube only)auto: false// Downloads all the available subtitles.all: false// Languages of subtitles to download, separated by commas.lang: 'en'// The directory to save the downloaded files in.cwd: __dirname;youtubedl;
Downloading thumbnails
var youtubedl = ;var url = 'https://youtu.be/PizwcirYuGY';youtubedlvar options =// Downloads available thumbnail.all: false// The directory to save the downloaded files in.cwd: __dirname;youtubedl;
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.
Downloading playlists
var path = ;var fs = ;var ytdl = ;youtubedl{'use strict';var video = ;video;var size = 0;video;var pos = 0;video;video;};
Getting the list of extractors
var youtubedl = ;youtubedlyoutubedl;
Will print something like
Found 521 extractors1up.com220.ro24video3sat
youtube-dl
binary directly
Call the This module doesn't have youtube-dl
download the video. Instead, it uses the url
key from the --dump-json
CLI option to create a node stream. That way, it can be used like any other node stream.
If that, or none of the above support your use case, you can use ytdl.exec()
to call youtube-dl
however you like.
ytdl;
Update
Since the youtube-dl binary is updated regularly, you can run npm run update
to check for and download any updates for it. You can also require ../lib/downloader
in your app if you'd like to place youtube-dl
binary in a specific directory and control when it gets updates.
var downloader = ;youtubedl;
Tests
Tests are written with vows
npm test
License
MIT