Improve API for episode downloader.

This commit is contained in:
Roel van Uden 2015-01-23 20:48:15 +01:00
parent 256f9cd887
commit faac313553
2 changed files with 12 additions and 12 deletions

View File

@ -18,7 +18,7 @@
"quotmark" : "single", "quotmark" : "single",
"undef" : true, "undef" : true,
"unused" : true, "unused" : true,
"singleGroups" : true, "singleGroups" : false,
"strict" : true, "strict" : true,
"maxparams" : 5, "maxparams" : 5,
"maxdepth" : 5, "maxdepth" : 5,

View File

@ -11,7 +11,7 @@ var xml2js = require('xml2js');
* Streams the episode video and subtitle to disk. * Streams the episode video and subtitle to disk.
* @param {Object} config * @param {Object} config
* @param {string} address * @param {string} address
* @param {function(Error)} done * @param {function(Error, boolean=)} done
*/ */
module.exports = function (config, address, done) { module.exports = function (config, address, done) {
_page(address, function(err, page) { _page(address, function(err, page) {
@ -59,7 +59,7 @@ function _complete(message, begin, done) {
* @param {Object} config * @param {Object} config
* @param {Object} page * @param {Object} page
* @param {Object} player * @param {Object} player
* @param {function(Error)} done * @param {function(Error, boolean=)} done
*/ */
function _download(config, page, player, done) { function _download(config, page, player, done) {
var tag = config.tag || 'CrunchyRoll'; var tag = config.tag || 'CrunchyRoll';
@ -67,7 +67,7 @@ function _download(config, page, player, done) {
var fileName = page.series + ' - ' + episode + ' [' + tag + ']'; var fileName = page.series + ' - ' + episode + ' [' + tag + ']';
var filePath = path.join(config.path || process.cwd(), fileName); var filePath = path.join(config.path || process.cwd(), fileName);
_subtitle(config, player, filePath, function(err, exists) { _subtitle(config, player, filePath, function(err, exists) {
if (err || exists) return done(err || undefined); if (err || exists) return done(err, err ? undefined : false);
var begin = Date.now(); var begin = Date.now();
console.log('Fetching ' + fileName); console.log('Fetching ' + fileName);
_video(config, page, player, filePath, function(err, exists) { _video(config, page, player, filePath, function(err, exists) {
@ -171,14 +171,14 @@ function _subtitle(config, player, filePath, done) {
} }
/** /**
* Streams the video to disk. * Streams the video to disk.
* @private * @private
* @param {Object} config * @param {Object} config
* @param {Object} page * @param {Object} page
* @param {Object} player * @param {Object} player
* @param {string} filePath * @param {string} filePath
* @param {function(Error, boolean=)} done * @param {function(Error, boolean=)} done
*/ */
function _video(config, page, player, filePath, done) { function _video(config, page, player, filePath, done) {
var extension = path.extname(player.video.file); var extension = path.extname(player.video.file);
fs.exists(filePath + (config.merge ? '.mkv' : extension), function(exists) { fs.exists(filePath + (config.merge ? '.mkv' : extension), function(exists) {