PDA

View Full Version : Hide stats when offline


geekpower
24th October 2006, 20:04
Hi,
how can i hide the stats with currently playing song from my site, when the radio is down(no dj's connected) .?

geekpower
24th October 2006, 21:19
if (substr_count ($value, "[/SERVERTITLE]")) {
$value = str_replace("[/SERVERTITLE]","", $value);
$servertitle=$value;
if (substr_count ($servertitle, "N/A")) {}
}

if (substr_count ($value, "[/SERVERTITLE]")) {
$value = str_replace("[/SERVERTITLE]","", $value);
$servertitle=$value;
if (substr_count ($servertitle, "N/A")) {print("<p><table border=0 cellspacing=0 cellpadding=10 bgcolor=red><tr><td style='padding: 1px; background: #FF9900'>\n");
print("<b><i>MWB-Radio <font color=green>OnLine</font></i> <font color=white>Trackinfo:</font><font color=black> Nu spilles: $titles[0]</font><font color=white> Listeners:</font> <font color=black>$currentlisteners/$maxlisteners </font><font color=white>Genre:</font> <font color=black>$servergenre</font></b> <b><i><a href=\"http://radio.mostwantedbits.org\">Lyt med!</a></i></b>");
print("</td></tr></table>\n");}
}

this was surely not the way to do it.. but can someone please help :) ?

djSpinnerCee
24th October 2006, 21:50
If you're talking about hiding the last-N, stream title, current track, etc... from your stats app, when no source is connected, a better way is to get the "status" line from /index.html (Server is [down|up with...]) and from there have the script either get and display or not get and display the specific info based on the text.

The server is "up" [DNAS is running] but the stream "down" [off-air] when there is no source connected.

* If anyone's interested, I'll post some PHP to handle that.

[massEdit:I totally misunderstood the OP on the first read]

geekpower
24th October 2006, 22:17
This works.. But an odd bug.. Sometimes it shows the last song played, thought no-one is playing anymore.. refresh and its gone, and refresh again and it shows it.. how come ?

if($titles[0] == "")
{
print("");
}
else{
print("<p><table border=0 cellspacing=0 cellpadding=10 bgcolor=red><tr><td style='padding: 1px; background: #FF9900'>\n");
print("<b><i>MWB-Radio <font color=green>OnLine</font></i> <font color=white>Trackinfo:</font><font color=black> Nu spilles: $titles[0]</font><font color=white> Listeners:</font> <font color=black>$currentlisteners/$maxlisteners </font><font color=white>Genre:</font> <font color=black>$servergenre</font></b> <b><i><a href=\"http://radio.mostwantedbits.org\">Lyt med!</a></i></b>");
print("</td></tr></table>\n");
}

djSpinnerCee
24th October 2006, 22:36
$titles[0] -- Where does this come from?

The DNAS track history remains until the server is shutdown (unloaded) even when there is no source, so be careful using that to imply a [dis]connected source -- it is likely to always return the last tracks played regardless of the DNAS status.

It's better to use a condition to set a logical [true|false] flag that will switch the output:

// set the condition first....

$DNASdown=FALSE;
if($titles[0] == "")
$DNASdown=TRUE;

if($DNASdown) {
// do nothing or say something useful here...
print("[Off-Air]");
}

else {
// Print output containing values when a source is connected...
print("[On-Air], etc...");
}


* After some checking, it seems that the XML stats in /admin.cgi just stop dead when the source diosconnects, that means that <songtitle>...</songtitle> will remain at it's last value, as will just about every other dynamic stream specific value.

I would get the /index.html and parse the Server Status line:

// assuming you have retrieved /index.html and it is now in $page...

$serverstatusMSG = ereg_replace('</b>.*', '',
ereg_replace('.*Server Status: </font></td><td><font class=default><b>',
'', $page));

// This will return "Server is currently up.... with a source connected
// and "Server is down" when no source is present.

// Set the status flag:
if (ereg_replace(' up ', '',$serverstatusMSG)==$serverstatusMSG) {
$DNASdown=TRUE;
}
else {
$DNASdown=FALSE;
}
// then continue....



* You would also want to return the $DNASdown=TRUE; output when the PHP script cannot connect to the server at all.

geekpower
25th October 2006, 06:29
$titles[0] ... you used it yourself in the code you pasted.. ?
And as fare as I can see your code does the same as mine .. ? Whats the difference..

djSpinnerCee
25th October 2006, 12:32
If $titles[0] was extracted from the /admin.cgi XML page or /played.html, it will NOT help you determine if there is a source connected.

All you posted was a code fragment. I only used it to illustrate a better way to switch the output.

Do you know what your code does exactly? It's difficult to make changes if you just downloaded it from somewhere and don't understand what it's doing in the first place.