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 when requested
Browse files Browse the repository at this point in the history
this should do it ...
  • Loading branch information
przemyslawpluta committed Aug 2, 2014
1 parent aeab2dd commit 69166bf
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions lib/youtube-dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,11 @@ fs.exists(file, function(exists) {

var isYouTubeRegex = /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.be)\//;
var isNoSubsRegex = /WARNING: video doesn't have subtitles/;
var subs = ['--write-sub', '--write-srt', '--srt-lang', '--all-subs'];
var subsRegex = /--write-sub|--write-srt|--srt-lang|--all-subs/;

// Check if win.
var isWin = /^win/.test(process.platform);

/**
* Regular Expresion IndexOf for Arrays
*
* @param {Array.<String>} arr
* @param {String} rx
*/
function reIndexOf(arr, rx) {
var i;
for (i = arr.length - 1; i >= 0; i--) {
if (arr[i].toString().match(rx)) { return i; }
}
return -1;
}

/**
* Downloads a video.
*
Expand Down Expand Up @@ -121,12 +107,13 @@ function call(video, args1, args2, options, callback) {

// Try once to download video if no subtitles available
if (!options.nosubs && isNoSubsRegex.test(stderr)) {

var i;
var cleanupOpt = opt[1];

subs.map(function map(item) {
var target = reIndexOf(cleanupOpt, item);
if (target > -1) { cleanupOpt.splice(target, 1); }
});
for (i = cleanupOpt.length - 1; i >= 0; i--) {
if (subsRegex.test(cleanupOpt[i])) { cleanupOpt.splice(i, 1); }
}

options.nosubs = true;

Expand Down

0 comments on commit 69166bf

Please sign in to comment.