diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/initialize.js | 2 | ||||
-rw-r--r-- | lib/videos.js | 26 |
2 files changed, 21 insertions, 7 deletions
diff --git a/lib/initialize.js b/lib/initialize.js index 195423a..9552c41 100644 --- a/lib/initialize.js +++ b/lib/initialize.js @@ -38,7 +38,7 @@ module.exports = function run(profile, argv) { mdbvideos.init(answers, argv, function get(err, data, profile) { - if (err !== null) { throw err; } + if (err !== null) { return console.log('i'.red + ' ' + err.stack + '.\n'); } if (profile.preset.video[1] === videoPreference || argv.h) { return processList(data, profile); } diff --git a/lib/videos.js b/lib/videos.js index 1dde7e1..7c2e56d 100644 --- a/lib/videos.js +++ b/lib/videos.js @@ -17,10 +17,11 @@ var path = require('path'), extract = require('extract-zip'), rimraf = require('rimraf'), mv = require('mv'), - _ = require('lodash'); + _ = require('lodash'), + moment = require('moment'); var isDebug = /[debug]/, downloadPath = '', proxy = '', downloadList = [], hash = {}, - co = false, ncc = false, handout = false, cc = false, uz = false, hq = false, verbose = false; + co = false, ncc = false, handout = false, cc = false, uz = false, hq = false, verbose = false, retry = 0, maxRetry; function setOptions(argv) { @@ -34,6 +35,7 @@ function setOptions(argv) { if (argv.uz) { uz = true; } if (argv.hq) { hq = true; } if (argv.co) { co = true; } + if (argv.retry) { retry = argv.retry; } if (argv.verbose) { verbose = true; } } @@ -160,7 +162,7 @@ var handleList = function handleList(list, tags) { }); }, - getVideos = function getVideos(item, nocc, notAvailable) { + getVideos = function getVideos(item, notAvailable) { if (handout) { return getHandouts(item); } @@ -170,7 +172,7 @@ var handleList = function handleList(list, tags) { downloaded = fs.statSync(downloadPath + hash[item]).size; } - var dl = youtubedl(item, nocc || opt, {start: downloaded, cwd: downloadPath}); + var dl = youtubedl(item, opt, {start: downloaded, cwd: downloadPath}); dl.on('info', function(info) { size = info.size + downloaded; @@ -198,9 +200,16 @@ var handleList = function handleList(list, tags) { if (err.message.indexOf('requested format not available') !== -1) { _.pull(opt, '--format=22'); opt.push('--format=18'); - return getVideos(item, nocc, true); + return getVideos(item, true); } - console.log(err.stack); + + if (err.message.match(/Command failed: python|ENETDOWN|ENOTFOUND|EAI_AGAIN/) && retry !== 0) { + if (!maxRetry) { maxRetry = moment().add(retry, 'seconds'); } + if (maxRetry && maxRetry.diff(moment()) > 0) { return delay(item); } + } + + console.log('i'.red + ' Download Failed: '.red + err.stack); + }); dl.on('close', function close() { @@ -208,10 +217,15 @@ var handleList = function handleList(list, tags) { }); dl.on('end', function end() { + maxRetry = null; var left = (currentList.length) ? currentList.length + ' left ...' : ''; console.timeEnd('i'.magenta + ' ' + stash._filename + '. Done in'); getSubtitles(item, left, currentList, tags); }); + }, + + delay = function delay(target) { + setTimeout(function timeout() { getVideos(target); }, 5000); }; if (currentList.length) { |