jul
1
2009
1
2009
Detectar si tienes locutores al aire con shoutcast y Php

Este es un exelente script en php en el cual consiste en imprimirte que locutoresta al aire segun la configuracion que tengas puesta en tu shoutcast cuando estas transmitiendo.
1 2 | / Información del servidor shoutcast $host = TU IP; $port = EL PUERTO; $password = PASSWORD DEL SHOUTCAST; //Ejecuta cada ves que ahy un elemento XML function StartHandler(&$Parser, &$Elem, &$Attr) { global $Data, $CData; /* Start with empty CData array. */ $CData = array(); /* Put each attribute into the Data array. */ while ( list($Key, $Val) = each($Attr) ) { $Data["$Elem:$Key"] = trim($Val); //echo "$Elem:$Key = " . $Data["$Elem:$Key"] . "\n"; } } // Busca los elementos XML function CharacterHandler(&$Parser, &$Line) { global $CData; /* * Place lines into an array because elements * can contain more than one line of data. */ $CData[] = $Line; } function EndHandler(&$Parser, &$Elem) { global $Data, $CData, $listeners, $server, $song, $dj, $wee, $locu; //Mush all of the CData lines into a string and put it into the $Data array. $Data[$Elem] = trim( implode('', $CData) ); //echo "$Elem = " . $Data[$Elem] . "<br>\n"; switch ($Elem){ //for each case, we are putting some data into a variable. case 'SERVERGENRE': $server['GENRE'] = $Data['SERVERGENRE']; break; case 'AIM': $dj['AIM'] = $Data['AIM']; break; case 'SERVERTITLE': $locu['LO'] = $Data['SERVERTITLE']; break; } } //empiesa la conexion $fp = @fsockopen($host, $port, $errno, $errstr, 30); if (!$fp) { echo "Connection to server could not be established! <BR>"; } else { //request xml fputs($fp,"GET /admin.cgi?pass=".$password."&mode=viewxml&page=0 HTTP/1.0\nUser-Agent: Mozilla Compatible\n\n"); while(!feof($fp)) { //put xml into $Data $Contents .= fgets($fp, 1000); } } //close connection fclose($fp); $Contents = str_replace('HTTP/1.0 200 OK','', $Contents); $Contents = str_replace('Content-Type:text/xml','', $Contents); $Contents = str_replace("\n",'', $Contents); $Contents = str_replace("\r",'', $Contents); $Contents = preg_replace('/(&|&;)/i', '&', $Contents); $Contents = preg_replace('/[^\x20-\x7E\x09\x0A\x0D]/', "\n", $Contents); $Data = array(); // Initialize the parser. $Parser = xml_parser_create('ISO-8859-1'); xml_set_element_handler($Parser, 'StartHandler', 'EndHandler'); xml_set_character_data_handler($Parser, 'CharacterHandler'); //Pass the content string to the parser. if (!xml_parse($Parser, $Contents)) { $Probs[] = "$URI$Sym\n Had problem parsing file:\n " . xml_error_string(xml_get_error_code($Parser)); } if (isset($Probs)) { echo implode("\n", $Probs); } $fp = @fsockopen($host, $port, $errno, $errstr, 30); //abre connection if(!$fp) { $success=2; //se-t if no connection } if($success!=2){ //if connection fputs($fp,"GET /7.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n"); //get 7.html while(!feof($fp)) { $page .= fgets($fp, 1000); } fclose($fp); //Cierra connection $page = ereg_replace(".*<body>", "", $page); //extract data $page = ereg_replace("</body>.*", ",", $page); //extract data $numbers = explode(",",$page); //extract data $currentlisteners=$numbers[0]; //set variable $connected=$numbers[1]; //set variable if($connected==1) //if DSP is connected $wordconnected="yes"; //set variable else //if no DSP connection $wordconnected="no"; //set variable $peaklisteners=$numbers[2]; //set variable $maxlisteners=$numbers[3]; //set variable $reportedlisteners=$numbers[4]; //set variable $bit=$numbers[5]; } if($success!=2 && $connected==1){ $song=explode(" - ",$numbers[6]); $string0= $locu[LO]; $string1= $server[GENRE]; $string2= $song[0]; $string3= $song[1]; $string4= "<b>Correo locutor:</b> "; $string5= $dj[AIM]; print "<marquee onMouseOver='this.stop()' onMouseOut='this.start()'><b>Locutor:</b> ".$string0." | "; print "<b>Rola:</b> ".$string2." | "; print $string4; print $string5."<br></marquee>"; }else { $string1= "<marquee onMouseOver='this.stop()' onMouseOut='this.start()'>En este momento no hay locutores al aire </marquee>"; print $string1; } |
Con este simple script podemos saber quien transmite o si esta fuera del aire, este script es muy bueno y si tu tienes una estacion de radio en tu web que esperas en ponerlo.
Miguel Ortega
Related Posts
2 Comments + Add Comment
Leave a comment
Patrocinador
Siguenos
Suscribete
Correo @zoneartcss.com
Comentarios
- juan manuel en Subdominios con php y .htaccess
- PCHART-Crear gráficas en PHP | Espacio de *M@?!*[lOs KeRoS mUcHo a ToDoS...] en Pchart – Crear gráficas en PHP
- EH en Evitar resize de un textarea con CSS
- KAREN en Envia mensajes de texto gratis a celulares telcel
- Elie Cottage en Ventajas y desventajas de tener un blog gratis

An article by







como inserto este codigo enmi web??? espero me peudas ayduar por que se ve que esta muy interesante!! ayuda porfa!!
Orales gracias por el codigo,
Una pregunta man, esto mismo se podria hacer con el giss.tv??
esque en ninguna parte del codigo veo que hagas referencia al servidor de la radio.
Gracias por la inspiracion.