Build a Python2 based application using Deezer Native SDK

Bringing music everywhere

Deezer offers developers various SDK (Software Development Kit) in order to include Deezer music in their applications.

The Native SDK is one of these and mainly allows Deezer services like playback and offline synchronization.

By integrating this SDK you can address the three major platforms: Linux, MacOS and Windows.

(1) Mac OS X 10.8 or upper. (2) Windows7 or upper. (3) Validated with Fedora23 and Raspbian Jessie

Since the release of the Native SDK on March the 30th, Deezer tries to provide more and more sample applications in different languages in order to help developers make their own applications in their favorite one.

In that context I was hired to develop the first sample apps and wrappers for some popular languages, so I created two wrappers and an example application, in C# and Python respectively. Here we will focus on the Python2 sample app and wrapper.

Embed Deezer in a Python application

As the SDK is originally written in C/C++, I managed to develop a python2 wrapper in order to allow developers to make their own Python application using the NativeSDK.

The Python2 sample is a console-based application. It calls the SDK functions via a wrapper that uses CTypes to translate C functions from the SDK into Python2 functions. I chose CTypes mostly because I was used to it and because I didn’t need any advanced wrapping functionalities, just to translate a bunch of C types and some simple functions. Although the structure pointers translation was pretty rough I managed to translate the major SDK functions into Python definitions.

The structure of the wrapped library along with the python sample

The wrapper itself can be used with any application you created. You can delete the whole sample app and replace it with your own.

One quick note about authentication

This sample does not implement the OAuth2 authentication process (this process is required to identify yourself and your application when using the Deezer API). It uses instead an already generated access token for demonstration purpose. For more information about how to generate your access token, read this article. If you do not feel comfortable with this process or just want to test the sample, you can use the given access token (see below).

How to use this sample

You first need to download the NativeSDK here, then clone the sample code repository on GitHub there.

  • Place the SDK folder from the NativeSDK folder into the root of the repository as shown below:
<native-sdk-samples>
├── NativeSDK
│ ├── Bins
│ └── Include
├── PythonSample
├── README.md- Exemple simple d’intégration.
...
  • Open myDeezerApp.py with your favorite text editor. Here change the authentication info with your personal OAuth info. Leave the original values for a sample free user.
self.user_access_token = ”” # SET your user access token
self.your_application_id = ”" # SET your application id
self.your_application_name = ”” # SET your application name
self.your_application_version = ”" # SET your application version
self.user_cache_path = ”” # SET the user cache path
  • Run app_start.py with Python2. For example, in order to play the album 11375984 (Zanaka by Jain):
python app_start.py dzmedia://album/11375984
  • That’s it! Follow the instruction on the output in order to use the player. Here are the basic keystrokes:
S to start or stop the playbackP to play or pause the playback+ to play the next track of the track list- to play the previous track of the track listR to toggle the repeat mode (OFF / ONE / ALL)? to toggle the random mode (OFF / ON)Q to shutdown the application

You can of then reuse the python wrapper for your own python application and use this sample as an inspiration.

Article written by: LEANDRI Aurélien