Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
skip over not available videos during playlist download
Browse files Browse the repository at this point in the history
  • Loading branch information
przemyslawpluta committed Mar 25, 2016
1 parent 4da180b commit 45ee26b
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/youtube-dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/;

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
Expand All @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 45ee26b

Please sign in to comment.