<commit_before>// Copyright (c) 2012 The WebM project authors. All Rights Reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS.  All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.

'use strict';

/**
 * Download and parse Dash manifest file.
 * @param {string} url The url for the manifest file.
 * @constructor
 */
function DashParser(url) {
  this.url_ = url;
}

/**
 * Local file request has succeeded status code.
 * @const
 * @type {number}
 */
DashParser.FILE_OK_STATUS_CODE = 0;

/**
 * HTTP request has succeeded status code.
 * @const
 * @type {number}
 */
DashParser.HTTP_OK_STATUS_CODE = 200;

/**
 * Static function to return version string.
 * @return {string} version.
 */
DashParser.version = function() {
  return '0.1.0.1';
};

/**
 * Static function to parse XML duration.
 * @param {string} xsDuration XML duration.
 * @return {Object} The status object. {Object}.value returns the duration in
 *     seconds.
 */
DashParser.parseXsDuration = function(xsDuration) {
  // TODO(fgalligan): Handle years, months, and days.
  if (xsDuration.substr(0, 2).toUpperCase() != 'PT')
    return new ErrorStatus('PT not in xsDuration:' + xsDuration);

  var hours = xsDuration.match(/\d+(?=H)/i);
  var minutes = xsDuration.match(/\d+(?=M)/i);
  var seconds = xsDuration.match(/\d+\.?\d*(?=S)/i);

  var duration = 0;
  if (hours)
    duration += parseFloat(hours[0]) * 3600;
  if (minutes)
    duration += parseFloat(minutes[0]) * 60;
  if (seconds)
    duration += parseFloat(seconds[0]);

  return {status: ErrorStatus.STATUS_OK, value: duration};
};

/**
 * Url pointing to the manifest file.
 * @private
 * @type {string}
 */
DashParser.prototype.url_ = null;

/**
 * XML document representation of the manifest.
 * @private
 * @type {string}
 */
DashParser.prototype.xmlDoc_ = null;

/**
 * Logging function to be set by the application.
 * @param {string} str The input string to be logged.
 */
DashParser.prototype.log = function(str) {};

/**
 * Loads the manifest file and initializes the MPD class. The format for
 * callback(object) is obj.status {number} The returned status and
 * [obj.reason] {string} Extra information on the status.
 * @param {function} callback Callback function.
 */
DashParser.prototype.load = function(callback) {
  var xhReq = null;
  var t = this;
  this.callback = callback;

  if (this.url_ == null) {
    callback(new ErrorStatus('DashParser url is null.'));
    return;
  }

  if (window.XMLHttpRequest) {
    xhReq = new XMLHttpRequest();
  } else {
    xhReq = new ActiveXObject('Microsoft.XMLHTTP');
  }

  xhReq.onreadystatechange = function() {
    if (xhReq.readyState != 4) {
      return;
    }

    if (xhReq.status != DashParser.HTTP_OK_STATUS_CODE &&
        xhReq.status != DashParser.FILE_OK_STATUS_CODE) {
      t.callback(new ErrorStatus('Bad xhReq.status:' + xhReq.status));
    } else {
      t.xmlDoc_ = xhReq.responseXML;
      t.mpd = new MPD();
      var res = t.mpd.parseXmlDoc(t.xmlDoc_);
      if (res.status != ErrorStatus.STATUS_OK) {
        var errorStr = 'DashParser Parsing XML document failed. :' + res.reason;
        this.log(errorStr);
        t.callback(new ErrorStatus(errorStr));
      }
<commit_msg>Set XHR response MimeType to 'text/xml'.<commit_after>// Copyright (c) 2012 The WebM project authors. All Rights Reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS.  All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.

'use strict';

/**
 * Download and parse Dash manifest file.
 * @param {string} url The url for the manifest file.
 * @constructor
 */
function DashParser(url) {
  this.url_ = url;
}

/**
 * Local file request has succeeded status code.
 * @const
 * @type {number}
 */
DashParser.FILE_OK_STATUS_CODE = 0;

/**
 * HTTP request has succeeded status code.
 * @const
 * @type {number}
 */
DashParser.HTTP_OK_STATUS_CODE = 200;

/**
 * Static function to return version string.
 * @return {string} version.
 */
DashParser.version = function() {
  return '0.1.0.2';
};

/**
 * Static function to parse XML duration.
 * @param {string} xsDuration XML duration.
 * @return {Object} The status object. {Object}.value returns the duration in
 *     seconds.
 */
DashParser.parseXsDuration = function(xsDuration) {
  // TODO(fgalligan): Handle years, months, and days.
  if (xsDuration.substr(0, 2).toUpperCase() != 'PT')
    return new ErrorStatus('PT not in xsDuration:' + xsDuration);

  var hours = xsDuration.match(/\d+(?=H)/i);
  var minutes = xsDuration.match(/\d+(?=M)/i);
  var seconds = xsDuration.match(/\d+\.?\d*(?=S)/i);

  var duration = 0;
  if (hours)
    duration += parseFloat(hours[0]) * 3600;
  if (minutes)
    duration += parseFloat(minutes[0]) * 60;
  if (seconds)
    duration += parseFloat(seconds[0]);

  return {status: ErrorStatus.STATUS_OK, value: duration};
};

/**
 * Url pointing to the manifest file.
 * @private
 * @type {string}
 */
DashParser.prototype.url_ = null;

/**
 * XML document representation of the manifest.
 * @private
 * @type {string}
 */
DashParser.prototype.xmlDoc_ = null;

/**
 * Logging function to be set by the application.
 * @param {string} str The input string to be logged.
 */
DashParser.prototype.log = function(str) {};

/**
 * Loads the manifest file and initializes the MPD class. The format for
 * callback(object) is obj.status {number} The returned status and
 * [obj.reason] {string} Extra information on the status.
 * @param {function} callback Callback function.
 */
DashParser.prototype.load = function(callback) {
  var xhReq = null;
  var t = this;
  this.callback = callback;

  if (this.url_ == null) {
    callback(new ErrorStatus('DashParser url is null.'));
    return;
  }

  if (window.XMLHttpRequest) {
    xhReq = new XMLHttpRequest();
  } else {
    xhReq = new ActiveXObject('Microsoft.XMLHTTP');
  }
  xhReq.overrideMimeType('text/xml');

  xhReq.onreadystatechange = function() {
    if (xhReq.readyState != 4) {
      return;
    }

    if (xhReq.status != DashParser.HTTP_OK_STATUS_CODE &&
        xhReq.status != DashParser.FILE_OK_STATUS_CODE) {
      t.callback(new ErrorStatus('Bad xhReq.status:' + xhReq.status));
    } else {
      t.xmlDoc_ = xhReq.responseXML;
      t.mpd = new MPD();
      var res = t.mpd.parseXmlDoc(t.xmlDoc_);
      if (res.status != ErrorStatus.STATUS_OK) {
        var errorStr = 'DashParser Parsing XML document failed. :' + res.reason;
        this.log(errorStr);
        t.callback(new ErrorStatus(errorStr));
      }

{'fraction_non_alphanumeric': 0.13229966671496884, 'fraction_numerical': 0.007245326764237067, 'mean_word_length': 3.332705586942875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3589375', 'n_tokens_mistral': 2264, 'n_tokens_neox': 2177, 'n_words': 680}