<commit_before>
/*
 * Chrome-Last.fm-Scrobbler amazon.com "new interface" Connector
 *
 * <NAME> --- http://sheckel.net --- jacob[at]sheckel[dot]net
 *
 * Derived from Pandora module by <NAME>
 */

/********* Configuration: ***********/

// changes to the DOM in this container will trigger an update.
watchedContainer = "div.nowPlayingDetail";

// changes to the DOM in this container are due to play/pause/forward/back
playerMasterControl = "div.mp3Player-MasterControl";

/**
 * Function that returns title and artist of current song.
 * Make best effort to get the full, untruncated values from the
 * main cloud player pane. But, the user may have navigated away
 * from that - if so, fall back to the (possibly truncated) values
 * in the bottom now playing pane.
 */
function titleAndArtist() {
  var mainContentTableRow = $("tr.selectable").has("a.nowPlaying");
  if (mainContentTableRow.size () > 0) {
    return {
      title: mainContentTableRow.children("td.titleCell").attr("title"),
      artist: mainContentTableRow.children("td.artistCell").attr("title")
    }
  } else {
    var currentSongDetails = $(".currentSongDetails .title");
    return {
      title: currentSongDetails.text(),
      // substring(3) because format is: 'by Artist'
      artist: currentSongDetails.next().text().substring(3)
    }
  }
}

/**
 * Takes raw string, checks that it is in the form "xx:xx", and
 * calculates and returns the number of seconds, otherwise returns
 * -1 indicating failure to parse.
 */
function parseTime (maybeTime) {
  if (typeof(maybeTime) == "string" && maybeTime.indexOf (":") > 0) {
    var timeArr = maybeTime.split(":");
    return parseInt(timeArr[0])*60 + parseInt(timeArr[1]);
  } else {
    return -1;
  }
}

function currentTimeAndTrackDuration () {
  var songStatusTimer = $(".currentSongStatus .timer");
  return {
    currentTime: parseTime(songStatusTimer.find("#currentTime").html()),
    trackDuration: parseTime(songStatusTimer.children().filter(":last").html())
  }
}

function isPaused() {
  return $("div.mp3MasterPlayGroup").hasClass("paused");
}

function isPlaying() {
  return $("div.mp3MasterPlayGroup").hasClass("playing");
}


/********* Connector: ***********/

var track = function(title, artist) {
  return title + " " + artist;
}

var songTrack = function (song) {
  return track (song.title, song.artist);
}

/**
 * Encapsulate some "private" state and functions,
 * present a "public" API.
 */
