View previous topic :: View next topic |
Author |
Message |
hoolahoops
Joined: 24 May 2010 Posts: 14
|
Posted: Thu May 27, 2010 5:13 pm Post subject: PHP Icecast Status by Phil of Simplegaming.net |
|
|
Hi guys,
I managed to make a sworn after PHP script that will parse the status of your Icecast server.
This script extracts all the infomation (under the stream: (stream) part) and formats it into a neat PHP array for useage as you like.
Feel free to use as it says in the example.php file.
See the example.php file for how to use and configuration settings.
Download link: Click Here
Hope you like and feel free to contact me.
-Phil |
|
Back to top |
|
|
impactdj
Joined: 06 Apr 2010 Posts: 18
|
Posted: Thu May 27, 2010 9:36 pm Post subject: please please help **complete noob** |
|
|
Hi there,
I've been having a nightmare trying to embed my icecast stats on my website. I've looked all over the forums and tried a load of different methods but i'm having no luck. It doesn't help that i don't know any code What you've put together looks like exactly what i need Please Please Please could you help me?
my stream is at: http://undergroundsoundz.kicks-ass.net:7500
my website is at: http://www.undergroundsoundz.com
I realised after a while that i can't embed it as the site does not support php! so i've decided to create a blank php website with the stats and embed it on my actual website using an iframe.
the php site is at: http://undergroundsound.byethost10.com
Could you do me a massive favour and put the one or two files together (index.php etc.) that i can then just upload to the php site so that they show up in the iframe on my html website? |
|
Back to top |
|
|
hoolahoops
Joined: 24 May 2010 Posts: 14
|
Posted: Thu May 27, 2010 10:33 pm Post subject: |
|
|
you can download the index file i created here
it will be available for 1 week as of posting.
You will need to download the other file in my first post and edit the cast_info.php so the config matches your server url and port. |
|
Back to top |
|
|
impactdj
Joined: 06 Apr 2010 Posts: 18
|
Posted: Fri May 28, 2010 8:30 am Post subject: |
|
|
Many thanks for getting back to me
i've changed the cast_info.php as you said to the below:
$SERVER = 'http://undergroundsoundz.kicks-ass.net:7500'; //enter the URL to your Icecast server
$STATS_FILE = '/status.xsl'; //enter the path to your status.xsl file (leave blank unless u know its different)
The Server is definitely running but i am getting "unable to connect to icecast sever"
Any ideas? |
|
Back to top |
|
|
impactdj
Joined: 06 Apr 2010 Posts: 18
|
|
Back to top |
|
|
hoolahoops
Joined: 24 May 2010 Posts: 14
|
Posted: Fri May 28, 2010 7:24 pm Post subject: |
|
|
Seem's to work fine for me using your server address below is the code for the cast_info.php file i have used. Its exactly the same just with your address in:
Code: |
<?php
/*
* Script Configurations
*/
$SERVER = 'http://undergroundsoundz.kicks-ass.net:7500';
//$SERVER = 'http://sg.webhop.net:8000'; //enter the URL to your Icecast server
$STATS_FILE = '/status.xsl'; //enter the path to your status.xsl file (leave blank unless u know its different)
//////////////////////////////////// END OF CONFIGURATION ----- DO NOT EDIT BELOW THIS LINE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//get statistics file contents
$fp = fopen($SERVER.$STATS_FILE,'r');
if(!$fp) {
//error connecting to server!
die("Unable to connect to Icecast server.");
}
$stats_file_contents = '';
while(!feof($fp)) {
$stats_file_contents .= fread($fp,1024);
}
fclose($fp);
//create array to store results for later usage
$radio_info = array();
$radio_info['server'] = $SERVER;
$radio_info['title'] = '';
$radio_info['description'] = '';
$radio_info['content_type'] = '';
$radio_info['mount_start'] = '';
$radio_info['bit_rate'] = '';
$radio_info['listeners'] = '';
$radio_info['most_listeners'] = '';
$radio_info['genre'] = '';
$radio_info['url'] = '';
$radio_info['now_playing'] = array();
$radio_info['now_playing']['artist'] = '';
$radio_info['now_playing']['track'] = '';
$temp = array();
//format results into array
$search_for = "<td\s[^>]*class=\"streamdata\">(.*)<\/td>";
$search_td = array('<td class="streamdata">','</td>');
if(preg_match_all("/$search_for/siU",$stats_file_contents,$matches)) {
foreach($matches[0] as $match) {
$to_push = str_replace($search_td,'',$match);
$to_push = trim($to_push);
array_push($temp,$to_push);
}
}
//build final array from temp array
$radio_info['title'] = $temp[0];
$radio_info['description'] = $temp[1];
$radio_info['content_type'] = $temp[2];
$radio_info['mount_start'] = $temp[3];
$radio_info['bit_rate'] = $temp[4];
$radio_info['listeners'] = $temp[5];
$radio_info['most_listeners'] = $temp[6];
$radio_info['genre'] = $temp[7];
$radio_info['url'] = $temp[8];
//format now playing
$now_playing = explode(" - ",$temp[9]);
$radio_info['now_playing']['artist'] = $now_playing[0];
$radio_info['now_playing']['track'] = $now_playing[1];
?>
|
|
|
Back to top |
|
|
impactdj
Joined: 06 Apr 2010 Posts: 18
|
Posted: Sat May 29, 2010 3:48 pm Post subject: |
|
|
Still having problems i'm affraid. I have a free php site hosing account where i have uploaded both the index.php and the cast_info.php files to the public folder.
when you visit the site after uploading the files at: http://undergroundsoundz.hostzi.com/
It is showing the followin error message:
Warning: fopen(http://undergroundsoundz.kicks-ass.net:7500/status.xsl) [function.fopen]: failed to open stream: Connection timed out in /home/a1651256/public_html/cast_info.php on line 14
Unable to connect to Icecast server
I have just the code you provided as below in the files:
index.php
Code: |
<?php
require_once("cast_info.php");
?>
<table>
<tr>
<th colspan="2">Stats For Icecast Server: <?php echo $radio_info['title']; ?></th>
</tr>
<?php
foreach($radio_info as $title => $data) {
switch($title) {
case 'now_playing' :
?><tr>
<td><b><?php echo $title; ?></b></td>
<td><?php echo $data['artist']; ?><br />
<?php echo $data['track']; ?>
</td>
</tr><?php
break;
case 'title' :
//skip
break;
default :
?><tr>
<td><?php echo $title; ?></td>
<td><?php echo $data; ?></td>
</tr><?php
break;
}
}
?>
</table>
|
cast_info.php
Code: |
<?php
/*
* Script Configurations
*/
$SERVER = 'http://undergroundsoundz.kicks-ass.net:7500';
//$SERVER = 'http://sg.webhop.net:8000'; //enter the URL to your Icecast server
$STATS_FILE = '/status.xsl'; //enter the path to your status.xsl file (leave blank unless u know its different)
//////////////////////////////////// END OF CONFIGURATION ----- DO NOT EDIT BELOW THIS LINE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//get statistics file contents
$fp = fopen($SERVER.$STATS_FILE,'r');
if(!$fp) {
//error connecting to server!
die("Unable to connect to Icecast server.");
}
$stats_file_contents = '';
while(!feof($fp)) {
$stats_file_contents .= fread($fp,1024);
}
fclose($fp);
//create array to store results for later usage
$radio_info = array();
$radio_info['server'] = $SERVER;
$radio_info['title'] = '';
$radio_info['description'] = '';
$radio_info['content_type'] = '';
$radio_info['mount_start'] = '';
$radio_info['bit_rate'] = '';
$radio_info['listeners'] = '';
$radio_info['most_listeners'] = '';
$radio_info['genre'] = '';
$radio_info['url'] = '';
$radio_info['now_playing'] = array();
$radio_info['now_playing']['artist'] = '';
$radio_info['now_playing']['track'] = '';
$temp = array();
//format results into array
$search_for = "<td\s[^>]*class=\"streamdata\">(.*)<\/td>";
$search_td = array('<td class="streamdata">','</td>');
if(preg_match_all("/$search_for/siU",$stats_file_contents,$matches)) {
foreach($matches[0] as $match) {
$to_push = str_replace($search_td,'',$match);
$to_push = trim($to_push);
array_push($temp,$to_push);
}
}
//build final array from temp array
$radio_info['title'] = $temp[0];
$radio_info['description'] = $temp[1];
$radio_info['content_type'] = $temp[2];
$radio_info['mount_start'] = $temp[3];
$radio_info['bit_rate'] = $temp[4];
$radio_info['listeners'] = $temp[5];
$radio_info['most_listeners'] = $temp[6];
$radio_info['genre'] = $temp[7];
$radio_info['url'] = $temp[8];
//format now playing
$now_playing = explode(" - ",$temp[9]);
$radio_info['now_playing']['artist'] = $now_playing[0];
$radio_info['now_playing']['track'] = $now_playing[1];
?>
|
|
|
Back to top |
|
|
hoolahoops
Joined: 24 May 2010 Posts: 14
|
Posted: Sun May 30, 2010 9:32 am Post subject: |
|
|
Ahhhh ok i know the answer to this problem...
Some PHP hosts have the php.ini set so you can't call external files using fopen().
I'll rig up a version 1.1 of the script using a different function to get the stream infomation and that should solve your problem and anyone else who runs into this.
Be up in a day or 2 as i'm in my last few weeks of college and have allot of coursework to do. |
|
Back to top |
|
|
impactdj
Joined: 06 Apr 2010 Posts: 18
|
Posted: Sun May 30, 2010 11:22 am Post subject: |
|
|
cool, look forward to it |
|
Back to top |
|
|
hoolahoops
Joined: 24 May 2010 Posts: 14
|
Posted: Mon May 31, 2010 11:23 am Post subject: |
|
|
Version 1.1 is no ready for release.
Just copy and paste the code below into your cast_info.php file then upload it to your server.
CHANGE LOG:
Replaced the way the cast info is gained by making use of the php cURL extention instead of using file commands (fopen(), fread(), fclose() etc).
This method should work on all setups of PHP unless the cURL extention is not installed if it isn't just ask your host and they should be able to install it in seconds.
Enjoy!
CODE:
Code: |
<?php
/*
* SCRIPT CONFIGURATIONS
*/
$SERVER = 'http://myserver.com:8000'; //URL TO YOUR ICECAST SERVER
$STATS_FILE = '/status.xsl'; //PATH TO STATUS.XSL PAGE YOU CAN SEE IN YOUR BROWSER (LEAVE BLANK UNLESS DIFFERENT)
///////////////////// END OF CONFIGURATION --- DO NOT EDIT BELOW THIS LINE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//create a new curl resource
$ch = curl_init();
//set url
curl_setopt($ch,CURLOPT_URL,$SERVER.$STATS_FILE);
//return as a string
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
//$output = our stauts.xsl file
$output = curl_exec($ch);
//close curl resource to free up system resources
curl_close($ch);
//build array to store our radio stats for later use
$radio_info = array();
$radio_info['server'] = $SERVER;
$radio_info['title'] = '';
$radio_info['description'] = '';
$radio_info['content_type'] = '';
$radio_info['mount_start'] = '';
$radio_info['bit_rate'] = '';
$radio_info['listeners'] = '';
$radio_info['most_listeners'] = '';
$radio_info['genre'] = '';
$radio_info['url'] = '';
$radio_info['now_playing'] = array();
$radio_info['now_playing']['artist'] = '';
$radio_info['now_playing']['track'] = '';
//loop through $ouput and sort into our different arrays
$temp_array = array();
$search_for = "<td\s[^>]*class=\"streamdata\">(.*)<\/td>";
$search_td = array('<td class="streamdata">','</td>');
if(preg_match_all("/$search_for/siU",$output,$matches)) {
foreach($matches[0] as $match) {
$to_push = str_replace($search_td,'',$match);
$to_push = trim($to_push);
array_push($temp_array,$to_push);
}
}
//sort our temp array into our ral array
$radio_info['title'] = $temp_array[0];
$radio_info['description'] = $temp_array[1];
$radio_info['content_type'] = $temp_array[2];
$radio_info['mount_start'] = $temp_array[3];
$radio_info['bit_rate'] = $temp_array[4];
$radio_info['listeners'] = $temp_array[5];
$radio_info['most_listeners'] = $temp_array[6];
$radio_info['genre'] = $temp_array[7];
$radio_info['url'] = $temp_array[8];
$x = explode(" - ",$temp_array[9]);
$radio_info['now_playing']['artist'] = $x[0];
$radio_info['now_playing']['track'] = $x[1];
?>
|
|
|
Back to top |
|
|
Brutish
Joined: 18 Mar 2010 Posts: 62
|
Posted: Mon May 31, 2010 6:55 pm Post subject: |
|
|
This script is excellent! Can I post this on my site? _________________ www.Hobbycaster.com |
|
Back to top |
|
|
hoolahoops
Joined: 24 May 2010 Posts: 14
|
Posted: Tue Jun 01, 2010 12:49 pm Post subject: |
|
|
yea sure you can just please make sure to give credit to myself and a link back to my website, http://www.simplegaming.net so that I can get some work lol if you want anymore scripts give us a bell and we can sort something out
Made this only because I needed it for my college project cause i'm setting up a fake radio station and using icecast for it lol |
|
Back to top |
|
|
impactdj
Joined: 06 Apr 2010 Posts: 18
|
|
Back to top |
|
|
hoolahoops
Joined: 24 May 2010 Posts: 14
|
Posted: Thu Jun 03, 2010 4:21 pm Post subject: |
|
|
Yea it does this when the icecast server is running but there is no stream running to the icecast server.
Check the stats page its self in your browser to check it isn't empty. |
|
Back to top |
|
|
impactdj
Joined: 06 Apr 2010 Posts: 18
|
|
Back to top |
|
|
|