Skip to content

Commit

Permalink
Functionality for removing tracks from playlists (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
fdeitylink authored Dec 7, 2023
1 parent 5f4cf01 commit b408e18
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ bindings in the resulting buffer:
| Key | Description |
|:-----------------|:--------------------------------------------------------------------|
| <kbd>a</kbd> | Adds track to a playlist |
| <kbd>r</kbd> | Removes track from current playlist
| <kbd>l</kbd> | Loads the next page of results (pagination) |
| <kbd>g</kbd> | Clears the results and reloads the first page of results |
| <kbd>f</kbd> | Follows the current playlist |
Expand Down
17 changes: 17 additions & 0 deletions smudge-api.el
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,23 @@ Call CALLBACK with results."
(format "{\"uris\": [ %s ]}" tracks)
callback)))

(defun smudge-api-playlist-remove-track (playlist-id track-id callback)
"Remove TRACK-ID from PLAYLIST-ID.
Removed by USER-ID. Call CALLBACK with results."
(smudge-api-playlist-remove-tracks playlist-id (list track-id) callback))

(defun smudge-api-playlist-remove-tracks (playlist-id track-ids callback)
"Remove TRACK-IDs from PLAYLIST-ID for USER-ID.
Call CALLBACK with results."
(let ((tracks (format "%s" (mapconcat
(lambda (x) (format "{\"uri\": %s}" (smudge-api-format-id "track" x)))
track-ids ","))))
(smudge-api-call-async
"DELETE"
(format "/playlists/%s/tracks" (url-hexify-string playlist-id))
(format "{\"tracks\": [ %s ]}" tracks)
callback)))

(defun smudge-api-playlist-follow (playlist callback)
"Add the current user as a follower of PLAYLIST.
Call CALLBACK with results."
Expand Down
14 changes: 14 additions & 0 deletions smudge-track.el
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
(set-keymap-parent map tabulated-list-mode-map)
(define-key map (kbd "M-RET") #'smudge-track-select)
(define-key map (kbd "a") #'smudge-track-add)
(define-key map (kbd "r") #'smudge-track-remove)
(define-key map (kbd "l") #'smudge-track-load-more)
(define-key map (kbd "g") #'smudge-track-reload)
(define-key map (kbd "f") #'smudge-track-playlist-follow)
Expand Down Expand Up @@ -286,6 +287,19 @@ Default to sortin tracks by number when listing the tracks from an album."
(lambda (_)
(message "Song added.")))))))))

(defun smudge-track-remove ()
"Remove the track under the cursor from the selected playlist."
(interactive)
(if (bound-and-true-p smudge-selected-playlist)
(let ((playlist (smudge-api-get-item-id smudge-selected-playlist))
(selected-track (tabulated-list-get-id)))
(smudge-api-playlist-remove-track
playlist
(smudge-api-get-item-uri selected-track)
(lambda (_)
(message "Song removed."))))
(message "Cannot remove a track from a playlist from here")))

(defun smudge-track-add-to-queue ()
"Add the track under the cursor to the queue."
(interactive)
Expand Down

0 comments on commit b408e18

Please sign in to comment.