<commit_before>/**
 * Module dependencies.
 */

var toMS = require('./toMS')

/**
 * Parse SRT string.
 * @param {String} srt
 * @return {Array} subtitles
 */

module.exports = function parse (srt) {
  var subs = []
  var index
  var time
  var text
  var start
  var end

  if (!srt) {
    throw new Error('No SRT to parse')
  }

  srt = srt.trim()
  srt += '\n'
  srt = srt.replace(/\r\n/g, '\n').split('\n')

  srt.forEach(function (line) {
    line = line.toString()

    // if we don't have an index, so we should expect an index
    if (!index) {
      if (/^\d+$/.test(line)) {
        index = parseInt(line)
        return
      }
    }

    // now we have to check for the time
    if (!time) {
      var match = line.match(/^(\d{2}:\d{2}:\d{2},\d{3}) --> (\d{2}:\d{2}:\d{2},\d{3})$/)
      if (match) {
        start = match[1]
        end = match[2]
        time = true
        return
      }
    }

    // now we get all the strings until we get an empty line
    if (line.trim() === '') {
      subs.push({
        index: index,
        start: start,
        end: end,
        duration: toMS(end) - toMS(start),
        text: text
      })
      index = time = start = end = text = null
    } else {
      if (!text) {
        text = line
      } else {
        text += '\n' + line
      }
    }
  })

  return subs
}
<commit_msg>Normalize extra newlines.<commit_after>/**
 * Module dependencies.
 */

var toMS = require('./toMS')

/**
 * Parse SRT string.
 * @param {String} srt
 * @return {Array} subtitles
 */

module.exports = function parse (srt) {
  var subs = []
  var index
  var time
  var text
  var start
  var end

  if (!srt) {
    throw new Error('No SRT to parse')
  }

  srt = srt.trim()
  srt += '\n'
  srt = srt
    .replace(/\r\n/g, '\n')
    .replace(/\n{3,}/g, '\n\n')
    .split('\n')

  srt.forEach(function (line) {
    line = line.toString()

    // if we don't have an index, so we should expect an index
    if (!index) {
      if (/^\d+$/.test(line)) {
        index = parseInt(line)
        return
      }
    }

    // now we have to check for the time
    if (!time) {
      var match = line.match(/^(\d{2}:\d{2}:\d{2},\d{3}) --> (\d{2}:\d{2}:\d{2},\d{3})$/)
      if (match) {
        start = match[1]
        end = match[2]
        time = true
        return
      }
    }

    // now we get all the strings until we get an empty line
    if (line.trim() === '') {
      subs.push({
        index: index,
        start: start,
        end: end,
        duration: toMS(end) - toMS(start),
        text: text
      })
      index = time = start = end = text = null
    } else {
      if (!text) {
        text = line
      } else {
        text += '\n' + line
      }
    }
  })

  return subs
}

{'fraction_non_alphanumeric': 0.17335766423357665, 'fraction_numerical': 0.007664233576642336, 'mean_word_length': 1.6560077519379846, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '706032', 'n_tokens_mistral': 996, 'n_tokens_neox': 981, 'n_words': 276}