From 2 weeks to 15 minutes — How we optimized playlist generation

From 2 weeks to 15 minutes — How we optimized playlist generation In the past few years, the music streaming industry has been very competitive and all companies are looking for a way to differentiate themselves. At Deezer, we aim at being the least standardized, most personalized and most human streaming service. Providing musical recommendations to millions […]

From 2 weeks to 15 minutes — How we optimized playlist generation

In the past few years, the music streaming industry has been very competitive and all companies are looking for a way to differentiate themselves. At Deezer, we aim at being the least standardized, most personalized and most human streaming service. Providing musical recommendations to millions of users relies heavily on algorithms but a key part of what makes Deezer different, more human, is that we also truly count on the wonderful work of our Editorial team. They are the ones behind Deezer’s curated playlists, looking to create the perfect combination of tracks to enlighten key moments of your life.

The problem

“100%” playlists are a collection of playlists that our editors curate and that our users particularly love. They consist of a selection of the 50 most iconic tracks of an artist or band. To make things even better, Deezer Free users can listen to some of these playlists without restrictions depending on their tastes, listening habits and favorite content.

Our Editorial team was so overwhelmed by the success of the “100%” playlists that at some point, an average of two weeks were needed to create a single playlist!

That’s when the Tooling Team stepped in.

The Tooling Team

The Tooling Team works in the shadows, as part of the Quality & Operations division, and tries to automate tedious tasks, mainly collaborating with teams who don’t have their own developers and can’t solve those issues in autonomy. The main clients of the Tooling Team are the Customer Care and Editorial teams.

The analysis

When breaking down the process of generating a “100%” playlist, it became clear where the issues lay and what needed to be done to bring joy and happiness back into our editors’ lives.

There are 3 main steps required to create a “100%” playlist:

  1. Gather an initial list of tracks from the artist or band (these are provided by the Recommendation team)
  2. Check, reorder and filter these tracks to create the best listening experience (this is done by the Editorial Team)
  3. Create the playlist cover that will be displayed in the Deezer product (this is done by the Studio Team, who is responsible for all of our digital assets)

The second step is where the editorial magic happens, and it can hardly be done by an algorithm, especially if you want to keep this human touch that we like so much at Deezer.

However, step 1 and 3 are both ideal candidates for automation.

The story of how we automated the first step would be a good read, but here I chose to focus on how we designed a tool that automatically generates covers for “100%” playlists.

Because every new cover was generated by the Studio team, a bottleneck had appeared: in the best case scenario, it would take them one week to deliver the cover; in the worst case scenario, it would take them up to three weeks.

couverture-facile

The Tooling Team has a history of finding funny names for their various projects they create and this one is no exception. Named after the French riddle website ouverture-facile, the goal of couverture-facile is to automatically generate “100%” playlist covers.

Starting from an artist ID, we need to:

  1. Find the artist name and the image that will be used for the cover
  2. Render the background
  3. Draw the Deezer logo
  4. Draw the “100%” asset
  5. Draw the artist name

1/ Gather the artist information

Thanks to the Partnership division at Deezer, external developers have access to a simple subset of our internal APIs. It is documented here.

A few Python lines later, we have what we were looking for.

2/ Render the background

Once we have an image url, creating our background for the next steps is very easy.

The issue when automating image generation is that you have to deal with various visuals. So here, we are turning down brightness a little bit to accommodate very bright images and be able to draw things in white on top of them.

3/ Draw the Deezer logo

Thanks to the rebranding we conducted a few years ago, the Deezer logo is now a bit simpler to draw programmatically. Here, we are placing it in the bottom right corner of the cover.

Since all the covers have the same size, the quick and dirty way involves a lot of (otherwise undesirable) magic numbers.

4/ Draw the “100%” asset

Nothing fancy here:

The most tricky thing is to determine the top position of the asset. And THAT is where all the complexity lies. More on that next!

5/ Draw the artist name

Since we are dealing with all kinds of artists’ names (from a few letters to several words) and alphabets (mainly Latin, Japanese, Arabic, Hebrew), drawing the artist’s name is the most complicated part of the project.

Different alphabets mean that we require different fonts. To select the appropriate one, we first need to detect which one is used. Fortunately for us, it can be done easily:

Here, we are only dealing with the first alphabet we found in the artist’s name, but you get the idea.

Once we know the one to target, a quick lookup will give us the font:

The last line of this snippet is very important since some languages are read from right to left and require some text transformations.

One thing I didn’t anticipate is that I would have to manually split the artist’s name on several lines when it is too long for the selected configuration. After a lot of trials and errors, this is the method i settled for:

If the artist’s name doesn’t fit on one line, we try to split the name in tokens that we evenly spread on two lines. Some artists’ names are still too long to fit on two lines, and for those special edge cases, we just fill one line before adding another one.

Now that we know if our text fits on one line or more, we know where we can draw the “100%” asset and consequently we know where we can position the text, wrapping up this project with a nice and clean:

Notice that the anchor parameter is set to “ms”. This is the simplest way I could find to position multiline text on an image while ensuring decent results.

https://pillow.readthedocs.io/en/stable/handbook/text-anchors.html

This tool doesn’t cover every edge case but it doesn’t really matter. The idea was to speed up the process for 95% of playlists generated and let the Studio Team deal with the remaining 5% corner cases that would be a nightmare to automate.

From PoC to Prod

The key for a quick hack to be successful is to move fast. As soon as couverture-facile worked in a test environment, the last step was to integrate it into the “100%” playlist generator that we created for editors in our internal back office. Once done, the process was almost fully automated: editors can now pick the artist they wish to create a playlist for and the tool automatically generates the cover and initial track list using our internal recommendation API.

In a few steps, editors are provided with a basic but satisfactory “100%” playlist that they can tailor to their tastes before publishing it to the users.

The whole process — from creation to publication — now only takes 15 minutes instead of 2 weeks.

Conclusion

In line with one of Deezer’s core values — “Just Hack It”, we managed to create a tool in a short time that greatly helps our Editorial team in their day-to-day work.

Helping internal teams be more efficient can be achieved in a lot of surprising ways but one thing that is common to all these projects is the satisfaction of unlocking “virtual head counts” by automating repetitive tasks, so that other teams can focus their efforts on what really matters: our users.

Do you want to help us build and deliver the best experience on Deezer?
Take a look at our
open positions and join one of our teams!


From 2 weeks to 15 minutes — How we optimized playlist generation was originally published in Deezer I/O on Medium, where people are continuing the conversation by highlighting and responding to this story.

Source: Deezer