Spotifyd delivers beautiful music without the bloat
Retro Charm
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
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.
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.
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).
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
.
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.
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.
Infos
- Spotify for Linux: https://www.spotify.com/de/download/linux
- "Redistribute Spotify on Linux Distributions": https://community.spotify.com/t5/Live-Ideas/Redistribute-Spotify-on-Linux-Distributions/idi-p/1695334#M188735
- Volumio: https://volumio.org
- Spotifyd: https://github.com/Spotifyd/spotifyd
- Rust: https://www.rust-lang.org
- Spotify Connect: https://www.spotify.com/connect
- spotify-tui: https://github.com/Rigellute/spotify-tui
- Rust Package Registry: https://crates.io
- Spotify Web API: https://developer.spotify.com/documentation/web-api
- Spotify for Developers Dashboard: https://developer.spotify.com/dashboard/applications
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
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.
News
-
Gnome Fans Everywhere Rejoice for the Latest Release
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.