diff --git a/lib/youtube-dl.js b/lib/youtube-dl.js index 750d7f3..3691bbb 100644 --- a/lib/youtube-dl.js +++ b/lib/youtube-dl.js @@ -21,6 +21,7 @@ var isDebug = /^\[debug\] /; var isWarning = /^WARNING: /; var isYouTubeRegex = /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.be)\//; var isNoSubsRegex = /WARNING: video doesn't have subtitles|no closed captions found/; +var videoNotAvailable = /This video is not available/; var subsRegex = /--write-sub|--write-srt|--srt-lang|--all-subs/; /** @@ -59,13 +60,11 @@ function processData(data, options, stream) { if (options && options.start > 0 && res.statusCode === 416) { // the file that is being resumed is complete. - stream.emit('complete', item); - return; + return stream.emit('complete', item); } if (res.statusCode !== 200 && res.statusCode !== 206) { - stream.emit('error', new Error('status code ' + res.statusCode)); - return; + return stream.emit('error', new Error('status code ' + res.statusCode)); } stream.emit('info', item); @@ -121,6 +120,7 @@ var ytdl = module.exports = function(videoUrl, args, options) { function call(urls, args1, args2, options, callback) { 'use strict'; var args = args1; + var passOver = false; if (args2) { args = args.concat(util.parseOpts(args2)); } @@ -145,6 +145,7 @@ function call(urls, args1, args2, options, callback) { if (id) { if ((id === 'playlist') && !options.maxBuffer) { options.maxBuffer = 7000 * 1024; } args.push(video); + args.unshift('-i'); } } } else { @@ -155,9 +156,12 @@ function call(urls, args1, args2, options, callback) { // Call youtube-dl. execFile(ytdlBinary, args, options, function done(err, stdout, stderr) { - if (err) { return callback(err); } + if (err) { + if (videoNotAvailable.test(err.message)) { passOver = true; } + if (!passOver) { return callback(err); } + } - if (stderr) { + if (stderr && !passOver) { // Try once to download video if no subtitles available if (!options.nosubs && isNoSubsRegex.test(stderr)) { var i; @@ -266,7 +270,6 @@ ytdl.getInfo = function getInfo(url, args, options, callback) { call(url, defaultArgs, args, options, function done(err, data) { if (err) { return callback(err); } - var info; try { info = data.map(parseInfo);