For Neovim users who want to have music at their fingertips.
spotipy.nvim is a plugin that allows you to control your Spotify account from within Neovim.
-
Display/Filter the search results with Telescope
-
Currently playing statusline.
-
Currently playing notification.
-
Toggle track status
-
Skip a track
-
Add a track to queue
-
Select which device to play on
-
Search by tracks
spotipy.nvim is a python based plugin, using the spotipy library to interact with the Spotify API.
As spotipy.nvim only handles the interaction with the Spotify API, you will need a Spotify Premium account to use this plugin.
As Spotify API does not handle the playback of the music, you will need to have the Spotify app running in the background.
The spotipy.nvim plugin was tested using on linux and mac using the full version of the Spotify app, it may not work with spotifyd.
-- Lua
use {
"AvivKehrmann/spotipy.nvim",
requires = 'nvim-telescope/telescope.nvim',
config = function()
local spotipy = require("spotipy.nvim")
spotipy.setup({
status = {
update_interval = 10000}
})
end
}return {
{
"AvivKehrmann/spotipy.nvim",
requires = "nvim-telescope/telescope.nvim",
config = function()
local spotipy = require("spotipy.nvim")
spotipy.setup({
status = {
update_interval = 10000}
})
end
}
}Decreasing the update_interval value means more API calls in a shorter period. Because of the Spotify API rate limiter, setting this too low can block future requests.
Besides that, keep in mind these updates are api calls, they will slow your computer down.
Generally, i use 5000ms as the update interval, and experience no issues.
spotipy.nvim needs to connect to Spotify’s API in order to find music by
name, play tracks etc.
In order to do so please follow these steps:
- Go to the Spotify dashboard.
- Click
Create an app.- You now can see your
Client IDandClient Secret.
- You now can see your
- Now click
Edit Settings. - Add
http://localhost:8888/callback(if the spacific port is taken choose any port you'd like) to the Redirect URIs. - Scroll down and click
Save. - You are now ready to authenticate with Spotify!.
- Go back to the terminal.
- Add the Client Id, Client Secret, and Redirect URI to your environment variables, by adding the following lines to your
.bashrcor.zshrc:export SPOTIPY_CLIENT_ID='YOUR_CLIENT_ID' export SPOTIPY_CLIENT_SECRET='YOUR_CLIENT_SECRET' export SPOTIPY_REDIRECT_URI='http://localhost:'YOUR_PORT'/callback'
- Use the
sourcecommand to apply the changes:source ~/.bashrc # or source ~/.zshrc
- Use the
SpotifyDevicescommand to connect to your Spotify account. - A browser window will open, asking you to log in to your Spotify account.
- After logging in, you will be redirected to a page that says
Authentication complete. You can close this tab. - Now you are connected to the Spotify API and can use the
spotipy.nvimplugin.
And now you are ready to use the spotipy.nvim
spotipy.nvim has several commands:
Add a track to the queue (plays it next) by specifying a track URI.
:SpotifyAdd <track_uri>Open a menu of the devices connected to your Spotify account and select which one to play on.
:SpotifyDevicesPlay a track by providing its URI.
:SpotifyPlay <track_uri>Control the playback with options to skip or go back a track.
:SpotifyPlayback -n/next # Skip to the next track
:SpotifyPlayback -p/prev # Go back to the previous trackShow the next 20 tracks in the queue.
:SpotifyPlaylistSearch for a track by providing its name and display the top 20 results.
:SpotifySearch <track_name>Uses the vim.notify API to display the current Spotify status, including track name, album name, artist name, and duration. If no track is playing, an appropriate message will be shown.
Recommented usage with nvim.notify plugin.
:SpotifyStatusToggle the current playback on or off based on the current state.
:SpotifyToggleThe following keymaps are set by default, notice they all need to be prefixed with youre leader key.:
| mode | key | Description |
|---|---|---|
| normal | ms | search for tracks |
| normal | mt | toggle playback |
| normal | ml | show Playlist |
| normal | mn | skip track |
| normal | mp | go back to the previous track |
| normal | md | show devices |
| normal | mm | show current status |
The default keymaps are set during the spotipy.nvim setup function.
Make sure to call the setup function before setting your own keymaps.
You can override the default keymaps by settings your own in the following way:
vim.api.nvim_set_keymap("n", "<leader>mt", ":SpotifyToggle<CR>", { noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "<leader>ml", ":SpotifyPlaylist<CR>", { noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "<leader>mn", ":SpotifyPlayback -n<CR>", { noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "<leader>mp", ":SpotifyPlayback -p<CR>", { noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "<leader>mm", ":SpotifyStatus<CR>", { noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "<leader>md", ":SpotifyDevices<CR>", { noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "<leader>ms", ":lua require('neovim-spotify').search()<CR>", { noremap = true, silent = true })You can display what's currently playing on your status bar.
The example below shows how to show it on lualine,
although the configuration should be quite similar on other statusline plugins:
local status = require"spotipy.nvim".status
status:start()
require('lualine').setup {
sections = {
lualine_x = {
status.listen
}
}
}You can display the current status and many other notifications using the nvim.notify plugin.
use {
'rcarriga/nvim-notify',
config = function()
vim.notify = require("notify")
end
}
