Last active
August 29, 2015 14:00
-
-
Save coderaiser/f1ce9146004a0a2d7100 to your computer and use it in GitHub Desktop.
express youtube
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
var express = require('express'), | |
app = express(), | |
ytdl = require('ytdl'), | |
EXT = 'mp4', | |
URL = 'https://www.youtube.com/watch?v=', | |
PORT = 8888; | |
app.get('/:id', function(req, res) { | |
var id = req.params.id; | |
download(res, id); | |
}); | |
app.listen(PORT); | |
function download(res, id) { | |
ytdl(URL + id, { | |
filter: filter | |
}).pipe(res); | |
} | |
function filter(format) { | |
var is = format.container === EXT; | |
return is; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment