Browse Source

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

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

29
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) {
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){ @@ -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(){ @@ -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