Browse Source

Merge branch 'master' of varbavahearst/kahtlane-fm into master

master
siinus 5 years ago committed by Gogs
parent
commit
4dc36a3e53
  1. 25
      script.js

25
script.js

@ -6,11 +6,15 @@ function update(){ @@ -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) {
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,7 +31,10 @@ function update_field(field, data){ @@ -27,7 +31,10 @@ 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(){
@ -45,11 +52,19 @@ function reset_bg(){ @@ -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;
}

Loading…
Cancel
Save