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

Commit

Permalink
manage missing video array plus tests
Browse files Browse the repository at this point in the history
  • Loading branch information
przemyslawpluta committed Sep 27, 2017
1 parent 17c3fb1 commit 6f2840e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
15 changes: 15 additions & 0 deletions example/missing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var ytdl = require('..');

var playlist = [
'http://www.youtube.com/watch?v=SvPZo52X5vo',
'http://www.youtube.com/watch?v=2xJWQPdG7jE'
];

ytdl.getInfo(playlist, function info(err, info) {

'use strict';
if (err) { throw err; }

console.dir(info);

});
7 changes: 6 additions & 1 deletion lib/youtube-dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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|This video has been removed by the user|Please sign in to view this video/;
var videoNotAvailable = /This video is not available|This video has been removed by the user|Please sign in to view this video|This video is no longer available/;
var subsRegex = /--write-sub|--write-srt|--srt-lang|--all-subs/;

/**
Expand Down Expand Up @@ -191,6 +191,11 @@ function call(urls, args1, args2, options, callback) {

}

if (passOver && stdout === '' && urls.length > 1) {
urls.shift();
return call(urls, args1, args2, options, callback);
}

var data = stdout.trim().split(/\r?\n/);

callback(null, data);
Expand Down
20 changes: 20 additions & 0 deletions test/getInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ vows.describe('getInfo').addBatch({
});
}
},
'from a youtube array of videos with one missing': {
'topic': function() {
'use strict';
var pl = [
'http://www.youtube.com/watch?v=SvPZo52X5vo',
'http://www.youtube.com/watch?v=2xJWQPdG7jE'
];
ytdl.getInfo(pl, this.callback);
},

'info returned': function(err, info) {
'use strict';
assert.isNull(err);
assert.isArray(info.formats);
assert.ok(info.formats.length);
info.formats.forEach(function(videoInfo) {
assert.isString(videoInfo.url);
});
}
},
'from a soundcloud track': {
'topic': function() {
'use strict';
Expand Down

0 comments on commit 6f2840e

Please sign in to comment.