'use strict';

var path = require('path');
var async = require('async');
var _ = require('lodash');
var parse = require('../lib/torrent-parser');
var glob = require('../plugins/input/glob');
var customCommand = require('../plugins/input/customCommand');

module.exports = function(program, config, done) {
  async.waterfall([
    function (next) {
      if (config.input.globs) {
        glob(config.input.globs, next);
      } else if (config.input.customCommand) {
        customCommand(program, config.input.customCommand).exec(next);
      } else {
        program.log.error('no input specified');
      }
    },
    function (filePaths, next) {
      // TODO extract to input filters
      var filtered = _.filter(filePaths, function (filePath) {
        return -1 !== _.indexOf(['.avi', '.mp4', '.mpg', '.mkv'], path.extname(filePath));
      });
      next(null, filtered)
    },
    function (filePaths, next) {
      async.map(filePaths, parse.bind(null, program, config), next);
    }
  ], done);
}

@@ -696,159 +696,399 @@
 var 
-filtered = _.filter(filePaths, function (filePath) %7B%0A        return -1 !== _.indexOf(%5B'.avi', '.mp4', '.mpg', '.mkv'%5D, path.extname(filePath));%0A      %7D
+allowedExt = %5B'.avi', '.mp4', '.mpg', '.mkv'%5D;%0A      var regex = /(Extras%7CSample%7CE00)/;%0A%0A      program.log.debug('%25s files found', filePaths.length);%0A      var filtered = _.filter(filePaths, function (filePath) %7B%0A        return -1 !== _.indexOf(allowedExt, path.extname(filePath)) && !regex.test(filePath);%0A      %7D);%0A%0A      program.log.debug('%25s files remained after filter', filtered.length
 );%0A 

Move all input filtering to emit episodes for now