info about link
: Javascript : PHP Index : MySQL :
shoutcast class
: Source : : Explanation : : Example : : Todo : : Feedback :
There is a new version of this script!
Please do not use / download this script unless your webserver only supports PHP4 (and not PHP5)
The new version can be found here

Why this script

For a personal project, i needed to be able to display information about the streams of shoutcast radio stations. So i decided to write a class that would make this a bit easier for me.
This is the result :-)
Btw, if you have no idea what i'm talking about, check out www.shoutcast.com. Using, for example, winamp, you can connect to these radiostations.

Usage

This class can be used for two purposes:
  1. To display information about a server/radiostation
  2. To display the recently played songs
To create an object, you'll have to know the ip and the port of this server. Then do the following:
$radio = new Radio("http://81.18.170.44:80");
To display server information
Define an array with the information you want to display:
$display_array = array(
	"Stream Title",
	"Stream Genre",
	"Stream URL",
	"Current Song"
	);
Possible options are:
  • Server Status
  • Stream Status
  • Listener Peak
  • Average Listen Time
  • Stream Title
  • Content Type
  • Stream Genre
  • Stream URL
  • Stream AIM
  • Stream IRC
  • Current Song

We already have the object (see above), now do the following to get the data:
$data_array = $radio->getServerInfo($display_array);
$display_array is the array that defines what information is usefull for you
A simple print_r($data_array) would reveal the outcome.


To display the song-history
We can use the same object for this and there's two methods that can help us out:
  1. getHistoryArray()
  2. getHistoryTable()
The first will return an array of all the songs with their timestamp, the second will output an html table.
Let's look at the syntax of the array-function first
$radio->getHistoryArray("/played.html");
It only has one argument, which indicates where the server-generated list can be found. This is usually /played.html. Also, don't forget to include the / at the beginning, or else it won't work.

To get everything wrapped up in an HTML table do this:
$radio->getHistoryTable("/played.html");
Same argument, same effect, and it will display everything in a nice HTML table. Well, .. 'nice'... not so nice actually. That's why it has 3 more optional arguments:
$radio->getHistoryTable("/played.html", "Time", "Song", "className");
The second defines the text put at the top of the 'timestamp'-column, the third the text for the songname column and with the fourth and last argument you can give the table a classname so you can define its looks in a stylesheet


Version 2.0 of this class now also supports Icecast servers!

Juggling with the encoding
Sometimes the stream's encoding (character set) is incompatible with the character set you wish to use for your webpage. In this case you can let the shoutcast class convert the information to your desired character set. It's quite simple to achieve this: immediately after you instantiate the $radio object, call setOutputEncoding() and pass the desired character encoding as the argument. For example::
$radio = new Radio($host.":".$ip);
$radio->setOutputEncoding('UTF-8');
This will convert everything to UTF-8. The stream's encoding should be automatically detected, but in case it isn't you can force it by calling setInputEncoding()


Changelog

2.6 (2010-11-07)
- added support for shoutcast 2.0 servers

2.5 (2010-01-27)
- added better support for icecast servers by parsing an additional file with information on the icecast server

2.1 (2009-11-06)
- added support for character set conversion

2.0 (2006-07-19)
- added support for icecast servers

=[Disclaimer]=     © 2005-2012 Excudo.net