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: R2 (released in 04/08/2014)
- *
- * -------------------------------------------------------------------
- */
- 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('-','!','"','#','$','%','&','\'','(',')','*','+',',','.','/',':',';','<','=','>','?','@','[','\\',']','_','`','{','|','}','~');
- private $shoutcastUrlPrefix = 'http://www.shoutcast.com/';
- function __construct() {
- $RequestValues = array(
- "genre" => ($_GET['genre'])?(int)$_GET['genre']:null,
- "station" => ($_GET['station'])?(int)$_GET['station']:null,
- "type" => ($_GET['type'])?(int)$_GET['type']:null,
- "artist" => ($_GET['artist'])?(int)$_GET['artist']:null,
- "song" => ($_GET['song'])?(int)$_GET['song']:null
- );
- $validParams = false;
- foreach($_GET as $ind => $val)
- foreach($RequestValues as $searchInd => $searchVal)
- if($searchInd == $ind) {
- $validParams = true;
- break;
- }
- if(isset($_GET['getStreamUrl'])) {
- $url = $this->shoutcastUrlPrefix. 'Player/GetStreamUrl';
- } else if(count($_GET) > 0 && $validParams) {
- $url = $this->shoutcastUrlPrefix. 'Search/UpdateAdvancedSearch';
- } else {
- $url = $this->shoutcastUrlPrefix. 'Home/Top';
- }
- $count = ($_GET['count'])?(int)$_GET['count']:10;
- $start = ($_GET['start'])?(int)$_GET['start']:0;
- $show = ($_GET['show'])?explode('|', $_GET['show']):false;
- $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, $this->shoutcastUrlPrefix);
- if(isset($_GET['getStreamUrl'])) die($req['data'][1]);
- $i = 0;
- $response = json_decode($req['data'][1]);
- foreach($response as $station) {
- if(isset($_GET['streamUrl'])) {
- $stationUrlRequest = $this->Request($this->shoutcastUrlPrefix. 'Player/GetStreamUrl', 1, null, array('station' => $station->ID), $this->shoutcastUrlPrefix);
- preg_match('/"(.*?)"/', $stationUrlRequest['data'][2], $stationUrl);
- $stations['stations']['s'. $i]['streamUrl'] = $stationUrl[1];
- }
- foreach($station as $ind => $val)
- if($i >= $start && (in_array($ind, $show) || !$show))
- $stations['stations']['s'. $i][$ind] = $val;
- if($i > $count) 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), 3),
- "httpcode" => (int)curl_getinfo($ch, CURLINFO_HTTP_CODE)
- );
- }
- } new ShoutCastAPI();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement