<commit_before>/*global Promise: false*/
(function () {
  'use strict';

  function transformUri(uri) {
    uri = uri.trim();
    var match = /^https?:\/\/(?:www\.)?youtu(?:\.be|be\.com)\/(?:\S+\/)?(?:[^\s\/]*(?:\?|&)vi?=)?([^#?&]+)/i.exec(uri);
    if (match) {
      return 'plugin://plugin.video.youtube/?path=/root&search&action=play_video&videoid=' + match[1];
    }
    return uri;
  }

  function parseResult(obj) {
    return new Promise(function (resolve, reject) {
      if (obj.error) {
        // console.warn('Error!');
        reject(obj.error);
      } else {
        // console.log('Success!');
        resolve(obj.result);
      }
    });
  }

  function callMethod(request) {
    // console.log('Calling ' + method);
    return window.fetch(window.kodi.url, {
      method: "POST",
      body: JSON.stringify({
        "id": 1,
        "jsonrpc": "2.0",
        "method": request.method,
        "params": request.params
      }),
      headers: {
        "Content-Type": "application/json"
      },
      credentials: "same-origin"
    }).then(function (response) {
      // console.log(response.statusText);
      return response.json();
    }).then(parseResult);
  }

  window.kodi = window.kodi || {};
  window.kodi.url = '/jsonrpc';
  if (window.location.protocol.indexOf('http') === -1) {
    window.kodi.url = 'http://192.168.237.9:8080' + window.kodi.url;
    window.console.warn('Using test server: ' + window.kodi.url);
  }
  window.kodi.call = callMethod;
  window.console.info('Kodi initialized');
}());<commit_msg>code refactoring.<commit_after>/*global Promise: false*/
(function () {
  'use strict';

  function transformUri(uri) {
    uri = uri.trim();
    var match = /^https?:\/\/(?:www\.)?youtu(?:\.be|be\.com)\/(?:\S+\/)?(?:[^\s\/]*(?:\?|&)vi?=)?([^#?&]+)/i.exec(uri);
    if (match) {
      return 'plugin://plugin.video.youtube/?path=/root&search&action=play_video&videoid=' + match[1];
    }
    return uri;
  }

  function callMethod(request) {

    function formatRequest(r) {
      return {
        method: "POST",
        body: JSON.stringify({
          id: r.id || 1,
          jsonrpc: r.jsonrpc || '2.0',
          method: r.method || 'JSONRPC.Ping',
          params: r.params || {}
        }),
        headers: {
          "Content-Type": "application/json"
        },
        credentials: "same-origin"
      };
    }

    function toJson(r) {
      return r.json();
    }

    function parseResult(obj) {
      if (!obj.error) {
        return Promise.resolve(obj.result);
      }
      return Promise.reject(obj.error);
    }

    return window.fetch(window.kodi.url, formatRequest(request))
      .then(toJson)
      .then(parseResult);
  }

  window.kodi = window.kodi || {};
  window.kodi.url = '/jsonrpc';
  if (window.location.protocol.indexOf('http') === -1) {
    window.kodi.url = 'http://192.168.237.9:8080' + window.kodi.url;
    window.console.warn('Using test server: ' + window.kodi.url);
  }
  window.kodi.call = callMethod;
  window.console.info('Kodi initialized');
}());
{'fraction_non_alphanumeric': 0.2071686945083854, 'fraction_numerical': 0.012495889510029596, 'mean_word_length': 2.4489795918367347, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, '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': '6734149', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1042, 'n_words': 162}