Downloading Songs from Soundcloud

Published 2012-11-21 on Farid Zakaria's Blog

The next task

I've been fiddling around with HypeMachine for quite a while now even though my personal music taste has taken me elsewhere in search of music. Lately, I've been enjoying subscribing to individual artists on Soundcloud as a way of finding more niche electronica.

My experience so far with Soundcloud has been great. They even let you download some songs based on settings set by the artist! I however want the music while I'm on the go; especially on my jogs. I've now moved onto the task of seeing how I can liberate much of my beloved music from Soundcloud similarly to what I've accomplished with HypeMachine.

Investigation

Once again most of the information gleamed was from saving the raw HTML of a request to SoundCloud outside the browser (i.e. via python or perl). They look to be doing something similar to HypeMachine in removing certain HTML elements because I cannot find them when I view source through my browser.


<script type="text/javascript">
window.SC.bufferTracks.push({"id":64568412,"uid":"WtquUHiysWgk",
                              "user":{"username":"diplo","permalink":"diplo"},
                              "uri":"/diplo/got-stoned-and-mixed-really",
                              "duration":2162227,
                              "token":"H7TPl",
                              "name":"got-stoned-and-mixed-really",
                              "title":"got stoned and mixed really old records for half an hour",
                              "commentable":true,
                              "revealComments":true,
                              "commentUri":"/diplo/got-stoned-and-mixed-really/comments/",
                              "streamUrl":"http://media.soundcloud.com/stream/WtquUHiysWgk?stream_token=H7TPl",
                              "waveformUrl":"http://w1.sndcdn.com/WtquUHiysWgk_m.png",
                              "propertiesUri":"/diplo/got-stoned-and-mixed-really/properties/","statusUri":"/transcodings/WtquUHiysWgk",
                              "replacingUid":null,"preprocessingReady":true,
                              "renderingFailed":false,"isPublic":true,
                              "geo":[],
                              "commentableByUser":true,
                              "favorite":false,
                              "followingTrackOwner":false});
</script>

We can see one of the track elements is the streamURL:

"streamUrl":"http://media.soundcloud.com/stream/WtquUHiysWgk?stream_token=H7TPl"

Node.JS Style

Grabbing the bufferTracks variable can easily be accomplished in Node.JS with the help of the jsdom. I'd simply need to build the DOM according to the HTML file and access the JavaScript variable! I'm curious if there is even an easier way.... Drop a comment if you know of one!