<commit_before>"use strict";

const spawn = require('child_process').spawn;

const ffmpegTimeToSec = require('./lib/ffmpegTimeToSec');

module.exports = function convertFile(args) {
  var _this = this;

  return new Promise(function (resolve, reject) {
    const new_file_name = args.temp_dir + '/' + args.file_name + '.mp3';
    const ffmpeg = spawn('ffmpeg', ['-i', args.temp_file_loc, '-f', 'mp3', new_file_name]);

    let total_duration_secs;
    console.log(ffmpeg.stderr);
    ffmpeg.stderr.setEncoding('utf8');
    ffmpeg.stderr.on('data', function (data) {
      //console.log(data.toString());
      if (data.indexOf('Overwrite ? [y/N]') !== -1) ffmpeg.stdin.write('y\n');else if (data.indexOf('Duration: ') !== -1) {
        let duration_matches = args.duration_re.exec(data.toString());
        if (duration_matches instanceof Array && duration_matches[1]) {
          total_duration_secs = ffmpegTimeToSec(duration_matches[1]);
        } else {
          console.log('heloooooo\n\n\n\n\n');
          //console.log(data.toString());
          console.log('\n\n\n\n\n');
          reject('no duration_matches[1], could not extract total file time');
        }
      } else if (data.indexOf('time=') !== -1) {
        let time_matches = args.time_re.exec(data.toString());
        if (time_matches[1]) {
          _this.emit('conversion-progress', {
            current: ffmpegTimeToSec(time_matches[1]),
            total: total_duration_secs
          });
        } else {
          reject('no time_matches[1], could not extract current conversion time');
        }
      }
    });

    ffmpeg.on('error', function (err) {
      return reject(err);
    });

    ffmpeg.on('close', function (code) {
      if (code === 0) resolve(new_file_name);else reject('ffmpeg exited with code ' + code);
    });
  });
};<commit_msg>Correctly saving result w/ file ext<commit_after>"use strict";

const spawn = require('child_process').spawn;

const ffmpegTimeToSec = require('./lib/ffmpegTimeToSec');

module.exports = function convertFile(args) {
  var _this = this;

  return new Promise(function (resolve, reject) {
    const new_file_name = args.temp_dir + '/' + args.file_name + '.mp3';
    const ffmpeg = spawn('ffmpeg', ['-i', args.temp_file_loc, '-f', 'mp3', new_file_name]);

    let total_duration_secs;
    console.log(ffmpeg.stderr);
    ffmpeg.stderr.setEncoding('utf8');
    ffmpeg.stderr.on('data', function (data) {
      //console.log(data.toString());
      // Let's chech for the byte length instead of specific duration: string
      if (data.indexOf('Overwrite ? [y/N]') !== -1) ffmpeg.stdin.write('y\n');else if (data.indexOf('Duration: ') !== -1) {
        let duration_matches = args.duration_re.exec(data.toString());
        if (duration_matches instanceof Array && duration_matches[1]) {
          total_duration_secs = ffmpegTimeToSec(duration_matches[1]);
        } else {
          console.log('heloooooo\n\n\n\n\n');
          //console.log(data.toString());
          console.log('\n\n\n\n\n');
          reject('no duration_matches[1], could not extract total file time');
        }
      } else if (data.indexOf('time=') !== -1) {
        let time_matches = args.time_re.exec(data.toString());
        if (time_matches[1]) {
          _this.emit('conversion-progress', {
            current: ffmpegTimeToSec(time_matches[1]),
            total: total_duration_secs
          });
        } else {
          reject('no time_matches[1], could not extract current conversion time');
        }
      }
    });

    ffmpeg.on('error', function (err) {
      return reject(err);
    });

    ffmpeg.on('close', function (code) {
      if (code === 0) resolve(new_file_name);else reject('ffmpeg exited with code ' + code);
    });
  });
};
{'fraction_non_alphanumeric': 0.16277217206585237, 'fraction_numerical': 0.006903876792352629, 'mean_word_length': 2.8635897435897437, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5661230', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1204, 'n_words': 236}