<?php
require_once 'Services/Soundcloud.php';
/*
* function to get via cUrl
* From lastRSS 0.9.1 by Vojtech Semecky, webmaster @ webdot . cz
* See http://lastrss.webdot.cz/
*/
function curlGet($URL) {
$ch = curl_init();
$timeout = 3;
curl_setopt( $ch , CURLOPT_URL , $URL );
curl_setopt( $ch , CURLOPT_RETURNTRANSFER , 1 );
curl_setopt( $ch , CURLOPT_CONNECTTIMEOUT , $timeout );
/* if you want to force to ipv6, uncomment the following line */
//curl_setopt( $ch , CURLOPT_IPRESOLVE , 'CURLOPT_IPRESOLVE_V6');
$tmp = curl_exec( $ch );
curl_close( $ch );
return $tmp;
}
/*
* function to use cUrl to get the headers of the file
*/
function get_location($url) {
$my_ch = curl_init();
curl_setopt($my_ch, CURLOPT_URL,$url);
curl_setopt($my_ch, CURLOPT_HEADER, true);
curl_setopt($my_ch, CURLOPT_NOBODY, true);
curl_setopt($my_ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($my_ch, CURLOPT_TIMEOUT, 10);
$r = curl_exec($my_ch);
foreach(explode("\n", $r) as $header) {
if(strpos($header, 'Location: ') === 0) {
return trim(substr($header,10));
}
}
return '';
}
function get_size($url) {
$my_ch = curl_init();
curl_setopt($my_ch, CURLOPT_URL,$url);
curl_setopt($my_ch, CURLOPT_HEADER, true);
curl_setopt($my_ch, CURLOPT_NOBODY, true);
curl_setopt($my_ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($my_ch, CURLOPT_TIMEOUT, 10);
$r = curl_exec($my_ch);
foreach(explode("\n", $r) as $header) {
if(strpos($header, 'Content-Length:') === 0) {
return trim(substr($header,16));
}
}
return '';
}
function get_description($url) {
$fullpage = curlGet($url);
$dom = new DOMDocument();
@$dom->loadHTML($fullpage);
$xpath = new DOMXPath($dom);
$tags = $xpath->query('//div[@class="info-description-body"]');
foreach ($tags as $tag) {
$my_description .= (trim($tag->nodeValue));
}
return utf8_decode($my_description);
}
// create a client object with your app credentials
$client = new Services_Soundcloud(
'6813c5d125013568ef986b73e4ba265c', '2eb6f212de6f4963c3873f8afdf517e9');
// a permalink to a track
$track_url = 'http://soundcloud.com/forss/voca-nomen-tuum';
if($_GET['url']){
$track_url = $_GET['url'];
}
$url='http://api.soundcloud.com/resolve.json?url='.$track_url.'&client_id=6813c5d125013568ef986b73e4ba265c';
$headers=get_headers($url,1);
$location=$headers['Location'];
// resolve track URL into track resource
//$track = json_decode($client->get('resolve', array('url' => $track_url)));
/* now that we have the track id, we can get a list of comments, for example
foreach (json_decode($client->get('tracks/' . $track->id . 'comments')) as $c)
print 'Someone said: ' . $c->body . ' at ' . $c->timestamp . "\n";
try {
$track = $soundcloud->download($track->id);
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
exit($e->getMessage());
}
file_put_contents("files/download.mp3",$track);
echo "<a href='files/download.mp3'>download</a>";*/
echo $location;
function modify_url($mod, $url = FALSE){
// If $url wasn't passed in, use the current url
if($url == FALSE){
$scheme = $_SERVER['SERVER_PORT'] == 80 ? 'http' : 'https';
$url = $scheme.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
}
// Parse the url into pieces
$url_array = parse_url($url);
// The original URL had a query string, modify it.
if(!empty($url_array['query'])){
parse_str($url_array['query'], $query_array);
foreach ($mod as $key => $value) {
if(!empty($query_array[$key])){
$query_array[$key] = $value;
}
}
}
// The original URL didn't have a query string, add it.
else{
$query_array = $mod;
}
return $url_array['scheme'].'://'.$url_array['host'].'/'.$url_array['path'].'?'.http_build_query($query_array);
}
$location = modify_url(array('client_id' => 6813c5d125013568ef986b73e4ba265c), $location);
$json = file_get_contents($location);
$obj = json_decode($json);
echo $obj->id;
?>
- Output for 5.4.0 - 5.4.24
- Parse error: syntax error, unexpected 'c5d125013568ef986b73e4ba265c' (T_STRING), expecting ')' in /in/gqc70 on line 121
Process exited with code 255. - Output for 5.3.0 - 5.3.28
- Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/gqc70 on line 121
Process exited with code 255.
preferences:
159.24 ms | 1432 KiB | 7 Q