Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

on:
push:
branches: [main]
pull_request:

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: rhysd/action-setup-vim@v1
with:
version: stable
neovim: true

- name: Install test dependencies
run: |
git clone --depth=1 https://github.com/nvim-lua/plenary.nvim /tmp/plenary.nvim
git clone --depth=1 https://github.com/nvim-telescope/telescope.nvim /tmp/telescope.nvim

- name: Run smoke tests
run: |
nvim --headless -u NONE \
--cmd "set runtimepath^=/tmp/plenary.nvim" \
--cmd "set runtimepath^=/tmp/telescope.nvim" \
--cmd "set runtimepath^=$GITHUB_WORKSPACE" \
--cmd "runtime plugin/jam.lua" \
-c "luafile tests/smoke.lua" \
-c "quit"
nvim --headless -u NONE \
--cmd "set runtimepath^=$GITHUB_WORKSPACE" \
-c "luafile tests/oauth.lua" \
-c "quit"

- uses: JohnnyMorganz/stylua-action@v4
with:
version: latest
args: --check .
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
doc/tags
.luarc.json
212 changes: 212 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,213 @@
# jam.nvim

Search Spotify and control playback from a Telescope picker without leaving Neovim.

> [!NOTE]
> jam.nvim is an early preview. Spotify is the first provider; its provider-neutral
> core is designed for future Apple Music and YouTube Music adapters.

## Features

- Live, debounced Spotify search for tracks, albums, artists, and playlists
- Play, pause, skip, go back, and add tracks to the queue
- OAuth Authorization Code flow with PKCE—no client secret in your config
- Album-art previews through `image.nvim` or `chafa`, with automatic detection
- `:Jam` and `:Telescope jam` entry points
- Health diagnostics with `:checkhealth jam`

## Requirements

Required:

- Neovim 0.10+
- [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim)
- `curl` for Spotify API requests
- `openssl` for PKCE authentication
- A Spotify account and application client ID
- Spotify Premium and an active Spotify Connect device for playback control

Run `:checkhealth jam` after installation to verify these dependencies and your
configuration.

### Album artwork dependencies

Album artwork requires an optional renderer. Without one, the preview shows the
image URL as text.

