Using SoundCloud API to download MP3s

A tutorial on converting and downloading SoundCloud songs using SoundCloud API

Since September 2017, SoundCloud is not accepting new applications for SoundCloud API anymore. That means they closed their API for new users. Read here on how to acquire one >.

A common method to integrate and access SoundCloud data programatically is using their API. With this API access to SoundCloud's internals you can also download songs even when the user who uploaded the song decided to not make it publicly available for download.

This tutorial presumes you have an API key (i.e. client id) needed to authenticate with SoundCloud servers. If you need one, get it here.

In the following paragraphs you will learn how to use SoundCloud's API to create a download script in your selected programming language. If you want to use a solution that is already coded, there are some links and resources that include the scripts needed.

Developing a custom download script

For this you will going to need a CLIENT ID (from your API access data) and refering to Tracks endpoint in SoundCloud's API docs.

To form the streamable track URL you are going to need to create a URL like this: http://api.soundcloud.com/tracks/TRACK_ID/stream?client_id=CLIENT_ID ...where you replace TRACK_ID with the track's id and CLIENT_ID with the client id from your SoundCloud API credentials.

But how to get the track's id? There are multiple ways and it depends in which environment you will run the download script. A couple of options:
  • Fetch user's tracks using SoundCloud API and match by name
  • Via SoundCloud song page in the browser (from the source or observing network response)
  • CURL-ing SoundCloud's song page URL and parsing out the track id

Then, in the programming language you are working with, use a HTTP library that allows you to download a streamable (chunked) URL, which you formed in the previous step.

SoundCloud downloader scripts that you can use

You can use scripts that are already made by other developers. Here are a couple:

SoundCloud downloader script in JavaScript

SoundCloud downloader script in Python

How to get a SoundCloud Client ID

To perform track and streaming requests using the SoundCloud API, you will need a client id. That's a string identificator that SoundCloud uses internally to do monitoring and rate limiting to prevent abuse.

Since SoundCloud closed the applications for new API keys (and with that, client ids), it is not possible to get a new one at this moment. But fortunately, there are a couple of workarounds.

How to get the client id, then?

Scraping GitHub Repositories

GitHub is a place where developers post their code. Many of them posted their SoundCloud API code and left their client ids hardcoded for anyone to see.

If you do a "soundcloud downloader github" Google search, you will discover many code repositories. Then, if you snoop around a bit in them, you will quickly find codes like this:

SoundCloud API keys on Github

You can copy this client id and use it for your own project. One downside is that since this key is publicly available, you might have troubles with rate limiting since other folks could be using these keys as well.

From the SoundCloud website

Go to any SoundCloud page, start playing and observe the Network tab in your browser developer console. There you will find values like: https://api-v2.soundcloud.com/dashbox/listen?&client_id=fm3wyeQvCi4fIiAoBCz40q9gWfzFSUZu

Parse out the client_id parameter and voila, there you have it. You are now ready to download the track via a streamable URL mentioned above.