'use strict';
var path = require('path');
var os = require('os');
var async = require('async');
var generateHash = require('./hash');
var downloadForHash = require('./download');

var handleSingleFile = function (name, language, destination, callback) {
  callback = arguments[arguments.length - 1];
  if (typeof callback !== 'function') {
    throw new Error('Invalid callback');
  }

  var separator = /^win/.test(process.platform) ? '\\' : '/';

  if (name.match(/^[a-f0-9]{32}$/)) {
    var hash = name;
    if (typeof destination !== 'string') {
      destination = os.tmpdir() + separator + hash + '.srt';
    }

    downloadForHash(hash, language, destination, callback);
  } else {
    var filename = name;
    generateHash(filename, function (err, hash) {
      if (err) {
        if (err.message === 'Invalid video file') {
          callback(null, 'INVALID_VIDEO_FILE');
          return;
        }

        callback(err);
        return;
      }

      if (typeof destination !== 'string') {
        destination = path.dirname(filename) + separator
          + path.basename(filename, path.extname(filename))
          + '-' + language + '.srt';
      }

      downloadForHash(hash, language, destination, function (err, dest) {
        if (err) {
          if (err.message === 'No subtitles for hash') {
            callback(null, 'SUBTITLES_NOT_FOUND');
            return;
          }

          callback(err);
          return;
        }

        callback(null, 'OK', dest);
      });
    });
  }
};

var handleMultipleFiles = function (files, language, destinations, callback) {
  callback = arguments[arguments.length - 1];
  if (typeof callback !== 'function') {
    throw new Error('Invalid callback');
  }

  var i, tasks = [];

  if (files.length === 1) {
    handleSingleFile(files[0], language, destinations[0], callback);
    return;
  }

  files.forEach(function (file) {
    tasks.push(function (callback) {
      handleSingleFile(file, language, callback);
    });
  });

  async.series(tasks, function (err, status) {
    if (err) {
      callback(err);
      return;
    }

    var temp = [], destinations = [];
    status.forEach(function (arr) {
      if (typeof arr === 'object') {
        temp.push(arr[0]);
        destinations.push(arr[1]);
      } else {
        temp.push(arr);
        destinations.push(undefined);
      }
    });

    status = temp;
    callback(null, status, destinations);
  });
};

module.exports = handleMultipleFiles;

@@ -661,24 +661,157 @@
 nation, 
-callback
+function (err, destination) %7B%0A      if (err) %7B%0A        callback(err);%0A        return;%0A      %7D%0A%0A      callback(null, 'OK', destination);%0A    %7D
 );%0A  %7D e
@@ -1005,16 +1005,27 @@
 EO_FILE'
+, undefined
 );%0A     
@@ -1502,16 +1502,27 @@
 T_FOUND'
+, undefined
 );%0A     
@@ -2330,47 +2330,8 @@
 ) %7B%0A
-      if (typeof arr === 'object') %7B%0A  
     
@@ -2349,34 +2349,32 @@
 (arr%5B0%5D);%0A      
-  
 destinations.pus
@@ -2392,116 +2392,12 @@
     
-  %7D else %7B%0A        temp.push(arr);%0A        destinations.push(undefined);%0A      %7D%0A    %7D);%0A%0A    status = temp;
+%7D);%0A
 %0A   
@@ -2412,22 +2412,20 @@
 k(null, 
-status
+temp
 , destin

Make API consistent depending on different cases