- Install [`chafa`](https://hpjansson.org/chafa/) for a portable symbol preview
(`brew install chafa` on macOS or `sudo apt install chafa` on Debian/Ubuntu).
- Or install [image.nvim](https://github.com/3rd/image.nvim) and use a compatible
terminal such as Kitty or WezTerm.

`chafa` is the simplest cross-terminal option. Run `:checkhealth jam` to see
which artwork backend jam.nvim detected.

## Installation

### lazy.nvim

```lua
{
"bautistaaa/jam.nvim",
dependencies = {
"nvim-telescope/telescope.nvim",
-- Optional, for high-resolution artwork:
-- { "3rd/image.nvim", opts = {} },
},
cmd = { "Jam" },
opts = {
providers = {
spotify = {
client_id = vim.env.SPOTIFY_CLIENT_ID,
},
},
},
}
```

### Native `vim.pack`

```lua
vim.pack.add({
"https://github.com/nvim-telescope/telescope.nvim",
"https://github.com/bautistaaa/jam.nvim",
})

require("jam").setup({
providers = {
spotify = { client_id = vim.env.SPOTIFY_CLIENT_ID },
},
})
```

### mini.deps

```lua
local add = MiniDeps.add
add({ source = "nvim-telescope/telescope.nvim" })
add({ source = "bautistaaa/jam.nvim" })
```

### packer.nvim

```lua
use({
"bautistaaa/jam.nvim",
requires = { "nvim-telescope/telescope.nvim" },
config = function()
require("jam").setup({
providers = {
spotify = { client_id = vim.env.SPOTIFY_CLIENT_ID },
},
})
end,
})
```

### vim-plug

```vim
Plug 'nvim-telescope/telescope.nvim'
Plug 'bautistaaa/jam.nvim'
```

Then call `require("jam").setup(...)` from your Lua config.

## Spotify setup

1. Create an application in the [Spotify Developer Dashboard](https://developer.spotify.com/dashboard).
2. Add `http://127.0.0.1:8765/callback` as an exact redirect URI.
3. Put the application's client ID in your shell environment:

```sh
export SPOTIFY_CLIENT_ID="your-client-id"
```

Add that line to `~/.zshrc`, `~/.bashrc`, or the equivalent for your shell,
then start Neovim from a new terminal. A client secret is not needed and
should not be added to your configuration.
4. Install jam.nvim using one of the plugin-manager examples above.
5. Run `:checkhealth jam` and resolve any reported errors.
6. Run `:Jam auth spotify` and finish authorization in the browser.
7. Open Spotify and play something once so Spotify Connect marks the selected
device as active.
8. Run `:Jam`, enter a search, and press `<CR>` to play a result.

Tokens are stored with `0600` permissions under Neovim's data directory. Run
`:Jam logout` to remove them.

### Troubleshooting

- **`Device not found`**: Open Spotify, select a playback device, and manually
play a track once before retrying. Having the app open is not enough for the
Web API to consider the device active.
- **Artwork URL instead of an image**: Install `chafa`, or configure `image.nvim`
in a compatible terminal, then reopen the picker.
- **Client ID is not configured**: Confirm `:echo $SPOTIFY_CLIENT_ID` prints your
client ID. Restart Neovim from a new terminal after changing your shell
configuration.
- **OAuth redirect errors**: Confirm the redirect URI in Spotify is exactly
`http://127.0.0.1:8765/callback`.

## Usage

```vim
:Jam " Open search
:Jam search " Open search
:Jam auth spotify " Connect Spotify
:Jam pause
:Jam next
:Jam previous
:Jam now-playing
:Jam logout
:Jam health
:Telescope jam
```

Picker mappings:

| Mapping | Action |
| --- | --- |
| `<CR>` | Play selection |
| `<C-q>` | Add selection to queue |
| `<C-p>` | Pause playback |

## Configuration

```lua
require("jam").setup({
provider = "spotify",
search = {
debounce_ms = 250,
limit = 30,
types = { "track", "album", "artist", "playlist" },
},
artwork = {
enabled = true,
backend = "auto", -- auto, image, chafa, text, or none
width = 38,
height = 16,
cache = true,
},
picker = {
layout_strategy = "flex",
},
providers = {
spotify = {
client_id = vim.env.SPOTIFY_CLIENT_ID,
redirect_uri = "http://127.0.0.1:8765/callback",
},
},
})
```

## Provider design

Provider adapters declare capabilities and implement the common search and
playback interface. The Telescope UI does not call Spotify-specific endpoints,
so additional providers can expose only the capabilities their APIs support.

Apple Music and YouTube Music are not implemented yet. YouTube Music does not
offer an official public playback-control API, so that adapter will require a
carefully documented fallback rather than pretending all providers have equal
capabilities.
82 changes: 82 additions & 0 deletions doc/jam.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
*jam.txt* Search and control music from Neovim

==============================================================================
CONTENTS *jam-contents*

1. Introduction ................................................. |jam-intro|
2. Setup ........................................................ |jam-setup|
3. Commands ................................................... |jam-commands|
4. Artwork ..................................................... |jam-artwork|

==============================================================================
1. INTRODUCTION *jam-intro*

jam.nvim provides a Telescope interface for music search and playback. Spotify
is currently the only provider.

Requirements:
- Neovim 0.10 or newer
- telescope.nvim
- curl
- openssl
- Spotify Premium and an active Spotify Connect device for playback control

Album artwork additionally requires chafa, or image.nvim in a compatible
terminal. Without either renderer, the preview displays the artwork URL.

==============================================================================
2. SETUP *jam-setup*

Create an application in Spotify's developer dashboard and register this exact
redirect URI:

http://127.0.0.1:8765/callback

Then configure jam.nvim:
>
require("jam").setup({
providers = {
spotify = {
client_id = vim.env.SPOTIFY_CLIENT_ID,
},
},
})
<
Run `:checkhealth jam`, then `:Jam auth spotify` to connect your account. Open
Spotify and play something once before using playback controls; merely opening
the app may not make it an active Spotify Connect device.

==============================================================================
3. COMMANDS *jam-commands*

*:Jam*
:Jam Open the search picker.
:Jam search Open the search picker.
:Jam auth spotify Authenticate with Spotify.
:Jam logout Remove stored Spotify credentials.
:Jam pause Pause playback.
:Jam next Skip to the next item.
:Jam previous Return to the previous item.
:Jam now-playing Display the current track.
:Jam health Run health diagnostics.

The picker maps <CR> to play, CTRL-Q to queue, and CTRL-P to pause.

The picker can also be opened after loading the Telescope extension:
>
require("telescope").load_extension("jam")
:Telescope jam
<
==============================================================================
4. ARTWORK *jam-artwork*

With `backend = "auto"`, jam.nvim selects:

1. image.nvim in a detected compatible terminal
2. chafa when its executable is available
3. text metadata

Detection is best effort. Set `artwork.backend` to "image", "chafa", "text", or
"none" to override it. Run `:checkhealth jam` to inspect the selected backend.

vim:tw=78:ts=8:noet:ft=help:norl:
Loading
Loading