XpoLyrics Web Application working

A first version of XpoLyrics web application is now implemented. It is a Django application which shows a web interface for selecting a playlist from your Spotify playlists, then it shows the tracks included in it, and after selecting a track, it shows the lyrics for it.

Captura de pantalla de 2018-04-04 07-21-29

During the implementation, the spoting library has grown and now it includes also a genius module to work with the Genius API. The lyrics are shown using the Genius viewer, which is what Genius service will expect from this kind of application (scrapping the lyrics contents, which is trivial, would have legal issues). So now what? The goal of the use case is covered and the conclusion is that cool services can be built mixing Spotify with Genius APIs. But building real services that are in production need not only valuable use cases and implementing them, but also analyzing the business model, all legal issues related to the service if it is a commercial one or the marketing and promotion of the service. And now this is out of scope of spoting plauground, so let’s continue with another use case.


Getting the Lyrics for Spotify Playlists

Another goal reached in this trip using Spotify API. Using the Genius API for Lyrics retrieval,  I have developed xpolyrics, a simple script that show the lyrics from your tracks in your Spotify playlists.

The final idea is to have a web application in which you can select a playlist, a track and the lyrics for this track (song) are shown. This is a tool that I have missed too much in the past, so I am pretty motivated to implement it.

The results for the tests are cool: taking 50 tracks from rare Spanish artists, the lyrics from 49 out of 50 were found.

Using lyrics has some legal limitations and it has been a hot field in the copyright arena. Genius signed an accord with music publishers some years ago, and this is why it has limitations in the lyrics collection and usage. There are cool people doing cool things with lyrics.

Usage of Spotify Web API

In the Dashboard of the registered application you can see how your application is using the Web API from Spotify. Interesting the data already shown in it from my own development. It is just my usage (I am the only one using Spoting application) but with the current data you can understand the API needs of your application to do its work. Thirteen endpoints used already, and getting the top tracks for an artist and the playlist information (adding tracks to them) the most used. It is a kind of profiling for your application.Captura de pantalla de 2018-03-26 07-24-05

First results: Recommender playlist

After hacking during the weekend (30 commits and 300 python sloc) know I understand better the workflow with Spotify and there are some interesting results.

The first step is to find the initial data from which to start doing things. In the “finding new artists to follow use case” I have started finding the artists which I already follow and the ones that are in my top. Using this list, I have found related artists (301). And with the list of related artists I have taken one track per each from their top tracks. And with these selected tracks, I have created a new playlist called Recommender.

After that, evolving this idea, from the related artists I have filtered the ones with less than 5000 followers, to get “rare” recommendations. And I have created a new playlist RecommenderRare, which is more interesting that the original one.

New filters over this new artists can be done, and also, new ways to select what tracks from this new artists we want to include in the playlist.

At the end, what we really normally want is a list of tracks to be included in a playlist. This is the result of our hard work. You can get your own playlists using this script.

RecommenderRare Playlist

Recommender Playlist

Captura de pantalla de 2018-03-25 23-29-17

Spoting GitHub repository

After the initial steps understanding the Spotify API and the kind of data we can collect, it is clear that the Spotify data has a lot of potential. So the next natural step is to start writing some code to understand all the details about the use of the API and to get real data to play with.

I have created a new GitHub repository called spoting in which there is now some code to play with the API for getting the last played tracks, the top tracks, doing searches and more to come. All included in the explorer.py script.

The authentication is a bit tricky but with the help of spotipy it is easy once you have a registered application and a registered user in Spotify.

Be free to play with the code.

What to do with the Spotify API?

Now that we know how to access the Spotify API using authenticated queries, there is a full range of items that we can download. So the next step is design the use cases we want to cover with our development. The goal is to explore my own data. And probably, the most interesting data is the data I have already consumed: what are the songs I have played during the last years, how many times, the artist and so on. If I can access to this information, I can later to create analytics grouping the by artist, by kind of music … and later, to try to create a network of other songs that I would like to hear.

Time to research! The API call Get Current User’s Recently Played Tracks is what we are looking for, but it only returns the last 50 tracks. But playing with the after and before params, maybe we can paginate!  Let’s try!




First steps with the Spotify API

Let’s start using the Spotify API, one of the coolest moments in any data project. For using it, the first step is to understand how to authenticate ourselves in order to do queries to the API the right permissions. After that, the goal is to collect my own basic data from Spotify. So let’s find howto get the API Token for using the API. This part is a bit tricky but without it, the Spotify data can not be accessed.

My workflow is: I have my own application to access my own data. But in any case, I need to register the application in Spotify and after that, provide rights to the application to access my data, following the Authorization Workflow. After registering the application in Spotify, I have followed this spotipy approach to get my personal token. You provide to the script your usename in Spotify and it will open a web browser with the Spotify login form, and once you login and allow the application to access your data, it retrieves your user access token.


With it, if I want to access my playlists:

curl -X GET "https://api.spotify.com/v1/me/playlists" -H "Authorization: Bearer {your user access token}"

 "href" : "https://api.spotify.com/v1/users/acsspotify/playlists?offset=0&limit=20",
 "items" : [ {
 "collaborative" : false,
 "external_urls" : {
 "spotify" : "https://open.spotify.com/user/acsspotify/playlist/5oC7qd6aBFuh29ay4nJkl1"
 "href" : "https://api.spotify.com/v1/users/acsspotify/playlists/5oC7qd6aBFuh29ay4nJkl1",


"limit" : 20,
 "next" : "https://api.spotify.com/v1/users/acsspotify/playlists?offset=20&limit=20",
 "offset" : 0,
 "previous" : null,
 "total" : 42


This article is a nice introduction for using the non authenticated API.