<commit_before>var spawn        = require('child_process').spawn;
var execFile     = require('child_process').execFile;
var EventEmitter = require('events').EventEmitter;
var fs           = require('fs');
var path         = require('path');
var url          = require('url');
var split        = require('event-stream').split;
var util         = require('./util');


// Check that youtube-dl file exists.
var file = path.join(__dirname, '..', 'bin', 'youtube-dl');
fs.exists(file, function(exists) {
  if (exists) return;

  require(__dirname + '/../scripts/download');
  fs.exists(file, function(exists) {
    if (!exists) {
      throw new Error('youtube-dl file does not exist. tried to download it but failed.');
    }
  });
});

var progressRegex = /(\d+(?:\.\d)?)% of (\d+\.\d+\w+) at\s+([^\s]+) ETA ((\d|-)+:(\d|-)+)/;


/**
 * Downloads a video.
 *
 * @param {String} urladdr
 * @param {String} dest The directory where the video will be saved.
 * @param {Array.<String>} args
 */
exports.download = function(urladdr, dest, args) {
  // Setup settings.
  dest = dest || process.cwd();
  if (args == null) {
    args = [];
  } else {
    args = util.parseOpts(args);
  }
  args.push(urladdr);

  // Get ID from urladdr.
  var query = url.parse(urladdr, true).query;
  var id = query.v || '';

  // Call youtube-dl.
  var youtubedl = spawn(file, args, { cwd: dest });
  var speed = [];
  var start = Date.now();

  var filename, size, state;
  var emitter = new EventEmitter();
  var line = new split(/\r?\n|\r/);

  youtubedl.stdout.setEncoding('utf8');
  youtubedl.stdout.pipe(line);
  line.on('data', function(data) {
    var pos;<commit_msg>spawn ENOENT in win<commit_after>var spawn        = require('child_process').spawn;
var execFile     = require('child_process').execFile;
var EventEmitter = require('events').EventEmitter;
var fs           = require('fs');
var path         = require('path');
var url          = require('url');
var split        = require('event-stream').split;
var util         = require('./util');


// Check that youtube-dl file exists.
var file = path.join(__dirname, '..', 'bin', 'youtube-dl');
fs.exists(file, function(exists) {
  if (exists) return;

  require(__dirname + '/../scripts/download');
  fs.exists(file, function(exists) {
    if (!exists) {
      throw new Error('youtube-dl file does not exist. tried to download it but failed.');
    }
  });
});

var progressRegex = /(\d+(?:\.\d)?)% of (\d+\.\d+\w+) at\s+([^\s]+) ETA ((\d|-)+:(\d|-)+)/;


/**
 * Downloads a video.
 *
 * @param {String} urladdr
 * @param {String} dest The directory where the video will be saved.
 * @param {Array.<String>} args
 */
exports.download = function(urladdr, dest, args) {
  // Setup settings.
  dest = dest || process.cwd();
  if (args == null) {
    args = [];
  } else {
    args = util.parseOpts(args);
  }
  args.push(urladdr);

  // Get ID from urladdr.
  var query = url.parse(urladdr, true).query;
  var id = query.v || '';

  // check if win
  var isWin = /^win/.test(process.platform);
    
  // Call youtube-dl.
  var youtubedl = (isWin)? spawn('python', [file].concat(args), { cwd: dest }): spawn(file, args, { cwd: dest });
  var speed = [];
  var start = Date.now();

  var filename, size, state;
  var emitter = new EventEmitter();
  var line = new split(/\r?\n|\r/);

  youtubedl.stdout.setEncoding('utf8');
  youtubedl.stdout.pipe(line);
  line.on('data', function(data) {
    var pos;
{'fraction_non_alphanumeric': 0.19179278230500582, 'fraction_numerical': 0.0005820721769499418, 'mean_word_length': 2.9826187717265356, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4579760', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1151, 'n_words': 303}