Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * --------------- ShoutCast Radio Stations Search API ---------------
- *
- * @author Pedro P. L. Papadópolis (a.k.a Mandrakke).
- * @copyright There is no copyright, you can use it as you want, you can also show it to you mother to her see how much you are smart.
- *
- * If you speak Portuguese, try out our server;
- * http://brazucas-server.com
- *
- * If you dont, try out our translated-to-english tool (SA-MP Online Objects Viewer);
- * http://brazucas-server.com/$objetos
- *
- *
- * This script is also hosted on http://api.brazucas-dev.com/ShoutCastAPI.php but it can be turned offline at any time if the number of requests increase too much.
- *
- * More information about how to integrate this script with a SA-MP server can be find at the oficial topic on SA-MP forums;
- * http://forum.sa-mp.com/showthread.php?t=347016
- *
- *
- *
- * Version: R1-1 Beta (released in 02/06/2012)
- *
- * -------------------------------------------------------------------
- */
- if(!function_exists("curl_init")) die("cURL library is required.");
- //Disable error messages, if you have issues with this script, comment this line below to see which error occurs.
- error_reporting("E_ALL");
- final class ShoutCastAPI {
- private $forbidden = array('-','!','"','#','$','%','&','\'','(',')','*','+',',','.','/',':',';','<','=','>','?','@','[','\\',']','_','`','{','|','}','~');
- function __construct() {
- $RequestValues = array(
- "ajax" => true,
- "count" => 10,
- "order" => "desc",
- "strIndex" => 0
- );
- if(!isset($_GET["search"]) || strlen($_GET["search"]) == 0) {
- $url = "http://www.shoutcast.com/ajax_dir";
- if(!isset($_GET["field"]))
- $RequestValues["criteria"] = "listenershead";
- else
- $RequestValues["criteria"] = $_GET["field"]."head";
- } else {
- $url = "http://www.shoutcast.com/search-ajax/". urlencode($_GET["search"]);
- if(!isset($_GET["field"]))
- $RequestValues["mode"] = "listenershead2";
- else
- $RequestValues["mode"] = $_GET["field"]."head2";
- }
- $params = null;
- foreach($RequestValues as $ind => $val) {
- if($_GET[$ind] !== null)
- $RequestValues[$ind] = $_GET[$ind];
- $params .= $ind. "=". $RequestValues[$ind]. "&";
- }
- $stations = array();
- $req = $this->Request($url, 1, null, $params, "http://www.shoutcast.com/");
- $filter = new DOMDocument;
- @$filter->loadHTML($req["data"][1]);
- $divs = $filter->getElementsByTagName("div");
- $i = 0;
- foreach($divs as $div) {
- if($div->getAttribute("class") == "dirlist") {
- $a = $div->getElementsByTagName("a")->item(0);
- $stations["stations"]["s".$i]["stationid"] = $a->getAttribute("id");
- $tmp = $a->getAttribute("name");
- for($y = 0; $y < strlen($tmp); ++$y)
- if(!in_array($tmp[$y], $this->forbidden))
- $stations["stations"]["s".$i]["name"] .= $tmp[$y];
- $stations["stations"]["s".$i]["id"] = preg_replace("/^.*?id./i", "", $a->getAttribute("href"));
- $childDivs = $div->getElementsByTagName("div");
- foreach($childDivs as $childDiv)
- switch($childDiv->getAttribute("class")) {
- case "playingtext":
- $tmp = $childDiv->getAttribute("title");
- if($tmp == null && $childDiv->getElementsByTagName("span")->item(0) !== null)
- $tmp = $childDiv->getElementsByTagName("span")->item(0)->getAttribute("title");
- for($a = 0; $a < strlen($tmp); ++$a)
- if(!in_array($tmp[$a], $this->forbidden))
- $stations["stations"]["s".$i]["nowplaying"] .= $tmp[$a];
- if(strlen($stations["stations"]["s".$i]["nowplaying"]) > 13)
- $stations["stations"]["s".$i]["nowplaying"] = substr($stations["stations"]["s".$i]["nowplaying"], 0, 13). "...";
- break;
- case "dirgenre": $stations["stations"]["s".$i]["genre"] = $childDiv->nodeValue; break;
- case "dirlistners": $stations["stations"]["s".$i]["listeners"] = $childDiv->nodeValue; break;
- case "dirbitrate": $stations["stations"]["s".$i]["bitrate"] = $childDiv->nodeValue; break;
- case "dirtype": $stations["stations"]["s".$i]["type"] = $childDiv->nodeValue; break;
- }
- ++$i;
- }
- }
- $stations["stations"]["count"] = $i;
- if(@$vars = $_GET["show"]) {
- $showOnly = explode("|", $vars);
- foreach($stations["stations"] as $stationId => $stationData)
- foreach($stationData as $ind => $val)
- if(!in_array($ind, $showOnly))
- unset($stations["stations"][$stationId][$ind]);
- }
- switch(strtolower($_GET["format"])) {
- case "json":
- $output .= json_encode($stations);
- break;
- case "dini":
- default:
- $output = null;
- foreach($stations["stations"] as $stationId => $stationData)
- if(is_array($stationData))
- foreach($stationData as $ind => $val)
- $output .= $stationId. $ind. "=". $val. "\r\n";
- else
- $output .= $stationId. "=". $stationData. "\r\n";
- }
- die($output);
- }
- private function Request($a, $b, $c, $d, $e) {
- $ch = curl_init();
- $exec = curl_setopt_array($ch, array(
- CURLOPT_URL => $a,
- CURLOPT_RETURNTRANSFER => $b,
- CURLOPT_HEADER => 1,
- CURLOPT_NOBODY => 0,
- CURLOPT_COOKIE => $c,
- CURLOPT_CUSTOMREQUEST => ($d)?"POST":"GET",
- CURLOPT_POSTFIELDS => $d,
- CURLOPT_FOLLOWLOCATION => 1,
- CURLOPT_TIMEOUT => 6,
- CURLOPT_REFERER => $e
- )
- );
- return array(
- "data" => explode("\r\n\r\n", curl_exec($ch), 2),
- "httpcode" => (int)curl_getinfo($ch, CURLINFO_HTTP_CODE)
- );
- }
- } new ShoutCastAPI();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement