An emacs helm interface for searching Spotify and controlling playback (on premium).
Of note, spot4e controls Spotify via the Spotify API, not dbus. This means you can control Spotify playback on whichever device Spotify is currently active. For example, you can control Spotify playback on your iPhone or Google Home if you wish. You do not have to have Spotify open on the computer running emacs.
This feature also means that spot4e should work as-is on most operating systems.
spot4e depends upon lisp packages json, url, and helm to function properly.
Also, this app is NOT a backdoor to Spotify. You need to have a premium account to use playback features!
This package is not yet on MELPA.
To install, simply download the spot4e.el file and install however you like.
For example, clone the project to whichever location you prefer, and add the directory to your load path. I recommend placing the following to your init file:
(add-to-list 'load-path "/path/to/spot4e")
Because spot4e controls a given user’s Spotify playback, it requires each user allow spot4e to access user data. Each user must authorize spot4e through Spotify’s Authorization Code Flow, so there is some setup required:
To credential the app, run the interactive function spot4e-authorize:
M-x spot4e-authorize
This will open a login page in your browser.
Log in (or click ok if you are already logged in). You will be redirected to Spotify’s home page, where the URL contains your authorization code:
https://www.spotify.com/us/?code=AUTH_CODE_HERE
Copy the this code and paste into the emacs minibuffer prompt “Enter code from URL” and press enter
This authorization process has given you a refresh token, stored in spot4e-refresh-token, which you will want to save for future sessions.
I recommend storing this token in your emacs config file:
(setq spot4e-refresh-token "REFRESH_TOKEN_HERE")
Note: you can get your refresh token by simply typing spot4e-refresh-token into any buffer, placing your cursor immediately after the variable, and pressing C-u C-x C-e. This evaluates the variable and prints the output at point.
This refresh token does not expire and will be good for future sessions. The access-token, however, does expire every hour, so I recommend refreshing it periodically with the spot4e-refresh function. I recommend adding the following to your config file as well:
(run-with-timer 0 (* 60 59) 'spot4e-refresh)
To reiterate from the summary, spot4e controls user’s Spotify playback through the Spotify API. You must have an active Spotify session for spot4e to trigger playback on the respective device.
You can control Spotify playback with the following.
spot4e-message-currently-playing | message current track in minibuffer |
spot4e-player-play | send play to Spotify playback |
spot4e-player-pause | send pause to Spotify playback |
spot4e-player-next | send next to Spotify playback |
spot4e-player-previous | send previous to Spotify playback |
To start searching for tracks:
M-x spot4e-search-tracks
and begin searching for tracks.
Of note, this interfaces with the tracks search endpoint which allows you to search for tracks by artist, album, and track name.
Once the items appear, you can go to next an previous with either the C-n and C-p commands, respectively or the <down> and <up> keys, respectively.
To play a track, simply press Enter. By default, the track plays in the context of the album in which it appears, otherwise playback stops after the song is finished.
To start searching for albums:
M-x spot4e-search-albums
and begin searching for albums
Navigate through tracks as usual and press enter to see album tracks. Press enter on an album track to play the track. You can navigate back to search-albums with <f2>.
To start searching for artists:
M-x spot4e-search-artists
and begin searching for artists
Navigate through artists as usual and press enter to see artist albums. Press enter on an artist album to see album tracks. You can navigate back to search-albums with <f2>.
Press enter on album-track to play the track.
To start the category browser:
M-x spot4e-helm-search-categories
And browse categories. Press enter on a category to see that category’s playlists. Press enter on a playlist to see a category’s tracks. Press enter on a track to play the track.
A crude model for this browse interface is:
category<–>playlist<–>track
Note you can ‘go back’, let’s say from playlists to category, by pressing <f2>. This makes browsing more natural - similar to what you might experience in the Spotify app.
To start the new releases browser:
M-x spot4e-helm-search-new-releases
And browse new releases. Note these are albums. Press enter on a new release to see the tracks (note most of these new releases will be singles, so there may only be one or two tracks). Press enter on a track to play the track. Go back to new releases with <f2>.
To start browsing featured playlists:
M-x spot4e-helm-search-featured-playlists
And browse featured playlists. Press enter on a playlist to view it’s tracks. Press enter on a track to play the track or <f2> to go back to playlists.
To start browsing user owned and followed playlists:
M-x spot4e-helm-search-user-playlists
And browse user followed playlists. Press enter on a playlist to view it’s tracks. Press enter on a track to play the track or <f2> to go back to playlists.
To start browsing user followed artists:
M-x spot4e-helm-search-user-artists
Navigate through artists as usual and press enter to see artist albums. Press enter on an artist album to see album tracks. You can navigate back to search-albums with <f2>.
Press enter on album-track to play the track.
To start browsing user saved tracks:
M-x spot4e-helm-search-user-tracks
and browse user-saved tracks.
Press enter on a track to play the track.
Assuming a track is playing, start the recommended track browser with:
M-x spot4e-helm-search-recommendations-track
And browse recommendations. Of note, if done repeatedly, the recommended track list varies slightly, as I imagine there is some randomization that occurs in Spotify’s recommendation engine.
Of note you can also get recommendations from the spot4e-helm-search-tracks interface by pressing <f2>. This way you can get recommendations based upon specific songs you have in
To save a track:
spot4e-save.
This will then appear in your saved tracks on Spotify (can access these with spot4e-helm-search-user-tracks). Note that you can also save tracks from the spot4e-helm-search-tracks interface with spot4e-save.
This package was primarily inspired by Kris Jenkins’s helm-spotify, with the main differences being support for authentication and control of playback on third-party devices.
Credit is also due to the developers of the Spotify API, whose excellent design made the development of this app straightforward.