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

Commit

Permalink
fix for failed download with no subtitles
Browse files Browse the repository at this point in the history
At the moment if video doesn't have subtitles `youtube-dl` fails with ... 

```js
events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: : video doesn't have subtitles

    at /test/youtube-dl/lib/youtube-dl.js:122:23
    at ChildProcess.exithandler (child_process.js:645:7)
    at ChildProcess.emit (events.js:98:17)
    at maybeClose (child_process.js:755:16)
    at Process.ChildProcess._handle.onexit (child_process.js:822:5)
```

... this fix catches and removes possible options passed by the user and tries once to download video only without the subtitles.
  • Loading branch information
przemyslawpluta committed Jul 31, 2014
1 parent 3cf3363 commit 36fd75a
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/youtube-dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ var ytdl = module.exports = function(url, args, options) {
* @param {Function(!Error, String)} callback
*/
function call(video, args1, args2, options, callback) {

var args = args1.concat(util.parseOpts(args2));

// Parse url.
Expand Down Expand Up @@ -98,9 +99,28 @@ function call(video, args1, args2, options, callback) {

// Call youtube-dl.
execFile(opt[0], opt[1], options, function(err, stdout, stderr) {

if (err) return callback(err);
if (stderr) return callback(new Error(stderr.slice(7)));

if (stderr) {

// Try once to download video if no subtitles available
if (stderr.indexOf('WARNING: video doesn\'t have subtitles') !== -1 && !options.nocc) {
var cleanupOpt = opt[1];

['--write-sub', '--srt-lang=en', '--all-subs'].map(function map(item) {
var target = cleanupOpt.indexOf(item);
if (target > -1) { cleanupOpt.splice(target, 1); }
});

options.nocc = true;

return call(video, args1, cleanupOpt, options, callback);

}

return callback(new Error(stderr.slice(7)));
}
var data = stdout.trim().split(/\r?\n/);
callback(null, data);
});
Expand Down Expand Up @@ -163,7 +183,7 @@ ytdl.getInfo = function(url, args, options, callback) {

var playlist = [];
var track = [];

data.forEach(function(row) {
track.push(row);

Expand Down

0 comments on commit 36fd75a

Please sign in to comment.