Skip to content
Open
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
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ which artwork backend jam.nvim detected.
-- Optional, for high-resolution artwork:
-- { "3rd/image.nvim", opts = {} },
},
cmd = { "Jam" },
opts = {
providers = {
spotify = {
Expand Down Expand Up @@ -206,7 +205,7 @@ Picker mappings:
| --- | --- |
| `<CR>` | Open a collection or play the selected track/episode |
| `<C-q>` | Add selection to queue |
| `<C-p>` | Pause playback |
| `<M-p>` | Pause playback |
| `<Esc>` | Return from a collection to the original search |

Selecting an album opens its tracks in disc and track order. Selecting an artist
Expand Down
2 changes: 1 addition & 1 deletion doc/jam.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ their items when Spotify allows browsing them. Spotify Development Mode only
exposes playlist contents for playlists you own or collaborate on; other
playlists play immediately instead. In a collection picker, <CR> plays the
selected item and <Esc> returns to the original search. CTRL-Q queues the
selected item and CTRL-P pauses playback.
selected item and ALT-P pauses playback.

The picker can also be opened after loading the Telescope extension:
>
Expand Down
62 changes: 38 additions & 24 deletions lua/jam/providers/spotify.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ local function subtitle(item, kind)
end

local function normalize(item, kind)
if not item or item == vim.NIL or type(item) ~= "table" then
return nil
end
local album = item.album
return {
id = item.id,
Expand Down Expand Up @@ -152,13 +155,16 @@ function Spotify:search(query, options, callback)
for _, kind in ipairs(types) do
local bucket = {}
local group = response[plural[kind]]
if type(group) == "table" then
for _, item in ipairs(group.items or {}) do
if item then
table.insert(bucket, normalize(item, kind))
if type(group) == "table" then
for _, item in ipairs(group.items or {}) do
if item and item ~= vim.NIL and type(item) == "table" then
local normalized = normalize(item, kind)
if normalized then
table.insert(bucket, normalized)
end
end
end
end
end
table.insert(buckets, bucket)
if #bucket > max_count then
max_count = #bucket
Expand Down Expand Up @@ -190,11 +196,13 @@ function Spotify:album_tracks(album, callback)
return
end
for _, item in ipairs((response or {}).items or {}) do
if item then
if item and item ~= vim.NIL and type(item) == "table" then
local track = normalize(item, "track")
track.album = album.name
track.image_url = album.image_url
table.insert(tracks, track)
if track then
track.album = album.name
track.image_url = album.image_url
table.insert(tracks, track)
end
end
end
if response and type(response.next) == "string" and response.next ~= "" then
Expand Down Expand Up @@ -223,10 +231,12 @@ function Spotify:artist_top_tracks(artist, callback)
end
local tracks = {}
for index, item in ipairs((response or {}).tracks or {}) do
if item then
if item and item ~= vim.NIL and type(item) == "table" then
local track = normalize(item, "track")
track.list_position = index
table.insert(tracks, track)
if track then
track.list_position = index
table.insert(tracks, track)
end
end
end
callback(nil, tracks)
Expand All @@ -247,14 +257,16 @@ function Spotify:show_episodes(show, callback)
return
end
for _, item in ipairs((response or {}).items or {}) do
if item then
if item and item ~= vim.NIL and type(item) == "table" then
local episode = normalize(item, "episode")
episode.subtitle = show.name
episode.podcast = show.name
episode.publisher = show.publisher
episode.image_url = episode.image_url or show.image_url
episode.list_position = #episodes + 1
table.insert(episodes, episode)
if episode then
episode.subtitle = show.name
episode.podcast = show.name
episode.publisher = show.publisher
episode.image_url = episode.image_url or show.image_url
episode.list_position = #episodes + 1
table.insert(episodes, episode)
end
end
end
if response and type(response.next) == "string" and response.next ~= "" then
Expand Down Expand Up @@ -283,12 +295,14 @@ function Spotify:playlist_items(playlist, callback)
end
for _, row in ipairs((response or {}).items or {}) do
local media = row and (row.item or row.track)
if media then
if media and media ~= vim.NIL and type(media) == "table" then
local kind = media.type == "episode" and "episode" or "track"
local entry = normalize(media, kind)
entry.list_position = #entries + 1
entry.image_url = entry.image_url or playlist.image_url
table.insert(entries, entry)
if entry then
entry.list_position = #entries + 1
entry.image_url = entry.image_url or playlist.image_url
table.insert(entries, entry)
end
end
end
if response and type(response.next) == "string" and response.next ~= "" then
Expand Down Expand Up @@ -397,7 +411,7 @@ end

function Spotify:now_playing(callback)
self:_request({ url = API_URL .. "/me/player/currently-playing" }, function(err, response)
if err or not response or not response.item then
if err or not response or not response.item or response.item == vim.NIL then
callback(err, nil)
return
end
Expand Down
8 changes: 4 additions & 4 deletions lua/jam/ui/picker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ local function open_items(provider, config, title, results_title, items, search_
map("n", "<Esc>", back_to_search)
map("i", "<C-q>", queue)
map("n", "<C-q>", queue)
map("i", "<C-p>", pause)
map("n", "<C-p>", pause)
map("i", "<M-p>", pause)
map("n", "<M-p>", pause)
return true
end,
})
Expand Down Expand Up @@ -557,8 +557,8 @@ function M.open(provider, config, opts)
end
map("i", "<C-q>", queue)
map("n", "<C-q>", queue)
map("i", "<C-p>", pause)
map("n", "<C-p>", pause)
map("i", "<M-p>", pause)
map("n", "<M-p>", pause)
return true
end,
})
Expand Down