|
From: OryNider <ory...@us...> - 2008-02-24 01:26:51
|
Update of /cvsroot/mxbb/mx_shotcast/includes In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18322/includes Modified Files: common.php Added Files: shotcast_class.php Log Message: upgrade to 2.0.8 --- NEW FILE: shotcast_class.php --- <?php /** * radio.class is a stand-alone php class for ShoutCast Servers that obtains informations about the server. * USAGE: * $variable = new radio(HOST, PORT); - Construct the Object. ie. - new radio($SERVER_NAME, 8000); * $variable->host - Get server host. (INT) * $variable->port - Get server port. (INT) * $variable->stat - Status if server is on/off (INT, 1=on, 0=off) * $variable->bitrate - Bitrate of streaming audio. (INT) * $variable->listners - Listners. (INT) * $variable->station - Radiostation name (STRING) * $variable->genre - Streamers selected genre. (STRING) * $variable->song - Current song. (STRING) * $variable->played - Last played songs (ARRAY[STRING]) * * @author Niklas Pull * @created 2008-02-04, Sweden * * Keep the autor tag in order to use or distrubutate this php class, */ //ini_set('error_reporting', E_ALL ^ E_WARNING ^ E_NOTICE); class radio { var $host; var $port; var $rawdata; var $stat = 0; var $c = 0; /** * Constructor for radio class. * @param $host Server Host. * @param $port Server Port */ function radio($host, $port) { $this->host = $host; $this->port = $port; $this->rawdata = $this->getServerData("index.html"); $this->stat = $this->servStat(); } /** * Collecting raw data from ShoutCast server. * @param $source From where to collect data. * @return An array with each row. */ function getServerData($source) { $fp = @fsockopen($this->host, $this->port, $errno, $errstr, 10); if (!$fp) { return; } else { @fputs($fp, "GET /$source HTTP/1.1\r\n"); @fputs($fp, "Host: $this->host\r\n"); @fputs($fp, "User-Agent: SHOUTcast Song Status (Mozilla Compatible)\r\n\r\n"); @fputs($fp, "Connection: close\r\n\r\n"); while (!feof($fp)) { $buf .= @fgets($fp,128); } @fclose($fp); return explode("\t", strip_tags(str_replace(array("</td>", "</tr>", "Current Song"), array("\t", "\t", " Current Song"), $buf))); } } /** * @return An integer, 1 if the server is streaming otherwise 0. */ function servStat() { $i = 0; while ($i < count($this->rawdata)) { $this->rawdata[$i] = trim($this->rawdata[$i]); if (strstr($this->rawdata[$i], "Server Status:")) { $tmp = explode(" ", $this->rawdata[$i+1]); return ($tmp[3] == "up") ? "1" : "0"; } $i++; } return 0; } /** * @return An integer representing the bitrate of the streaming. */ function bitrate() { $i = 0; if($this->stat !== 1) { return 0; } while ($i < count($this->rawdata)) { $this->rawdata[$i] = trim($this->rawdata[$i]); if (strstr($this->rawdata[$i], "Stream Status:")) { $bitr = explode(" ", $this->rawdata[$i+1]); return $bitr[4]; } $i++; } } /** * @return An integer of how many listners. */ function listners() { $i = 0; if($this->stat !== 1) { return 0; } while ($i < count($this->rawdata)) { $this->rawdata[$i] = trim($this->rawdata[$i]); if (strstr($this->rawdata[$i], "Stream Status:")) { $listn = explode(" ", $this->rawdata[$i+1]); return $listn[7]; } $i++; } } /** * @return A string representing the Stream title. */ function station() { $i = 0; if($this->stat !== 1) { return; } while ($i < count($this->rawdata)) { $this->rawdata[$i] = trim($this->rawdata[$i]); if (strstr($this->rawdata[$i], "Stream Title:")) { return $this->rawdata[$i+1]; } $i++; } } /** * @return The streaming genre. */ function genre() { $i = 0; if($this->stat !== 1) { return; } while ($i < count($this->rawdata)) { $this->rawdata[$i] = trim($this->rawdata[$i]); if (strstr($this->rawdata[$i], "Stream Genre:")) { return $this->rawdata[$i+1]; } $i++; } } /** * @return A string with the current song playing on the stream. */ function song() { $i = 0; if($this->stat != 1) { return; } if($this->c != 0) { return trim($this->rawdata[$this->c]); } while ($i < count($this->rawdata)) { $this->rawdata[$i] = trim($this->rawdata[$i]); if (strstr($this->rawdata[$i], "Current Song:")) { $this->c = $i+1; return $this->rawdata[$i+1]; } $i++; } } /** * @return An array with Strings of every previous played song, the lenght is set inte the .ini file for the ShoutCast server. */ function played() { $played = array(); $i = 0; if($this->stat != 1) { return; } $raw_played = $this->getServerData("played.html"); while ($i < count($raw_played)) { $raw_played[$i] = trim($raw_played[$i]); if (strstr($raw_played[$i], "Current Song")) { $i=$i+3; break; } $i++; } $j=0; while ($raw_played[$i-1] != "") { $played[$j] = $raw_played[$i]; $i=$i+2; $j++; } return $played; } } ?> |