Announcements
The Spotify Stars Program: Celebrating Values Week!

Help Wizard

Step 1

NEXT STEP

How does Spotify decide the Chromecast background color?

How does Spotify decide the Chromecast background color?

 When streaming Spotify to a chromecast it sets a background color based on the album artwork on the screen the chromecast is connected to.

 

Does anyone have an idea what sort of logic they use to calculate this color?

I've tried to reverse engineer it, and with my algorithm I get the same color in about 80 % of the cases.

PS. It's not the most dominant color (more logic is used in the decision)

Reply
8 Replies

 Yeah, I noticed yesterday how the background changes depending on the artwork, somehow matching it pretty well. I was also wondering what's the algorithm behind it.

It's pretty cool your code matches 80% of the time. Could you share it? Maybe it's on GitHub?  (I have no commercial purposes :P)

Yes of course! I have it all here https://github.com/davidkrantz/Colorfy.

If you only are interested in this background color, see the spotify_background_color.py script for more details on how I do it.

Hey,

 

Nice work!

I was looking for this for a while now. 

 

Can spotify_background_color.py used by it self? Without the other scripts? Because I use an external system to control the RGB Led behind my TV. That system also retrieves the Spotify image and other information.

 

Thanks for sharing your code. 

- Jordo

 

 

Hi,

 

Thanks!

 

Yes, spotify_background_color.py can be used by itself. It has nothing to do with Spotify (which is why I probobly should change the name of it), and simply takes any image as input.

 

Cheers!

 

Hi,

 

Thanks for your fast reply. 

I am trying the code now wit a base64 image string. 

 

Is it "normal" that the processing is taking pretty long? Sometimes nearly a minute. 

 

- Jordo

 

Hi again,

 

Probably. It depends much on the size of the image and of number of distinct colors the K-means clustering is searching for (the k argument in the method best_color).

I am currently running this project on a Raspberry Pi 3 Model B+ with 100x100 pixel images, k=8 and the processing takes less than a second.

To resize the image you can simply put an additional input argument for the class as e.g. SpotifyBackgroundColor(img=image, image_processing_size=(100,100))

Hi both

 

First of all sorry for not answering to your previous reply. I was a busy over the last month :P. I noticed that the software expects a Raspberry Pi setting, but indeed some wrapper code can be written to use @dkrantz 's  spotify_background_color.py and run it on the PC with any artwork. In my tests it takes less than 10s. I will share my wrapper ASAP 🙂

Hi,

 

What part of the code in spotify_background_color.py do you mean requires a Raspberry Pi?

Suggested posts