summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--eos/sys/jao-ednc.el (renamed from sys/jao-ednc.el)0
-rw-r--r--eos/sys/jao-embark.el62
-rw-r--r--eos/sys/jao-minibuffer.el (renamed from sys/jao-minibuffer.el)0
-rw-r--r--eos/sys/jao-notify.el (renamed from sys/jao-notify.el)0
-rw-r--r--eos/sys/jao-osd.el (renamed from sys/jao-osd.el)0
-rw-r--r--eos/sys/jao-sleep.el (renamed from sys/jao-sleep.el)0
-rw-r--r--media/espotify.org58
-rw-r--r--readme.org2
8 files changed, 100 insertions, 22 deletions
diff --git a/sys/jao-ednc.el b/eos/sys/jao-ednc.el
index 03d4049..03d4049 100644
--- a/sys/jao-ednc.el
+++ b/eos/sys/jao-ednc.el
diff --git a/eos/sys/jao-embark.el b/eos/sys/jao-embark.el
new file mode 100644
index 0000000..9572489
--- /dev/null
+++ b/eos/sys/jao-embark.el
@@ -0,0 +1,62 @@
+;;; jao-embark.el --- embark actions -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2021 jao
+
+;; Author: jao <mail@jao.io>
+;; Keywords: convenience
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Actions and utilities for embark
+
+;;; Code:
+
+(require 'embark)
+
+(defvar jao-embark-video-url-rx
+ (format "^https?://\\(?:www\\.\\)?%s/.+"
+ (regexp-opt '("youtu.be"
+ "youtube.com"
+ "blip.tv"
+ "vimeo.com"
+ "infoq.com")
+ t))
+ "A regular expression matching URLs that point to video streams")
+
+(defun jao-embark-video-finder ()
+ "Check whether we're looking at a video URL.
+Return (video-url . <URL>) if so."
+ (when-let ((url (thing-at-point-url-at-point)))
+ (when (string-match-p jao-embark-video-url-rx url)
+ (cons 'video-url url))))
+
+(defun jao-embark-play-video-url (&optional url)
+ (interactive "sURL: ")
+ (let ((cmd (format "mpv %s" (shell-quote-argument url))))
+ (start-process-shell-command "mpv" nil cmd)))
+
+(add-to-list 'embark-target-finders #'jao-embark-video-finder)
+
+(embark-define-keymap jao-embark-video-url-map
+ "Actions on URLs pointing to remote video streams."
+ ("p" jao-embark-play-video-url)
+ ("b" browse-url)
+ ("f" browse-url-firefox))
+
+(add-to-list 'embark-keymap-alist '(video-url . jao-embark-video-url-map))
+
+(provide 'jao-embark)
+;;; jao-embark.el ends here
diff --git a/sys/jao-minibuffer.el b/eos/sys/jao-minibuffer.el
index b626151..b626151 100644
--- a/sys/jao-minibuffer.el
+++ b/eos/sys/jao-minibuffer.el
diff --git a/sys/jao-notify.el b/eos/sys/jao-notify.el
index dc48ca4..dc48ca4 100644
--- a/sys/jao-notify.el
+++ b/eos/sys/jao-notify.el
diff --git a/sys/jao-osd.el b/eos/sys/jao-osd.el
index acdc629..acdc629 100644
--- a/sys/jao-osd.el
+++ b/eos/sys/jao-osd.el
diff --git a/sys/jao-sleep.el b/eos/sys/jao-sleep.el
index 93da0e7..93da0e7 100644
--- a/sys/jao-sleep.el
+++ b/eos/sys/jao-sleep.el
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,
diff --git a/readme.org b/readme.org
index c40ea97..ac4fd03 100644
--- a/readme.org
+++ b/readme.org
@@ -2,13 +2,13 @@
*** Sections
+ - [[./eos][eos]] generic utilities for the emacs operating system
- [[./themes][themes]] color themes based on Emacs builtin custom themes
- [[org][org]] utilities for org-mode
- [[./doc][doc]] opening documents (pdfs, mostly)
- [[./media][media]] utilities for music players and the like
- [[./prog][prog]] utilities for compilation and programming modes
- [[./net][net]] utilities for networking (w3m, weather &c.)
- - [[./sys][sys]] generic utilities for external programs
- [[./bmk][bmk]] a web bookmark manager
See also my [[https://jao.io/cgit/emacs][emacs custom files]].