Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[PHP]SoundCloud Download Class

0xC0FFEE
Loyal Member
Joined
Dec 24, 2006
Messages
1,655
Reaction score
477
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:
<?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:
<?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.
 
0xC0FFEE
Loyal Member
Joined
Dec 24, 2006
Messages
1,655
Reaction score
477
Well, it's not reduntant in Litespeed since litespeed gives an error when calling the object and a construct isn't present..
 
Praise the Sun!
Loyal Member
Joined
Dec 4, 2007
Messages
2,502
Reaction score
986
Wouldn't this be more easy and faster? It has less function calls.

PHP:
<?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");
?>
 
Last edited:
Praise the Sun!
Loyal Member
Joined
Dec 4, 2007
Messages
2,502
Reaction score
986
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.
 
Back
Top