diff --git a/script.js b/script.js index 4606a97..3acc9cb 100644 --- a/script.js +++ b/script.js @@ -6,11 +6,15 @@ function update(){ var json_obj = JSON.parse(json_text); var playing = ''; var first = getFirstPlaying(json_obj); - if (first == null) {} - else if (first.artist != undefined) { - playing = first.artist + ' - '; + + if (first == null) { + playing = 'Mitte munnigi ei mängi prg'; + } else if (first.artist != undefined) { + playing = first.artist + ' - '; + playing += first.title; + } else { + playing += first.title; } - playing += first.title; var nowPlaying = playing; update_field('on-air', playing); update_listeners(json_obj); @@ -27,12 +31,15 @@ function update_field(field, data){ function update_listeners(json_obj){ var nowPlaying = getFirstPlaying(json_obj); - update_field('listeners1', nowPlaying.listeners); + + if (nowPlaying != null) { + update_field('listeners1', nowPlaying.listeners); + } } function autoupdate(){ update(); - setInterval(function(){ update(); }, 30000); + setInterval(function(){ update(); }, 30000); } function change_bg(id){ @@ -45,11 +52,19 @@ function reset_bg(){ function getFirstPlaying(jsonObj){ var sources = jsonObj.icestats.source; + var masterStreams = [ + '/live', + '/sai', + '/siinus', + '/viido', + ] + for(o=0; o < sources.length; o++) { - if (sources[o].title != undefined) { + if (sources[o].title != undefined && masterStreams.some(stream=>sources[o].listenurl.endsWith(stream))) { //check if source has a title key AND belongs to masterStreams return sources[o]; } } + return null; }