inoicouldalwaysturn2u
9/3/2017 - 10:29 PM

Shazam Crawler and Youtube Searcher in the console

Shazam Crawler and Youtube Searcher in the console

// change this variable to change timeout for async scroll load
var TIMEOUT_IN_MS = 1000

// script from https://gist.github.com/xavhan/87717da0217b9b8299df
// start from www.shazam.com/myshazam
// print all shazam songs loaded on the page
// TODO: Change format to JSON
function printShazamSongs(){
  $(".details").each(function(i){
    var artist = $(this).find(".artist meta").attr("content");
    var title =  $(this).find(".title").attr("content");
    
    var format = artist + " - " + title;
    var yt = 'http://www.youtube.com/results?search_type=&search_query=' + encodeURI(artist + " " + title) + '&aq=f&oq=';
    var spoti = 'https://play.spotify.com/search/'+ encodeURI(artist + " " + title);
    
    var item = new Object;
    console.groupCollapsed(format);
    console.log(yt);
    console.log(spoti);
    console.groupEnd();
  });
}

// modified script from http://www.alecjacobson.com/weblog/?p=758
// simulate infinite scroll to the bottom to display all songs
function scrollToBottom(){
  bottom = document.body.scrollHeight;
  current = window.innerHeight + document.body.scrollTop;
  if((bottom-current) >0){
    window.scrollTo(0, bottom);
    setTimeout ( 'scrollToBottom()', TIMEOUT_IN_MS );
  }
  else{
    alert("Done scrolling")
    printShazamSongs()
  }
}

scrollToBottom();