SoundCloud API


In [ ]:
# standard library:
import os  

from pprint import pprint

# other modules:
import matplotlib.pyplot as plt
import pandas as pd
import soundcloud as sc
import yaml

from pymongo import MongoClient
%matplotlib inline

SoundCloud Credentials

For APIs that don't require user authentication, providing a client ID is sufficient

To get a client ID, visit http://developers.soundcloud.com to register an app

Once you've obtained a client id, create a yml file in the same directory as this notebook and add the client id


In [ ]:
credentials = yaml.load(open('api_cred.yml'))
print credentials['CLIENT_ID']

In [ ]:
sc_client = sc.Client(client_id=credentials['CLIENT_ID'])

SoundCloud tracks


In [ ]:
tracks = sc_client.get('/tracks', limit=10)
for track in tracks:
    print track.title

Data Visualisations

Tracks with a Creative Commons Attribution ("cc-by") license sorted by track type.

Possible values for track type include:

“original”, “remix”, “live”, “recording”, “spoken”, “podcast”, “demo”, “in progress”, “stem”, “loop”, “sound effect”, “sample”, “other”


In [ ]:
tracks = sc_client.get('/tracks', license='cc-by', limit=200)

In [ ]:
#Unwrap resources
tracks_list = list()
for track in tracks:
    tracks_list.append({'track_type': track.track_type})
len(tracks_list)

In [ ]:
tracks_df = pd.DataFrame(tracks_list)

In [ ]:
tracks_df.head()

In [ ]:
tracks_df.apply(pd.value_counts).plot(kind='bar')

In [ ]:
tracks_df.describe()