Spotifyd delivers beautiful music without the bloat

Retro Charm

Article from Issue 233/2020
Author(s):

So you like to travel light and work at the command line? Why not access Spotify in the terminal and do without the official client?

Spotify has offered an official client for the Linux desktop for years [1]. Although no major functional differences exist between the versions for Windows, Mac OS X, and Linux, some in the FOSS community have criticized the Spotify desktop client – not just because it occupies more than 280MB on the hard disk, but also because of its license terms, which prohibit free distribution. The non-free license means that Spotify cannot be directly integrated into the package sources of the popular Linux distributions [2].

Some users who wish to avoid the Spotify client tune into the service via a web browser. The web browser must support the digital rights management (DRM) implemented in Spotify. However, the Linux environment does include some music players, such as Volumio, that support streaming of Spotify [3]. Especially in the Linux world, however, many users like their programs lean and don't consider a web interface much of an improvement over a desktop GUI. If you're a Linux user who would rather operate from the command line, you can still play your favorite tunes on Spotify. This article introduces you to some useful tools for playing Spotify in the terminal window.

Spotifyd

Spotifyd [4] is a lean Spotify client written in Rust [5]. The Spotifyd client requires access to the Spotify Connect service, which means you'll need a commercial premium Spotify account. If you only use the streaming service via an ad-funded account, you cannot use Spotifyd. In addition to running on Intel-based Linux systems, Spotifyd also runs on the ARM-based Raspberry Pi, which makes it easy to deploy an unobtrusive RaspPi as part of the streaming environment. Spotifyd uses only 3MB RAM. Because Spotifyd supports the Spotify Connect protocol, you can control it from other Spotify clients, which means you could connect the Spotifyd client system to your TV or stereo system, and then control it from another computer or Spotify device.

The developers are currently working very intensively on Spotifyd. Packages are only available for Arch Linux (spotifyd-full; see the "Installation on Arch Linux" box) and FreeBSD. Users of other distributions need to compile the program. Listing 1 shows the process for Ubuntu 19.04. Compiling takes a long time, especially on older computers. I recommend you choose option 2, which installs the compiled program to ~/.cargo/bin. To run Spotifyd, add the lines from Listing 2 to ~/.profile, restart the terminal program, and then run the spotifyd --version command to test.

Installation on Arch Linux

In the Arch User Repository (aka the AUR), the Arch Linux community maintains a collection of recipes from which a package for the Pacman package manager on an Arch system can be easily compiled using a helper program. Both Spotifyd and spotify-tui are already included in the AUR. If you work with the currently recommended AUR helper, Yay, you can install both programs at once with the command yay -S spotifyd-full spotify-tui.

Listing 1

Build in Ubuntu

 

Listing 2

Add to Path

 

The service is configured via the spotifyd.conf file in the ~/.config/spotifyd/ folder. Create the folder, and then create a file in it with the contents from Listing 3. The user name and password for Spotify Connect are available at the Spotify website [6] (Figure 1).

Listing 3

spotify.conf

 

Figure 1: In order for Spotifyd to access the streaming service, you need commercial premium access. A device username and password can then be created from the Spotify settings.

To test the configuration, call the spotifyd --no-daemon command. The command starts the service and should only print INFO lines. Afterwards you can stop Spotifyd by pressing Ctrl+C. After a successful test, it is best to start the service via systemd. Later on, you can use systemd to configure Spotifyd to automatically start and shutdown when you boot and power down your computer (Listing 4).

Listing 4

With systemd

 

If you have installed Spotifyd on a small headless computer like the Raspberry Pi that is connected to a stereo system, you can use the official Spotify app from a smartphone or PC to redirect playback to the Spotifyd-equipped computer using the icon to the left of the volume control and the Spotifyd@<computer_name> menu item (Figure 2). You can also use this approach with Spotify-compatible network speakers, such as the Sonos system.

Figure 2: Spotifyd can also be controlled from the official Spotify application. In the list of devices connected with Spotify Connect, it appears as Spotifyd@<computer_name>.

The spotify-tui command-line tool [7] can act as an interface for the Spotifyd client. spotify-tui serves as the music center, with Spotifyd handling the playback. Like Spotifyd, spotify-tui was developed in Rust. Listing 5 shows to install spotify-tui in Ubuntu using the Rust package manager cargo [8].

Listing 5

Installing with cargo

 

Before the program can talk to the streaming service via the Spotify Web API [9], you have to go through the configuration, which involves more than just entering an account. To access the API, you need to register as a developer [10] and create an "app" – don't worry, you don't have to do any programming. All you have to do is click on CREATE A CLIENT ID and enter some basic information (Figure 3). In the next step, click NO to promise that you have no commercial intentions and finally accept the terms of use.

Figure 3: To access the Spotify Web API, you need a developer account and your own Spotify app for spotify-tui. Don't worry: You don't have to program anything; a few mouse clicks are all it takes.

