8tracks on the Linux command line

Today it occurred to me that a Linux command-line player for 8Tracks.com would be good to have. I’m pretty slow on the uptake here, since 8tracks has been around since 2008, but better late than never.

I went looking for existing command line implementations, including but not limited to the following representative examples:

Orochi allows you to search through tags and titles for playlists, play files and search for users, as well as accessing social-web functionality such as ‘liking’ users and mixes. I would’ve simply stuck with Orochi, if it hadn’t been for the fact that the search functionality didn’t work for me. It’s based around version 2 of the API, whilst 8Tracks is up to version 3; it probably wouldn’t be too much hassle to adapt to version 3 in any case, but while a very cool solution I was looking for something much simpler.

A minimal downloader. It should be fairly obvious that the download-and-save functionality is against the developer API terms of service, but still this code is a very useful basis and mostly works. In fact, this code fails after the first few files are acccessed, throwing 403 (access denied) errors. The reason for this appears to be that you are expected to listen to the full track before moving on to the next track. If a call to ‘/sets/play-token/next?’ is made before the track is finished, or within a few seconds of it anyway, the API will refuse to give you access about the next track. You are allowed to skip files a couple of times per hour/per playlist, which explains why the first couple of files download successfully. This is probably a recent change, because various play scripts online suffer from this bug (as, currently, does youtube-dl’s 8tracks handler).

Fortunately, it’s easy to adapt this downloader into a functional audio player. You just need to tell the script to play the audio stream. A Raspberry Pi forum user has demonstrated this right here. The user has demonstrated calling mplayer via the command line; you might wonder whether in a Python program it wouldn’t be preferable to use gstreamer or pygame, but it turns out that pygame isn’t able to cope with some of the formats that 8tracks provides, and I found that I had little luck with gstreamer either. So mplayer it is.




Leave a Reply

Your email address will not be published. Required fields are marked *