This is a Firebase Cloud Function that extracts the main color from the track currently being played on Spotify.
- Create a new project on https://developer.spotify.com/
- Create a new project on http://console.firebase.google.com/
- Clone this repository
- Run
firebase init
to associate the directory into your Firebase project - Copy the
.env.example
file into a new.env
file and replace the placeholder values with information from your Spotify project
To use the function, simply make a POST request to the endpoint with the desired
parameters. Be sure to set the secret_key
in the request headers (the same
secret key from your .env
file).
The function accepts two optional parameters in the request body: from
and
colors
.
The from parameter allows you to select the algorithm for the color selection. You can specify one of the following values:
- album: this is the default option, it extracts the dark proeminent color from the track album image
- lyrics: determines a color based on feeling analysis from the track lyrics, falling back to album color if no lyrics are found for the track
The colors parameter allows you to restrict the response to a set of colors. The
response will be the color from the array which is closest to the track color.
It must be specified as an array of hexadecimal color codes (e.g. #ff0000
).
{
"from": "album",
"colors": ["#ff0000", "#00ff00", "#0000ff"]
}
The function will return a JSON object with the color property, as in the example below:
{
"color": "#0000ff"
}