Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functionality for removing tracks from playlists #72

Merged
merged 3 commits into from
Dec 7, 2023
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
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
Loading