How does Spotify decide the Chromecast background color?

Reply
Highlighted

How does Spotify decide the Chromecast background color?

dkrantz
Regular

 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)

8 Replies

Re: How does Spotify decide the Chromecast background color?

antortjim
Casual Listener

 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)

Re: How does Spotify decide the Chromecast background color?

dkrantz
Regular

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.

Re: How does Spotify decide the Chromecast background color?

Jord_o
Casual Listener

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

 

 

Re: How does Spotify decide the Chromecast background color?

dkrantz
Regular

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!

 

Re: How does Spotify decide the Chromecast background color?

Jord_o
Casual Listener

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

 

Re: How does Spotify decide the Chromecast background color?

dkrantz
Regular

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))

Re: How does Spotify decide the Chromecast background color?

antortjim
Casual Listener

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 :)

Re: How does Spotify decide the Chromecast background color?

dkrantz
Regular

Hi,

 

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

SUGGESTED POSTS