Morphex's blogologue (Life, technology, music, politics, business, mental health and more)

This is the blog of Morten W. Petersen, aka. morphex in various places. I blog about my life, and what I find interesting and/or important. This is a personal blog without any editor or a lot of oversight so treat it as such. :)

My email is morphex@gmail.com.

I am leavingnorway.info.

An OGG/Vorbis player, implemented in Javascript.

My Kiva bragging page
My shared (open source) code on GitHub

Morphex's Blogodex

News
Me on Instagram
Slashdot

Zope hosting by Nidelven IT

Morten Petersen on Linkedin

Morten Petersen on Facebook

Morten Petersen on SoundCloud

Morten Petersen on MixCloud

Blogologue on Twitter



Older entries



Atom - Subscribe - Categories

Facebook icon Share on Facebook Google+ icon Share on Google+ Twitter icon Share on Twitter LinkedIn icon Share on LinkedIn

A SoundCloud(R) export tool

Hoi. OK, so these last couple of weeks I've been cleaning up things in my SoundCloud account, as there were lots of cover songs and some mixes and remixes that triggered the "SoundCloud copyright system".

There has been many rounds back and forth, and I even had to clear out private tracks for example of cover songs, which is strange.

Anyway, I figured that it would be nice to be able to export all of the content I've created over the last couple of years, just in case SoundCloud decides to "terminate" my account, files could be lost etc.

I downloaded the python-soundcloud package, and started getting to work. This module has been created by some person over @ SoundCloud. After some trying and failing it looked like it wasn't able to download tracks with the package, so I forked it on github ( here https://github.com/morphex/soundcloud-python ). Using that module and the following code in a script called for example download.py should do the trick.

# The following code is available under the GPL, version 3, available here: http://www.gnu.org/copyleft/gpl.html

import soundcloud, urllib2, urllib
from soundcloud.request import make_request
import os

CLIENT_ID = 'REGISTER ON SOUNDCLOUD AS APP'
CLIENT_SECRET = 'REGISTER ON SOUNDCLOUD AS APP'
USERNAME='YOUR SOUNDCLOUD EMAIL'
PASSWORD='YOUR SOUNDCLOUD PASSWORD'
LIMIT = 1000 # Maximum number of tracks to download
             # a limit in case something goes wrong 
             # so we don't hammer the system.

def download_tracks(output_directory):
    client = soundcloud.Client(
        client_id=CLIENT_ID,
        client_secret=CLIENT_SECRET,
        username=USERNAME,
        password=PASSWORD,
        )
    for track in client.get('/me/tracks', limit=LIMIT):
        path = track.download_url[len('https://api.soundcloud.com/')-1:]
        filename, data = client.get(track.download_url)
        output = open(os.path.join(output_directory, filename), 'w')
        output.write(data)
        output.close()
        print 'Downloaded file: ', filename

if __name__ == '__main__':
    import sys
    if len(sys.argv) != 2:
        raise SystemExit, 'output directory required'
    import os
    output_directory = sys.argv[1]
    try:
        os.mkdir(output_directory)
    except OSError:
        pass
    download_tracks(output_directory)


[Permalink] [By morphex] [Technology (Atom feed)] [03 Jan 01:55 Europe/Oslo]