From c9218804220c496d0c841eecaa0c8b6a92146880 Mon Sep 17 00:00:00 2001 From: jao Date: Mon, 11 Jan 2021 01:14:36 +0000 Subject: more consult functions, new jao-embark, eos --- media/espotify.org | 58 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 21 deletions(-) (limited to 'media') diff --git a/media/espotify.org b/media/espotify.org index 6c07259..5cc0fee 100644 --- a/media/espotify.org +++ b/media/espotify.org @@ -11,10 +11,6 @@ track or album identifier that we can send then to the latter to play, with emacs completion mechanisms (consult and friends in this case) providing the glue between both worlds. -Note: you can access this post as an ~org~ file in my [[https://codeberg.org/jao/elibs/src/branch/main/media/espotify.org][jao/elibs -repository]], and transform it to an emacs-lisp file with ~M-x -org-babel-tangle~. - Let's start with an umbrella customization group: #+begin_src emacs-lisp ;;; espotify.el - spotify search and play - -*- lexical-binding: t; -*- @@ -197,6 +193,19 @@ Let's start with an umbrella customization group: | album_type | artists | available_markets | external_urls | href | id | images | name | release_date | release_date_precision | total_tracks | type | uri | | external_urls | followers | genres | href | id | images | name | popularity | type | uri | | | | + Another strategy would be to search for several types and pass to + our callback the concatenation of all items: + + #+begin_src emacs-lisp + (defun espotify-search-all (callback term &optional types filter) + (let ((types (or types '(album track artist playlist)))) + (espotify-search* (lambda (&rest items) + (funcall callback (apply append items))) + term + types + filter))) + #+end_src + * Sending commands to local players Once we now the URI we want to play (that ~uri~ entry in our items), @@ -283,7 +292,7 @@ Let's start with an umbrella customization group: ((or 'setup 'refresh) (funcall next action)) ('destroy (setq candidates nil) (funcall next 'destroy)) ((pred stringp) - (espotify-search* + (espotify-search-all (lambda (x) (setq candidates (mapcar 'espotify--format-item x)) (funcall next candidates)) @@ -339,6 +348,26 @@ Let's start with an umbrella customization group: (espotify--maybe-play (consult-spotify-by 'album filter))) #+end_src + And likewise for playlists, artists and combinations thereof: + + #+begin_src emacs-lisp + (defun consult-spotify-artist (&optional filter) + (interactive) + (espotify--maybe-play (consult-spotify-by 'artist filter))) + #+end_src + + #+begin_src emacs-lisp + (defun consult-spotify-track (&optional filter) + (interactive) + (espotify--maybe-play (consult-spotify-by 'track filter))) + #+end_src + + #+begin_src emacs-lisp + (defun consult-spotify-playlist (&optional filter) + (interactive) + (espotify--maybe-play (consult-spotify-by 'playlist filter))) + #+end_src + * Adding metadata to candidates using Marginalia Let's add metadata fields to our candidates, so that packages like @@ -358,28 +387,15 @@ Let's start with an umbrella customization group: (add-to-list 'marginalia-annotators-heavy (cons 'spotify-query-result 'espotify-marginalia-annotate)) - #+end_src - -* Exercises for the reader - - Defining new interactive commands for other types and queries, - as well as standard filters shouldn't be too complicated now that we - have the above tools at our disposal. - - For instance: - #+begin_src emacs-lisp - (defun consult-spotify-playlist (&optional filter) - (interactive) - (espotify--maybe-play (consult-spotify-by 'playlist filter))) - #+end_src - +#+end_src -* Post-amble :notes: +* Post-amble :noexport: #+begin_src emacs-lisp (provide 'espotify) #+end_src + * Footnotes [fn:1] This is an elegant strategy i first learnt about in SICP, many, -- cgit v1.2.3