Created
June 15, 2013 14:11
-
-
Save nguyenvanduocit/5788277 to your computer and use it in GitHub Desktop.
get stream URL from soundcloud
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SoundcloudAPI | |
{ | |
protected $clientID; | |
function __construct() { | |
$this->clientID = "69b6a6bc4f7d483fd21b170137a9cd51"; | |
} | |
function GetTrackLink($id) | |
{ | |
$trackinforURL = "http://api.soundcloud.com/tracks/$id.json?client_id=69b6a6bc4f7d483fd21b170137a9cd51"; | |
return json_decode($this->getPageData($trackinforURL)); | |
} | |
function getPageData($url, $follow = TRUE, $cookie = FALSE) | |
{ | |
$cookie_file_path = 'cookies.txt'; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $follow); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_FILETIME, 1); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 0); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; it; rv:2.0b4) Gecko/20100818'); | |
curl_setopt($ch, CURLOPT_REFERER, $url); | |
if($cookie) | |
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); | |
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
return $data; | |
} | |
function getStreamURL($id) | |
{ | |
$track = $this->GetTrackLink("oh-love-01"); | |
return $track->stream_url."?client_id=".$this->clientID; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'Soundcloud.class.php'; | |
if(isset($_GET["id"])) | |
{ | |
$demo = new SoundcloudAPI(); | |
header ('Location: '.$demo->getStreamURL($_GET["id"])); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment