Skip to content

Commit

Permalink
Make lyric call more robust (ascii, artist)
Browse files Browse the repository at this point in the history
  • Loading branch information
onli committed Jan 20, 2015
1 parent 11f35e8 commit 627c17b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
5 changes: 1 addition & 4 deletions public/mediaDBControls.js
Expand Up @@ -174,7 +174,6 @@ function showSearch() {
searchBox.innerHTML = searchTerm + "_";
}


document.querySelector("#mediaDB").addEventListener("scroll", function() {
localStorage.scrollPosition = this.scrollTop;
});
Expand All @@ -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();
2 changes: 1 addition & 1 deletion public/player.js
Expand Up @@ -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() {
Expand Down
23 changes: 18 additions & 5 deletions server.rb
Expand Up @@ -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
Expand Down

0 comments on commit 627c17b

Please sign in to comment.