Turning an old Apple TV into a Spotify player
In 2006, Apple unveiled the first-generation Apple TV. It was a set-top box for media consumption with hardware based on the Mac Mini. The small aluminium casing housed an Intel Pentium M, Nvidia Geforce Go, 40 or 160 GB internal HDD, integrated power supply, and a built-in Wi-Fi card. For connectivity, there was USB, Ethernet HDMI, composite, optical out and analog audio out through a high-quality DAC. Because of the tight coupling with iTunes and lack of software support the device isn’t very useful anymore and can be had for as little as €10 instead of the original €299.
For that low price point, it is amazing what you get from a hardware point of view. It’s a compact desktop computer with built-in Wi-Fi and high-quality audio components. And while the device is useless with the original software, thanks to the OSMC project it is fairly simple to turn it into a Linux box. Running a desktop environment on it is not advised due to the limited hardware, but it is perfectly fine for command-line applications.
So why not turn it into a standalone Spotify player? All the hardware we need is already present on the Apple TV, we just need to configure the software. By installing Linux and using the open-source spotifyd and spotify-tui we can turn the Apple TV into a standalone Spotify receiver and player.
1. Install Linux
The easiest method for installing Linux is to use OSMC. OSMC will install Debian 8 and Kodi Media Center on either a USB drive or the internal HDD. I prefer USB, so the original Apple TV software remains intact and usable. Download OSMC on a USB drive using the device installer provided on the website. Plug it in the Apple TV, hold down Menu and Volume Down on the remote while booting and let OSMC install itself. This is an unattended installation that may take a while. Afterwards, use the wizard to set up networking and make sure to enable SSH.
Disable Kodi Media Center
OSMC starts with Kodi Media Center by default. As we will not be using it, we can disable it. Use SSH to log on to the Apple TV remotely using the hostname, username and password osmc and run:
To make sure that we have a terminal after logging in, enable a getty with:
Reboot the Apple TV to verify that the media center does not start and that you can log on to the terminal from the Apple TV itself.
Update OSMC to get all the latest updates. Both OSMC for the Apple TV and Debian 8 are no longer supported but there are still some packages that can be upgraded after installation. Upgrading can take over an hour due to the limited hardware of the Apple TV.
The upgrade process will give a warning regarding the Nvidia driver but as we will not be using X that shouldn’t be a problem. Reboot after the update to ensure that everything is still operational.
You should now have a fully functional Debian 8 installation with a functioning terminal on the device and the ability to logon remotely through SSH.
2. Install Spotifyd
Spotifyd is an open-source daemon that can stream music from Spotify clients such as the Android, iOS, Windows and macOS apps. It shows up in Spotify as a Spotify Connect device and allows you to stream music to it. It works standalone and will continue playing the current playlist even after you close the Spotify app.
Unfortunately, because we run Debian 8, it is not possible to use modern package managers. We need to compile spotifyd ourselves. To prepare the system for this, we need the build-essential package and rustup:
Be sure to check the installation instructions for Rust as the command above might be outdated.
After installing Rust, we can compile spotifyd and all necessary packages with:
This can take up to four hours to finish.
Create a config file on ~/.config/spotifyd/spotifyd.conf:
I created a config file that should work in most cases but feel free to consult the configuration instructions for all options.
After compiling the spotifyd binary and putting the configuration in place, we can start the application with:
Verify that the Spotify app on your phone or computer now shows “AppleTV” available as a device for audio streaming. Connect to the device to verify playback. It should play audio through the red and white RCA jacks.
Exit the application with CTRL+C.
Create a self-starting spotifyd service
Now that spotifyd is configured, we can wrap it into a service that boots automatically as the device starts. Start by creating a symlink to spotifyd:
Continue by creating a file on ~/.config/systemd/user/spotifyd.service:
Enable the service and verify in Spotify that “AppleTV” is available for streaming:
As this is a user service, the service will only start after logging in. We can fix that by enabling lingering for the OSMC user:
This will start a user manager for this user on boot. Reboot to make sure that the spotifyd service starts on boot.
Your old and (formerly) useless Apple TV is now a Spotify receiver!
Put it in a nice place, attach speakers to the RCA jacks and enjoy.
But wait, there is more! We can now stream audio from the official Spotify apps on our phones and computers, but to be a truly standalone device, we need to install a Spotify client on the Apple TV. As running a full desktop and using the Spotify desktop client is too heavy for the limited hardware, we are going to use the terminal instead.
3. Install spotify-tui
Spotify TUI is a Spotify client for the terminal. We can either control it directly on the Apple TV or use SSH to control it remotely which makes it perfect for this use case.
As we already prepared the system for compiling Rust applications, we can easily compile it with:
This can take up to three hours to finish.
To configure spotify-tui, it is best to read the manual on connecting to the Spotify API. A small problem is that spotify-tui uses the browser to authenticate the client with Spotify. Copy the URL that is shown in the configuration wizard and paste it in a browser. After logging in it will redirect to a callback URL on localhost:8888 that is not reachable. Open a second console on the Apple TV (Ctrl+Alt+F2) or open a second SSH session. Run:
Spotify-tui should now be configured and running. Spotify-tui is only a client and can not play audio. Press D on the keyboard and select the spotifyd client to output audio to the daemon we set up earlier. Press ? on the keyboard to enter the help menu to familiarise yourself with the client.
To run spotify-tui on either the Apple TV directly or through an SSH session:
Wrapping it up
The formerly useless Apple TV can now be used as a Spotify streamer and player. By installing Linux, spotifyd and spotify-tui we were able to give meaning to what was essentially a paperweight. And with the low purchase price, built-in power supply, aluminium casing, high-quality DAC and optical audio output it easily tops a solution based on a Raspberry Pi or similar.
Pages that helped in the creation of this article:
- Starting and stopping Kodi
- Booting to command line
- Keeping your OSMC system up to date
- Installing Linux on the Apple TV 1st Generation
- Changing Wifi connection settings via terminal