1
0
Fork 0
Browse Source

fix to show the correct song title

master
IngridRegina 4 years ago
parent
commit
0f61ba7c08
  1. 27
      script.js

27
script.js

@ -6,11 +6,16 @@ function update(){
var json_obj = JSON.parse(json_text); var json_obj = JSON.parse(json_text);
var playing = ''; var playing = '';
var first = getFirstPlaying(json_obj); var first = getFirstPlaying(json_obj);
if (first == null) {}
else if (first.artist != undefined) { if (first == null) {
playing = 'Mitte munnigi ei mängi prg';
}
else if (first != null && first.artist != undefined) {
playing = first.artist + ' - '; playing = first.artist + ' - ';
playing += first.title;
} else {
playing += first.title;
} }
playing += first.title;
var nowPlaying = playing; var nowPlaying = playing;
update_field('on-air', playing); update_field('on-air', playing);
update_listeners(json_obj); update_listeners(json_obj);
@ -26,8 +31,11 @@ function update_field(field, data){
} }
function update_listeners(json_obj){ function update_listeners(json_obj){
var nowPlaying = getFirstPlaying(json_obj); var nowPlaying = getFirstPlaying(json_obj);
update_field('listeners1', nowPlaying.listeners);
if(nowPlaying != null) {
update_field('listeners1', nowPlaying.listeners);
}
} }
function autoupdate(){ function autoupdate(){
@ -45,11 +53,16 @@ function reset_bg(){
function getFirstPlaying(jsonObj){ function getFirstPlaying(jsonObj){
var sources = jsonObj.icestats.source; var sources = jsonObj.icestats.source;
var masterStreams = [
'/live',
]
for(o=0; o < sources.length; o++) { 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 sources[o];
} }
} }
return null; return null;
} }

Loading…
Cancel
Save