Then select the newly created Spotify app from the Dashboard with a left click and open the settings via EDIT SETTINGS. Now enter the address http://localhost:8888/callback as the last administrative task in Redirect URIs. Write down the Client ID, and – after a click on SHOW CLIENT SECRET – the corresponding secret password for the client (Figure 4).

Figure 4: From the Spotify dashboard you need to transfer the Client ID and the Client Secret to set up spotify-tui. Do not forget to adjust the Redirect URIs under EDIT SETTINGS.

Armed with this information, you can now start spotify-tui with the spt command. The program wants to know the Client ID you just created, along with the appropriate Client Secret (Figure 5). After that, the procedure gets a bit confusing: The program tries to open an extremely cryptic and long URL of the type http://localhost:8888/callback?code=AQtpdjW, which throws an error, because you do not usually have a web server running on your own system. Ignore the error message and simply copy and paste the address of the page from the browser into the setup of spotify-tui.

Figure 5: When first launched, spotify-tui wants to know the Client ID and the Client Secret. The resulting URL tries to open the setup in a browser. In the last step, you transfer this address to the terminal window.

In the first dialog after the setup, the program searches for Spotify Connect devices on the local network, including all smartphones and PCs running the Spotify app. Spotifyd should appear in the list of Devices as Spotifyd@computer_ name. Select this entry using the arrow keys and press Enter. If necessary, enlarge the terminal window, otherwise texts and elements often do not appear on the screen (see the box entitled "Tips"). spotify-tui then opens the actual application window, in which you will find a search bar at the top and sidebars with your Spotify library and playlists on the left (Figure 6).

Tips

spotify-tui tries to transfer the Responsive Design concept used with websites into the terminal. Depending on the size of the terminal window, the program shows and hides elements of the text interface and removes explanatory text. In practice, however, this approach proves to be tricky. For example, in a standard terminal with an 80 characters width and 24 lines height, the explanatory text is already completely missing in the first screen in which you need to select the Spotify device. Ideally, you should therefore work with a terminal maximized to the full size of the screen, especially at the beginning. Also when choosing the colors, you have to adapt a little to the preferences of the spotify-tui developers. The application uses hard-coded colors that only work well on a terminal with light text on a dark background.

Figure 6: spotify-tui serves as the music center, but Spotifyd is responsible for the playback. You can exit the program without the music playback stopping.

In spotify-tui, you can use the arrow keys to navigate through the individual elements of the interface. The program always color-highlights the current selection. To open the element currently highlighted, press Enter. Press Esc to go back one level. Much like text tools such as Less, you start a search in the Spotify library by entering /search term. spotify-tui then immediately displays the matches in the tracks, artists, albums, and playlists in the central section of the application. You can get help by entering a question mark.

As soon as you play a song, another box appears at the bottom with information about the song currently playing and a progress bar. The space bar can be used to pause and resume playback, but it is not possible to jump to a specific point in the song. Playback so far only offers a random mode, which you can activate with Ctrl+S. If necessary, press D to return to the Spotify device selection – this way you can use spotify-tui to control multiple devices at once. Press Q to exit the application. Since the playback relies on Spotifyd, the currently active playlist continues to play.

Conclusions

You don't necessarily have to use the duo of Spotifyd and spotify-tui together. For example, you can install Spotifyd on a Raspberry Pi that you have connected to a stereo system, and then control the music through the official Spotify application or, if necessary, through spotify-tui on another computer. Alternatively, control the music playback from the terminal using the official Spotify app.

On systems that are not completely under your control, it is a good idea to enter the access data for Spotify in plain text in the configuration. The GitHub page for Spotifyd describes how to store the account information in a secure keyring. Otherwise Spotifyd and spotify-tui leave plenty of scope for your own experiments. Both programs are backed by active developer communities that react quickly to bug reports and suggestions for improvement.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Waxing Lyrical

    Whether you listen to music on Spotify or a classic audio player like Rhythmbox, Lollypop, or Audacious, a tool named Lyrics-in-terminal will let you read the lyrics for the track you are currently playing.

  • Perl: Spotify

    For a monthly fee, the Spotify streaming service beams music onto your desktop or phone. To intensify the groove, Perlmeister Mike Schilli archived his Spotify playlists for eternity using an OAuth-protected web API.

  • File Inspector

    Spotify, the Internet music service, collects data about its users and their taste in music. Mike Schilli requested a copy of his files to investigate them with Go.

  • FOSSPicks

    This month Graham looks at SonoBus, NewsFlash, Kinto.sh, RetroShare, Emilia Pinball, and much more!

  • FOSSPicks

    Graham recently found the perfect use for his old Nintendo DS Lite. Thanks to having exactly the same screen resolution, it now runs the brilliant ZXDS Sinclair ZX Spectrum emulator.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News