A simple script to force shuffle Spotify playlists because Google Assistant running through Sonos can't do it.
I have a few Sonos speakers and use Google Assistant to control my smart home. I also have a few themed Spotify playlists that we like to listen to during dinner. However, it dinner only lasts so long and we end up listening to the same few song again and again.
Now the easy solution would be to open either the Spotify or Sonos apps and just click the shuffle button. However, I don't want to have my phone out during dinner.
My preferred solution would be to just ask Google Assistant to shuffle my playlists. Unfortunately, this is currently not possible. I can ask it to play a playlist, but it will always play the playlist in order. So I decided to write this script to permanently shuffle the playlists every time we get bored.
This script will authenticate with Spotify and then it will find the ID
s of the playlists you added to SPOTIFY_PLAYLIST
. It will then randomly shuffle the songs in each playlist and replace the existing playlist with the shuffled version.
- Have a Spotify Premium account
- Have
Go
installed locally - Create a Spotify app and get the
ID
andSecret
- Set the redirect URI to
http://localhost:8080/callback
- Set the redirect URI to
- Clone this repo
gh repo clone joekleinsorge/sonos-spotify-shuffle
- Create the following environment variables:
SPOTIFY_ID="<Your Spotify ID>"
SPOTIFY_SECRET="<Your Spotify Secret>"
SPOTIFY_PLAYLISTS="<Your Playlist names>,<Comma separated with no spaces>"
- Run
go run main.go
- When prompted, go to the URL and login to Spotify
- The script will then run and shuffle your playlists