[PHP]SoundCloud Download Class

Results 1 to 7 of 7
  1. #1
    0xC0FFEE spikensbror is offline
    MemberRank
    Dec 2006 Join Date
    SwedenLocation
    1,855Posts

    [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->soundcloudStreamServer0);
            
            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.


  2. #2
    :-) s-p-n is offline
    DeveloperRank
    Jun 2007 Join Date
    Next DoorLocation
    2,098Posts

    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 ;)

  3. #3
    0xC0FFEE spikensbror is offline
    MemberRank
    Dec 2006 Join Date
    SwedenLocation
    1,855Posts

    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..

  4. #4
    Praise the Sun! Solaire is offline
    MemberRank
    Dec 2007 Join Date
    Undead BurgLocation
    2,862Posts

    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");
    ?>
    Last edited by Solaire; 04-01-10 at 07:32 PM.

  5. #5
    0xC0FFEE spikensbror is offline
    MemberRank
    Dec 2006 Join Date
    SwedenLocation
    1,855Posts

    Re: [PHP]SoundCloud Download Class

    That doesn't return the right stream url.

  6. #6
    Praise the Sun! Solaire is offline
    MemberRank
    Dec 2007 Join Date
    Undead BurgLocation
    2,862Posts

    Re: [PHP]SoundCloud Download Class

    Quote Originally Posted by spikensbror View Post
    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.

  7. #7
    :-) s-p-n is offline
    DeveloperRank
    Jun 2007 Join Date
    Next DoorLocation
    2,098Posts

    Re: [PHP]SoundCloud Download Class

    Quote Originally Posted by Wizkidje View Post
    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?
    Last edited by s-p-n; 07-01-10 at 06:17 AM.



Advertisement