var module = function() {

  var resetState = function (track) {
    return {
      lastTrack : track,
      lock : false,
      scrobbled : false
    }
  }

  var initState = function() {
    return resetState ("");
  }

  var state = initState();

  var parseNewState = function() {
    var tAndA = titleAndArtist ();
    var timeAndDuration = currentTimeAndTrackDuration ();
    return {
      title : tAndA.title,
      artist : tAndA.artist,
      currentTime : timeAndDuration.currentTime,
      duration : timeAndDuration.trackDuration,
      track : track (tAndA.title, tAndA.artist)
    }
  }

  var maybeScrobbled = function (scrobbledSong) {
    if (state.lastTrack == songTrack (scrobbledSong)) {
      state.scrobbled = true;
    } 
  }

  var update = function(newState) {
    console.log("submitting a now playing request. artist: "+newState.artist+", title: "+newState.title+", current time: "+newState.currentTime+", duration: "+newState.duration);
    chrome.extension.sendRequest({type: 'validate', artist: newState.artist, track: newState.title}, function(response) {
      if (response != false) {
	chrome.extension.sendRequest({type: 'nowPlaying', artist: newState.artist, track: newState.title, currentTime:newState.currentTime, duration: newState.duration});
      } else { // on failure send nowPlaying 'unknown song'
	chrome.extension.sendRequest({type: 'nowPlaying', duration: newState.duration});
      }
    });
    state = resetState (newState.track);
  }

  var isReadyToUpdate = function(newState) {
    return (isPlaying() && 
            newState.currentTime >= 0 && 
            newState.duration > 0 && 
            newState.track != "" && 
            newState.track != state.lastTrack);
  }

  var maybeUpdate = function() {
    var newState = parseNewState();
    if (isReadyToUpdate(newState)) {
      update(newState);
    } else {
      setTimeout(maybeUpdate, 1000);
    }
  }

  /**
   * Pause requests are ignored for a track that has already been
   * scrobbled. But a "reset" request forces a reset.
   */
  var cancelAndReset = function(force) {<commit_msg>Parsing Amazon Cloudplayer album information.<commit_after>
/*
 * Chrome-Last.fm-Scrobbler amazon.com "new interface" Connector
 *
 * <NAME> --- http://sheckel.net --- jacob[at]sheckel[dot]net
 *
 * Derived from Pandora module by <NAME>
 */

/********* Configuration: ***********/

// changes to the DOM in this container will trigger an update.
watchedContainer = "div.nowPlayingDetail";

// changes to the DOM in this container are due to play/pause/forward/back
playerMasterControl = "div.mp3Player-MasterControl";

/**
 * Function that returns title and artist of current song.
 * Make best effort to get the full, untruncated values from the
 * main cloud player pane. But, the user may have navigated away
 * from that - if so, fall back to the (possibly truncated) values
 * in the bottom now playing pane.
 */
function titleAndArtist() {
  var mainContentTableRow = $("tr.selectable").has("a.nowPlaying");
  if (mainContentTableRow.size () > 0) {
    return {
      title: mainContentTableRow.children("td.titleCell").attr("title"),
      artist: mainContentTableRow.children("td.artistCell").attr("title"),
      album: mainContentTableRow.children("td.albumCell").attr("title")
    }
  } else {
    var currentSongDetails = $(".currentSongDetails .title");
	var currentSongStatus = $(".currentSongStatus a");
    return {
      title: currentSongDetails.text(),
      // substring(3) because format is: 'by Artist'
      artist: currentSongDetails.next().text().substring(3),
      album: currentSongStatus.text()
    }
  }
}

/**
 * Takes raw string, checks that it is in the form "xx:xx", and
 * calculates and returns the number of seconds, otherwise returns
 * -1 indicating failure to parse.
 */
function parseTime (maybeTime) {
  if (typeof(maybeTime) == "string" && maybeTime.indexOf (":") > 0) {
    var timeArr = maybeTime.split(":");
    return parseInt(timeArr[0])*60 + parseInt(timeArr[1]);
  } else {
    return -1;
  }
}

function currentTimeAndTrackDuration () {
  var songStatusTimer = $(".currentSongStatus .timer");
  return {
    currentTime: parseTime(songStatusTimer.find("#currentTime").html()),
    trackDuration: parseTime(songStatusTimer.children().filter(":last").html())
  }
}

function isPaused() {
  return $("div.mp3MasterPlayGroup").hasClass("paused");
}

function isPlaying() {
  return $("div.mp3MasterPlayGroup").hasClass("playing");
}


/********* Connector: ***********/

var track = function(title, artist) {
  return title + " " + artist;
}

var songTrack = function (song) {
  return track (song.title, song.artist);
}

/**
 * Encapsulate some "private" state and functions,
 * present a "public" API.
 */
var module = function() {

  var resetState = function (track) {
    return {
      lastTrack : track,
      lock : false,
      scrobbled : false
    }
  }

  var initState = function() {
    return resetState ("");
  }

  var state = initState();

  var parseNewState = function() {
    var tAndA = titleAndArtist();
    var timeAndDuration = currentTimeAndTrackDuration();
    return {
      title: tAndA.title,
      artist: tAndA.artist,
      album: tAndA.album,
      currentTime: timeAndDuration.currentTime,
      duration: timeAndDuration.trackDuration,
      track: track(tAndA.title, tAndA.artist)
    }
  }

  var maybeScrobbled = function (scrobbledSong) {
    if (state.lastTrack == songTrack (scrobbledSong)) {
      state.scrobbled = true;
    } 
  }

  var update = function(newState) {
    console.log("submitting a now playing request. artist: "+newState.artist+", title: "+newState.title+", album: "+newState.album+", current time: "+newState.currentTime+", duration: "+newState.duration);
    chrome.extension.sendRequest({type: 'validate', artist: newState.artist, track: newState.title}, function(response) {
      if (response != false) {
	chrome.extension.sendRequest({type: 'nowPlaying', artist: newState.artist, track: newState.title, currentTime:newState.currentTime, duration: newState.duration, album: newState.album});
      } else { // on failure send nowPlaying 'unknown song'
	chrome.extension.sendRequest({type: 'nowPlaying', duration: newState.duration});
      }
    });
    state = resetState (newState.track);
  }

  var isReadyToUpdate = function(newState) {
    return (isPlaying() && 
            newState.currentTime >= 0 && 
            newState.duration > 0 && 
            newState.track != "" && 
            newState.track != state.lastTrack);
  }

  var maybeUpdate = function() {
    var newState = parseNewState();
    if (isReadyToUpdate(newState)) {
      update(newState);
    } else {
      setTimeout(maybeUpdate, 1000);
    }
  }

  /**
   * Pause requests are ignored for a track that has already been
   * scrobbled. But a "reset" request forces a reset.
   */
  var cancelAndReset = function(force) {
{'fraction_non_alphanumeric': 0.14090520922288644, 'fraction_numerical': 0.0040563620836891546, 'mean_word_length': 3.504326923076923, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2385637', 'n_tokens_mistral': 2910, 'n_tokens_neox': 2812, 'n_words': 731}