[PHP]SoundCloud Download Class
Hello everybody. Just wanted to showcase this little thing I cooked up these last 10 minutes.
It is a PHP class that yields a function that can get the MP3 stream of a song from it's SoundCloud URL.
PHP Code:
<?php
/*
* SoundCloud Download Class
* Copyright 2009, Kimmy Andersson. All Rights Reserved.
* Created by Kimmy Andersson.
*
* Terms:
* You are not allowed to use this for commercial use.
* You are not allowed to claim this as you own, or as anyone else's except mine.
* You are allowed to create deravative works as long as you contact and credit me.
* This is for educational purposes only, I do not stand responsible if you get in trouble by using this.
* This script is not allowed to be redistributed, sold or re-uploaded without asking me.
*
*/
class SOUNDCLOUD
{
function __construct()
{
return;
}
private $soundcloudStreamServer = "http://media.soundcloud.com/stream/";
public function getMP3DownloadFromURI( $uri )
{
$fullPageSource = file($uri);
$fullPageSource = implode("", $fullPageSource);
$streamURIPos = strpos($fullPageSource, $this->soundcloudStreamServer, 0);
if(!$streamURIPos)
return false;
$streamURIArray = substr($fullPageSource, $streamURIPos);
$streamURIArray = explode('"', $streamURIArray);
$streamURI = $streamURIArray[0];
unset($streamURIArray);
if(!strstr($streamURI, $this->soundcloudStreamServer))
return false;
return $streamURI;
}
}
?>
Example to use:
PHP Code:
<?php
include("class/class.soundcloud.php");
$sCloud = new SOUNDCLOUD();
$link = $sCloud->getMP3DownloadFromURI("http://soundcloud.com/user5970490/adam-nickey-callista-original-mix");
if(!$link)
echo("No");
else
echo($link);
?>
Thank you for reading and enjoy.
Re: [PHP]SoundCloud Download Class
You don't need a construct if you're not going to use it.. It's redundant.
Other then that, looks cool ;)
Re: [PHP]SoundCloud Download Class
Well, it's not reduntant in Litespeed since litespeed gives an error when calling the object and a construct isn't present..
Re: [PHP]SoundCloud Download Class
Wouldn't this be more easy and faster? It has less function calls.
PHP Code:
<?php
function getToken($sURL) {
$sPagesource = file_get_contents($sURL);
$iPosition1 = strpos($sPagesource, "\"token\":\"") + 9; //strlen("\"token\":\"");
return substr($sPagesource, $iPosition1, (strpos($sPagesource, "\",\"trackName") - $iPosition1));
}
echo getToken("http://soundcloud.com/user5970490/adam-nickey-callista-original-mix");
?>
Re: [PHP]SoundCloud Download Class
That doesn't return the right stream url.
Re: [PHP]SoundCloud Download Class
Quote:
Originally Posted by
spikensbror
That doesn't return the right stream url.
You can easily update it to get the stream url instead of just the token. Was playing around with substr / strpos for this purpose.
Re: [PHP]SoundCloud Download Class
Quote:
Originally Posted by
Wizkidje
You can easily update it to get the stream url instead of just the token. Was playing around with substr / strpos for this purpose.
He wants you to stream from http://media.soundcloud.com/stream/
Right?