<commit_before>'use strict';

var request = require('request');
var cheerio = require('cheerio');
var Genius = require('node-genius');

var lyricist = function(key){

  var module = {};

  if(key){
    var genius = new Genius(key);
  }
  else{
    throw new Error('You need to provide an API key!');
  }

  /**
  * Look up song
  * @param  object|number  query     Search query (Genius ID or keywords).
  * @param  function       callback  The function to call when we have a result.
  */
  module.song = function(query, callback){
    // If query is an object with keywords like {search: 'keywords'}
    if(typeof query === 'object'){
      _search(query.search, callback);
    }
    // Or if query is an ID
    else if(typeof query === 'number'){
      _getSong(query, callback);
    }
  }; // End of module.song()

  /**
  * Look up album
  * @param  number    id        The album's Genius ID.
  * @param  object    options   Options e.g., fetch_lyrics (optional)
  * @param  function  callback  The function to call when we have a result.
  */
  module.album = function(id, options, callback){
    if(typeof options === 'function'){
      // If the options parameter receives a function then there will
      // be no options. use defaults:
      callback = options; // And get the callback from the options parameter.
    }
    genius.getAlbum(id, function(error, response){
      if(error){ return(callback(error)); }
      var album = JSON.parse(response).response.album;
      _scrapeTracklist(album.url, function(error, songs){
        album.songs = songs;
        callback(error, album);
      });
    });
  }; // End of module.album()

  /**
  * Look up artist
  * @param  number    id        The artist's Genius ID.
  * @param  object    options   Options e.g., page, per_page, get_songs (optional)
  * @param  function  callback  The function to call when we have a result.
  */
  module.artist = function(id, options, callback){
    if(typeof options === 'function'){
      // If the options parameter receives a function then there will
      // be no options. use defaults:
      options.get_songs = false;
      callback = options; // And get the callback from the options parameter.
    }
    genius.getArtist(id, function(error, response){
      if(error){ return(callback(error)); }
      var artist = JSON.parse(response).response.artist;
      if(options.get_songs){
        // Set defaults if empty:
        options.page = options.page || 1;
        options.per_page = options.per_page || 20;
        genius.getArtistSongs(artist.id, {per_page: options.per_page, pages: options.pages}, function(error, response){
          artist.songs = JSON.parse(response).response.songs;
          artist.next_page = JSON.parse(response).response.next_page;
          callback(error, artist);<commit_msg>resolved error which prevented pagination from happening<commit_after>'use strict';

var request = require('request');
var cheerio = require('cheerio');
var Genius = require('node-genius');

var lyricist = function(key){

  var module = {};

  if(key){
    var genius = new Genius(key);
  }
  else{
    throw new Error('You need to provide an API key!');
  }

  /**
  * Look up song
  * @param  object|number  query     Search query (Genius ID or keywords).
  * @param  function       callback  The function to call when we have a result.
  */
  module.song = function(query, callback){
    // If query is an object with keywords like {search: 'keywords'}
    if(typeof query === 'object'){
      _search(query.search, callback);
    }
    // Or if query is an ID
    else if(typeof query === 'number'){
      _getSong(query, callback);
    }
  }; // End of module.song()

  /**
  * Look up album
  * @param  number    id        The album's Genius ID.
  * @param  object    options   Options e.g., fetch_lyrics (optional)
  * @param  function  callback  The function to call when we have a result.
  */
  module.album = function(id, options, callback){
    if(typeof options === 'function'){
      // If the options parameter receives a function then there will
      // be no options. use defaults:
      callback = options; // And get the callback from the options parameter.
    }
    genius.getAlbum(id, function(error, response){
      if(error){ return(callback(error)); }
      var album = JSON.parse(response).response.album;
      _scrapeTracklist(album.url, function(error, songs){
        album.songs = songs;
        callback(error, album);
      });
    });
  }; // End of module.album()

  /**
  * Look up artist
  * @param  number    id        The artist's Genius ID.
  * @param  object    options   Options e.g., page, per_page, get_songs (optional)
  * @param  function  callback  The function to call when we have a result.
  */
  module.artist = function(id, options, callback){
    if(typeof options === 'function'){
      // If the options parameter receives a function then there will
      // be no options. use defaults:
      options.get_songs = false;
      callback = options; // And get the callback from the options parameter.
    }
    genius.getArtist(id, function(error, response){
      if(error){ return(callback(error)); }
      var artist = JSON.parse(response).response.artist;
      if(options.get_songs){
        // Set defaults if empty:
        options.page = options.page || 1;
        options.per_page = options.per_page || 20;
        genius.getArtistSongs(artist.id, {per_page: options.per_page, page: options.page}, function(error, response){
          artist.songs = JSON.parse(response).response.songs;
          artist.next_page = JSON.parse(response).response.next_page;
          callback(error, artist);
{'fraction_non_alphanumeric': 0.11995060857294056, 'fraction_numerical': 0.0010583877227024166, 'mean_word_length': 2.737640079103494, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1244002', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1649, 'n_words': 533}