Skip to content

Instantly share code, notes, and snippets.

@cacheflow
Created May 25, 2017 15:13
Show Gist options
  • Save cacheflow/39e61abdf8ba024162c31cf45e0a9e7f to your computer and use it in GitHub Desktop.
Save cacheflow/39e61abdf8ba024162c31cf45e0a9e7f to your computer and use it in GitHub Desktop.
const fs = require('fs');
const ytdl = require('./lib/index');
ytdl('https://youtu.be/fxlbIS8CoW8')
.pipe(fs.createWriteStream('video.flv'));
in util
case 'baseline':
format = formats.find(function(format) {return format.profile == 'baseline'})
break;
request(url, {}, function(err, res, body) {
if (err) {
format = util.chooseFormat(info.formats, {quality: 'baseline'});
url = format.url
}
if (format.live) {
var req = m3u8stream(url, {
chunkReadahead: +info.live_chunk_readahead,
requestOptions: options.requestOptions,
});
req.on('error', stream.emit.bind(stream, 'error'));
stream.destroy = req.end.bind(req);
req.pipe(stream);
} else {
if (options.begin) {
url += '&begin=' + util.fromHumanTime(options.begin);
}
doDownload(stream, url, options, {
trys: options.retries || 5,
range: {
start: options.range && options.range.start ? options.range.start : 0,
end: options.range && options.range.end ? options.range.end : -1,
},
downloaded: 0,
});
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment