1
0
Fork 0
Browse Source

fix to show the correct song title

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

21
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 = first.artist + ' - '; playing = 'Mitte munnigi ei mängi prg';
} }
else if (first != null && first.artist != undefined) {
playing = first.artist + ' - ';
playing += first.title; playing += first.title;
} else {
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);
@ -27,7 +32,10 @@ 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);
if(nowPlaying != null) {
update_field('listeners1', nowPlaying.listeners); 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