Someone recently posted something related to stats on a web page. I
decided to write a script, since the existing scripts out there for
Icecast served single streams, and I'm running multiple streams. So
assuming your .liq fills in all the relevant data, like so:
#!/usr/local/bin/liquidsoap
set("log.file.path","/home/audiodef/liquidradio.log")
set("log.level",4)
output.icecast(%vorbis, host = "localhost", port = 8000,
password = "(password)", mount = "audiodef.ogg",
description="Synthetronica Radio: Audiodef", genre="Electronic",
url="http://audiodef:8000/audiodef.ogg", name="Audiodef",
mksafe(fallback([playlist(timeout=3600.,
conservative=true, length=400.,
"http://audiodef/playlists/audiodef.m3u"),
single("/var/www/audiodef/htdocs/audio/dc3.ogg")])))
output.icecast(%vorbis, host = "localhost", port = 8000,
password = "(password)", mount = "ambient.ogg",
description="Synthetronica Radio: Ambient", genre="Ambient",
url="http://audiodef:8000/ambient.ogg", name="Ambient",
mksafe(fallback([playlist(timeout=3600.,
conservative=true, length=400.,
"http://audiodef/playlists/ambient.m3u"),
single("/var/www/audiodef/htdocs/audio/dc3.ogg")])))
output.icecast(%vorbis, host = "localhost", port = 8000,
password = "(password)", mount = "techno.ogg",
description="Synthetronica Radio: Techno", genre="Techno",
url="http://audiodef:8000/techno.ogg", name="Techno",
mksafe(fallback([playlist(timeout=3600.,
conservative=true, length=400.,
"http://audiodef/playlists/techno.m3u"),
single("/var/www/audiodef/htdocs/audio/dc3.ogg")])))
your localhost:8000 Icecast server can be queried for data with this PHP
script:
<?php
//Open stats page and store in var:
$fp = fsockopen("localhost", 8000, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: localhost\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
$file="";
while (!feof($fp)) {
$file.=fgets($fp, 128);
}
fclose($fp);
}
//Split up into channels. 0 is page header, you can
disregard it:
$channels=explode("Mount Point", $file);
//Arrays of info for all channels:
for($i=1; $i<count($channels); $i++){
/* $stream_info appendix:
Stream title: 9
Stream description: 13
Content type: 17
Mount started: 21
Quality: 25
Current listeners: 29
Peak listeners: 33
Stream genre: 37
Stream URL: 41
Current song: 45
*/
$stream_info=explode("\n", $channels[$i]);
$stream_desc[$i]=strip_tags($stream_info[13]);
$stream_genre[$i]=strip_tags($stream_info[37]);
$stream_url[$i]=strip_tags($stream_info[41]);
$stream_current_song[$i]=strip_tags($stream_info[45]);
//Etc. Set arrays as needed using appendix above.
}
?>
You can then access the vars in your PHP pages as needed, like so:
<table width="100%">
<tr>
<td align="right"><strong><?php
print($stream_genre[1]);?></strong></td>
<td align="center"><?php print($stream_current_song[1]);?></td>
<td align="left"><a href="<?php print($stream_url[1]); ?>"
title="Tune in to <?php print($stream_desc[1]);?>">Tune in</a></td>
</tr>
<tr>
<td align="right"><strong><?php
print($stream_genre[2]);?></strong></td>
<td align="center"><?php print($stream_current_song[2]);?></td>
<td align="left"><a href="<?php print($stream_url[2]); ?>"
title="Tune in to <?php print($stream_desc[2]);?>">Tune in</a></td>
</tr>
<tr>
<td align="right"><strong><?php
print($stream_genre[3]);?></strong></td>
<td align="center"><?php print($stream_current_song[3]);?></td>
<td align="left"><a href="<?php print($stream_url[3]); ?>"
title="Tune in to <?php print($stream_desc[3]);?>">Tune in</a></td>
</tr>
</table>
I hope this is useful for other people. :-)
Damien
------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
_______________________________________________
Savonet-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/savonet-users