19-05-2021

Raspbian is the dominant operating system on the Raspberry Pi, and for good reason – it makes the tiny Raspberry Pi feel like a full-sized computer, giving users access a web browser, utilities, and even games. But Raspbian doesn’t support every program out of the box, and Spotify fans will be disappointed to learn that their Raspberry Pi can’t play Spotify in the Chromium web browser that comes standard on Raspbian. Luckily, we can perform a few tweaks to make Spotify work on our Raspberry Pi and send music out over your choice of the HDMI connection or the headphone jack, which is perfect for feeding into your stereo system’s auxiliary input. Here’s how to listen to Spotify on the Raspberry Pi.

How to listen to Spotify on the Raspberry Pi

For this project, you’ll need a Raspberry Pi and all of the basic peripherals: a screen, a keyboard, a mouse, a power supply, and a microSD card. You’ll also need a computer with an SD card slot. If you want to use the headphone jack to listen to Spotify, you’ll need headphones or an aux cable.

We’ll be using Raspbian and the Chromium web browser in this project, but as we’ll see, that’s not enough to start Spotify. What we have to do is download a specific Chrome extension that will trick Spotify into thinking that we’re running Microsoft’s Internet Explorer. With the help of this little white lie, Spotify will work fine on Chromium.

With an always running Raspberry Pi a customized Spotify playlist playing. With the Powerful music server VOLUMIO and just a few add-ons it is very easy to set up and there is no need for knowledge on operating with linux. I will not show how to make the enclosure, because this is optimized to fit with the Speaker.

Step 1: Install Raspbian

First things first: this entire project takes place on Raspbian, so grab the disk image and put it on your microSD card. You can do this using the standard procedure for installing any operating system on the Raspberry Pi. Don’t remember that process? No problem – just check out our complete guide to installing Raspbian on the Raspberry Pi.

Once you have Raspbian installed, you’ll have a great operating system that you can use to perform basic computer functions (like word processing, web browsing, and more) or as the starting point to any of the nearly countless Pi projects that use Raspbian as their base. But one thing you won’t be able to do out of the box is use the included Chromium web browser to access Spotify’s web player. If you try, you’ll encounter a redirect or a screen that says: “Playback of protected content is not enabled.”

Bummer! Luckily for us, though, we have three more steps left in which to right this wrong. Let’s get started.

Step 2: Open Chromium and add the extension “User-Agent Switcher for Chrome”

Loyal readers will remember this extension from our guide to watching Netflix on the Raspberry Pi. We’re using it for the same purpose this time around: we’ll be tricking the website we want to use into thinking that we’re running one of their supported browsers, even though we’re not. This is a Chrome extension, but like many Chrome extensions, it works fine on the lighter-weight Chromium browser as well.

Step 3: Pretend to be using Internet Explorer 10

Now we just need to choose our new “user agent” before we try to access Spotify’s web player. Internet Explorer 10 will work, so let’s go ahead and do that: navigate to Internet Explorer > Internet Explorer 10 in User-Agent Switcher for Chrome’s settings.

Step 4: Listen to Spotify through your headphone jack or HDMI connection

If you’re content to use the headphone jack, we’re really already done here! Now that Spotify is blissfully unaware that we’re using the Chromium web browser, it will play nice with us. By default, this project will send the audio out of your Raspberry Pi’s headphone jack (rather than its HDMI port), which means you’ll have to plug in an auxiliary cord or some headphones to enjoy your tunes. This makes it perfect, though, for connecting to a larger stereo system!

Spotify On Raspberry Pi

Raspberry pi spotify jukeboxApp

If you want to use the HDMI connection instead, you just have one simple step left. In your terminal, run the command sudo raspi-config. This will give you a menu in your terminal window. Navigate to Advanced Options > A4 Audio > Choose the audio output: 2 Force HDMI. That’s it!

Spotify for the terminal written in Rust

Connecting to Spotify’s API

spotify-tui needs to connect to Spotify’s API in order to find music byname, play tracks etc.

Instructions on how to set this up will be shown when you first run the app.

But here they are again:

  1. Go to the Spotify dashboard https://developer.spotify.com/dashboard/applications
  2. Click Create a Client ID and create an app
  3. Now click Edit Settings
  4. Add http://localhost:8888/callback to the Redirect URIs - you don't need anything running on localhost, it will still work
  5. You are now ready to authenticate with Spotify!
  6. Go back to the terminal
  7. Run spt
  8. Enter your Client ID
  9. Enter your Client Secret
  10. You will be redirected to an official Spotify webpage to ask you for permissions.
  11. After accepting the permissions, you'll be redirected to localhost (blank webpage, might say something like 'Connection Refused' since no server is running), copy the URL and paste into the prompt in the terminal.

Raspberry Pi Spotify Client

And now you are ready to use the spotify-tui 🎉

You can edit the config at anytime at ${HOME}/snap/spt/current/.config/spotify-tui/client.yml.

Usage

The binary is named spt.

When running spotify-tui press ? to bring up a help menu that shows currently implemented key events and their actions.

Limitations

This app uses the Web API from Spotify, which doesn't handle streaming itself. So you'll need either an official Spotify client open or a lighter weight alternative such as spotifyd - https://github.com/Spotifyd/spotifyd

If you want to play tracks, Spotify requires that you have a Premium account.

Built with ♥️ from the Spotify TUI upstream source at https://github.com/Rigellute/spotify-tui