Monday, December 04, 2017

How to log in to SoundCloud in Kodi

The SoundCloud add-on for Kodi accesses SoundCloud via its API and OAuth2 authentication. It is supposed to log in once using your username and password, and get a token. After this, there is no need for your password, and it can access SoundCloud using just the token.

The problem is that SoundCloud's initial procedure for obtaining the token has changed, and you now need to use the /connect method. But, once the add-on has the token, it can log in. So, the solution is to get the token using another method.

Soundnode is a desktop app which also authenticates to SoundCloud via OAuth2. After authenticating, the token can be found in its configuration files.  In Linux, URL strings including the token can be found in ~/.config/Soundnode/Cache/data_*. Look for URL inside like https://api.soundcloud.com/me.json?&oauth_token=something . Then add the token to your add-on configuration file, in Linux at ~/.kodi/userdata/addon_data/plugin.audio.soundcloud/settings.xml. You need to add <setting id="login.access_token" value="something" /> .

While the add-on doesn't need the login.username and login.password, its code is written such that they need to exist and the login.hash needs to match. You can compute the hash in Python using:

import hashlib
username = 'username'
password = 'whatever'
m = hashlib.md5()
m.update(username.encode('utf-8') + password.encode('utf-8'))
m.hexdigest()


Since the add-on is incapable of actually using this information to log in, feel free to not actually put your real password there. The OAuth2 token provides access to your SoundCloud account, so keep that secure.

This may not be a complete solution, because although I can access lists of things, playback fails with a HTTP 401 error. I don't know if that means the SoundNode API quota is depleted or if I need to do other things. Setting CLIENT_ID and User-Agent in ~/.kodi/addons/plugin.audio.soundcloud/resources/lib/content/client.py did not help.

No comments: