diff --git a/public/mediaDBControls.js b/public/mediaDBControls.js index 18579e0..884e27e 100644 --- a/public/mediaDBControls.js +++ b/public/mediaDBControls.js @@ -174,7 +174,6 @@ function showSearch() { searchBox.innerHTML = searchTerm + "_"; } - document.querySelector("#mediaDB").addEventListener("scroll", function() { localStorage.scrollPosition = this.scrollTop; }); @@ -185,12 +184,10 @@ function restoreScroll() { adjustMediaDBHeight(); restoreScroll(); - if (document.querySelector('#mediaDB').getAttribute("size") == 0) { var event = document.createEvent("HTMLEvents"); event.initEvent("click", true, true); document.querySelector('#updateDB').dispatchEvent(event); } -addPlayerFunctions(); - +addPlayerFunctions(); \ No newline at end of file diff --git a/public/player.js b/public/player.js index 404283d..60e2d56 100644 --- a/public/player.js +++ b/public/player.js @@ -7,7 +7,7 @@ function addPlayerFunctions() { document.querySelector('#mediaDB').addEventListener("change", function(event) { var album = event.target.value; if (album != "") { - var artist = event.target.options[event.target.selectedIndex].parentNode.label; + artist = event.target.options[event.target.selectedIndex].parentNode.label; var http = new XMLHttpRequest(); http.onreadystatechange = function() { diff --git a/server.rb b/server.rb index a559aaf..75b59e9 100644 --- a/server.rb +++ b/server.rb @@ -161,16 +161,29 @@ def emptyMediaDB? end get '/lyrics' do - apiSearch = XmlSimple.xml_in(HTTP.get("http://api.chartlyrics.com/apiv1.asmx/SearchLyric?artist=#{params[:artist]}%20jackson&song=#{params[:track]}").to_s) - lyricId = apiSearch["SearchLyricResult"][0]["LyricId"][0] - checksum = apiSearch["SearchLyricResult"][0]["LyricChecksum"][0] i=0 - sleep 5 # the the api enforces timeouts + begin + apiSearch = XmlSimple.xml_in(HTTP.get(URI.encode("http://api.chartlyrics.com/apiv1.asmx/SearchLyric?artist=#{params[:artist]}&song=#{params[:track]}")).to_s) + rescue IOError => ioe + sleep 10 # give the api more time + i++ + until i == 2 + retry + end + end + begin + lyricId = apiSearch["SearchLyricResult"][0]["LyricId"][0] + checksum = apiSearch["SearchLyricResult"][0]["LyricChecksum"][0] + rescue NoMethodError => nme + return "no lyrics found" + end + i=0 + sleep 5 # the api enforces timeouts begin lyrics = XmlSimple.xml_in(HTTP.get("http://api.chartlyrics.com/apiv1.asmx/GetLyric?lyricId=#{lyricId}&lyricCheckSum=#{checksum}").to_s) return lyrics["Lyric"][0] rescue IOError => ioe - sleep 15 # give the api more time + sleep 15 i++ until i == 3 retry