<commit_before>// Detects whether or not the user has just replaced the youtube URL.
// If they have, automatically download the video for them.
// We're also going to assume that they only want audio, because who actually
// uses my site for video downloads. >_>
function tryAutoDownload() {
  // If watch is not the path, we can be confident that the user does not want
  // this feature.
  if (window.location.pathname !== '/watch') {
    return;
  }

  // If the URL does not have a video specified as the query string, we can also
  // be confident that the user does not want this feature.
  // For some reason, window.location.search refers to the query string >_>
  if (window.location.search.indexOf("v=") < 0) {
    return;
  }

  // Form a "fake" youtube url that refers to the video.
  // This is just the youtube video site + the query string, because that's all
  // we need.
  var createdUrl = "www.youtube.com/watch" + window.location.search;
  document.getElementById("url-input").value = createdUrl;

  // We are going to rely on the default radio option being "audio".

  // Download!
  pressedSubmit();
}

// Try to automatically download once the page loads.
document.addEventListener('onload', function() {
  // We use a delay to ensure that the page is loaded properly.
  setTimeout(tryAutoDownload, 3000);
});

// Action to take when pressing the Submit button.
function pressedSubmit() {
  var button = document.getElementById( "submit-button" );
  button.innerHTML = "Processing...";
  button.disabled = true;
  document.getElementById( "download-link" ).style.display = "none";

  data = $("form[name='download-form']").serialize();
  getDownloadLink(data);
}

// Displays the download link to the user.
function displayLink(filename, title) {
  $( "#download-link" ).toggleClass( "error" , false );
  $( "#download-link" ).html("");
  $( "<a />", {
    href: '/api/file?filename=' + filename + '&name=' + title,
    target: "_blank"
  }).text(title).appendTo( "#download-link" );
}

// Displays an error message to the user.
function displayError(jqXHR, textStatus, errorThrown) {
  var downloadMessage = document.getElementById( "download-link" );
  if ( errorThrown == "BAD REQUEST" ) {
    var message = jQuery.parseJSON( jqXHR.responseText );
    downloadMessage.innerHTML = "<b>Oops, something went wrong with the download</b><br><br><span>" + message.message + "</span>";
  } else {
    downloadMessage.innerHTML = "<b>An internal error has occurred!</b>";
  }
  downloadMessage.classList.toggle( "error", true );
}

function queryDownload(formData) {
  $.ajax({
    url: "/api/download",
    type: "POST",
    data: formData,
    success: function(data) {
      if (data.status === 'FINISHED') {
        displayLink(data.filename, data.title);
      } else if (data.status === 'STARTING' || data.status === 'STARTED') {
        setTimeout(function() {
          queryDownload(formData);
        }, 5000);
      }
    },
    error: displayError,
    complete: function(result) {
      data = JSON.parse(result.responseText);
      if (data.status === 'FINISHED' || data.status === 'ERROR') {
        $('.modal').removeClass('loading');
        var downloadMessage = document.getElementById('download-link');
        downloadMessage.style.display = 'block';
        var button = document.getElementById('submit-button');
        button.innerHTML = 'Start';
        button.disabled = false;
      }
    }
  });
}

function getDownloadLink(formData) {
  $('.modal').addClass('loading');
  queryDownload(formData);
}
<commit_msg>Add // in front to auto generated url<commit_after>// Detects whether or not the user has just replaced the youtube URL.
// If they have, automatically download the video for them.
// We're also going to assume that they only want audio, because who actually
// uses my site for video downloads. >_>
function tryAutoDownload() {
  // If watch is not the path, we can be confident that the user does not want
  // this feature.
  if (window.location.pathname !== '/watch') {
    return;
  }

  // If the URL does not have a video specified as the query string, we can also
  // be confident that the user does not want this feature.
  // For some reason, window.location.search refers to the query string >_>
  if (window.location.search.indexOf("v=") < 0) {
    return;
  }

  // Form a "fake" youtube url that refers to the video.
  // This is just the youtube video site + the query string, because that's all
  // we need.
  // The // at the beginning is required to meet the standards of an URL.
  var createdUrl = "//www.youtube.com/watch" + window.location.search;
  document.getElementById("url-input").value = createdUrl;

  // We are going to rely on the default radio option being "audio".

  // Download!
  pressedSubmit();
}

// Try to automatically download once the page loads.
document.addEventListener('onload', function() {
  // We use a delay to ensure that the page is loaded properly.
  setTimeout(tryAutoDownload, 3000);
});

// Action to take when pressing the Submit button.
function pressedSubmit() {
  var button = document.getElementById( "submit-button" );
  button.innerHTML = "Processing...";
  button.disabled = true;
  document.getElementById( "download-link" ).style.display = "none";

  data = $("form[name='download-form']").serialize();
  getDownloadLink(data);
}

// Displays the download link to the user.
function displayLink(filename, title) {
  $( "#download-link" ).toggleClass( "error" , false );
  $( "#download-link" ).html("");
  $( "<a />", {
    href: '/api/file?filename=' + filename + '&name=' + title,
    target: "_blank"
  }).text(title).appendTo( "#download-link" );
}

// Displays an error message to the user.
function displayError(jqXHR, textStatus, errorThrown) {
  var downloadMessage = document.getElementById( "download-link" );
  if ( errorThrown == "BAD REQUEST" ) {
    var message = jQuery.parseJSON( jqXHR.responseText );
    downloadMessage.innerHTML = "<b>Oops, something went wrong with the download</b><br><br><span>" + message.message + "</span>";
  } else {
    downloadMessage.innerHTML = "<b>An internal error has occurred!</b>";
  }
  downloadMessage.classList.toggle( "error", true );
}

function queryDownload(formData) {
  $.ajax({
    url: "/api/download",
    type: "POST",
    data: formData,
    success: function(data) {
      if (data.status === 'FINISHED') {
        displayLink(data.filename, data.title);
      } else if (data.status === 'STARTING' || data.status === 'STARTED') {
        setTimeout(function() {
          queryDownload(formData);
        }, 5000);
      }
    },
    error: displayError,
    complete: function(result) {
      data = JSON.parse(result.responseText);
      if (data.status === 'FINISHED' || data.status === 'ERROR') {
        $('.modal').removeClass('loading');
        var downloadMessage = document.getElementById('download-link');
        downloadMessage.style.display = 'block';
        var button = document.getElementById('submit-button');
        button.innerHTML = 'Start';
        button.disabled = false;
      }
    }
  });
}

function getDownloadLink(formData) {
  $('.modal').addClass('loading');
  queryDownload(formData);
}

{'fraction_non_alphanumeric': 0.14200609587143254, 'fraction_numerical': 0.0024937655860349127, 'mean_word_length': 3.3383413461538463, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 54, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2085461', 'n_tokens_mistral': 2085, 'n_tokens_neox': 2032, 'n_words': 659}