summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-01-22 00:10:17 +0000
committerjao <jao@gnu.org>2022-01-22 00:10:17 +0000
commite4e46f41b0d01b9efab86b2f3cebbf116c3216b5 (patch)
tree68b55bc840cef27c87ff44ccc6e798ef9020838e
parentec873bca5cfebe194b56ac03e4b760cf63f2156c (diff)
downloadelibs-e4e46f41b0d01b9efab86b2f3cebbf116c3216b5.tar.gz
elibs-e4e46f41b0d01b9efab86b2f3cebbf116c3216b5.tar.bz2
spt/mpris switching
-rw-r--r--completion.org5
-rw-r--r--exwm.org19
-rw-r--r--init.org61
-rw-r--r--lib/media/jao-mpris.el20
-rw-r--r--lib/media/jao-spt.el24
5 files changed, 89 insertions, 40 deletions
diff --git a/completion.org b/completion.org
index af9bca4..9c8362b 100644
--- a/completion.org
+++ b/completion.org
@@ -483,8 +483,13 @@
*** spotify
#+begin_src emacs-lisp
(with-eval-after-load "consult-spotify"
+ (defun jao-consult-spt-play (candidate)
+ (when-let (url (espotify-candidate-url candidate))
+ (jao-spt-play-uri url)))
+
(embark-define-keymap spotify-item-keymap
"Actions for Spotify search results"
+ ("s" jao-consult-spt-play)
("y" espotify-yank-candidate-url)
("a" espotify-play-candidate-album)
("h" espotify-show-candidate-info))
diff --git a/exwm.org b/exwm.org
index ce2f3d9..030d4ec 100644
--- a/exwm.org
+++ b/exwm.org
@@ -538,23 +538,7 @@
("M" (lambda () (concat "minibuffer" (when jao-minibuffer-enabled-p "*")))
jao-minibuffer-toggle)]])
- (transient-define-prefix jao-transient-spt ()
- [["play"
- ("x" "toggle" jao-spt-toggle)
- ("n" "next" jao-spt-next)
- ("p" "previous" jao-spt-previous)]
- ["current song"
- ("l" "like" jao-spt-like)
- ("d" "dislike" jao-spt-dislike)
- ("L" "lyrics" jao-spt-show-lyrics)]
- ["seek"
- ("f" "forward 10 secs" jao-spt-seek :transient t)
- ("b" "backward 10 secs" jao-spt-seek-back :transient t)]
- ["status/ui"
- ("w" "status" jao-spt-echo-current)
- ("u" "spt ui" jao-exwm-spt)]])
-
- #+end_src
+ #+end_src
* Keybindings
#+begin_src emacs-lisp
(define-key exwm-mode-map [?\C-q] #'exwm-input-send-next-key)
@@ -584,7 +568,6 @@
([?\s-s] . jao-transient-spotify)
([?\s-t] . vterm)
([?\s-w] . jao-transient-exwm)
- ([?\s-x] . jao-transient-spt)
([?\s-z] . jao-transient-sleep)
([XF86AudioMute] . jao-mixer-master-toggle)
([XF86AudioPlay] . jao-player-toggle)
diff --git a/init.org b/init.org
index 86005e1..7c801f5 100644
--- a/init.org
+++ b/init.org
@@ -2940,15 +2940,45 @@
:demand t
:config
(defun jao-mpris-setup-aliases ()
+ (setq espotify-play-uri-function #'espotify-play-uri-with-dbus)
+ (defalias 'jao-spotify-list 'jao-exwm-ncmpcpp)
+ (defalias 'jao-spotify-lyrics 'jao-show-lyrics)
(defalias 'jao-spotify-toggle #'jao-mpris-play-pause)
(defalias 'jao-spotify-next #'jao-mpris-next)
(defalias 'jao-spotify-prev #'jao-mpris-previous)
- (defalias 'jao-spotify-current #'jao-mpris-show-osd)))
+ (defalias 'jao-spotify-current #'jao-mpris-show-osd)
+ (defalias 'jao-spotify-seek #'jao-mpris-seek)
+ (defalias 'jao-spotify-seek-back #'jao-mpris-seek-back)
+ (defalias 'jao-spotify-volume #'jao-mpris-vol)
+ (defalias 'jao-spotify-volume-down #'jao-mpris-vol-down)))
(jao-mpris-setup-aliases)
(jao-mpris-register "mopidy" :system (if jao-modeline-in-minibuffer-p -10 70))
- (use-package jao-spt :demand t)
+ (use-package jao-spt
+ :demand t
+ :config
+ (defun jao-spt-setup-aliases ()
+ (setq espotify-play-uri-function #'jao-spt-play-uri)
+ (defalias 'jao-spotify-list 'jao-exwm-spt)
+ (defalias 'jao-spotify-lyrics 'jao-spt-show-lyrics)
+ (defalias 'jao-spotify-toggle #'jao-spt-toggle)
+ (defalias 'jao-spotify-next #'jao-spt-next)
+ (defalias 'jao-spotify-prev #'jao-spt-previous)
+ (defalias 'jao-spotify-current #'jao-spt-echo-current)
+ (defalias 'jao-spotify-seek #'jao-spt-seek)
+ (defalias 'jao-spotify-seek-back #'jao-spt-seek-back)
+ (defalias 'jao-spotify-volume #'jao-spt-vol)
+ (defalias 'jao-spotify-volume-down #'jao-spt-vol-down)))
+
+ (defvar jao-spt-on t)
+ (jao-spt-setup-aliases)
+
+ (defun jao-spotify-toggle-player ()
+ (interactive)
+ (if jao-spt-on (jao-mpris-setup-aliases) (jao-spt-setup-aliases))
+ (message "%s activated "
+ (if (setq jao-spt-on (not jao-spt-on)) "spt" "mpris")))
#+end_src
*** mpc
@@ -3019,21 +3049,14 @@
(interactive)
(jao-mpc-show-playlist jao-mopidy-port))
- (defun jao-player-seek-m10 ()
- (interactive)
- (jao-player-seek 10 jao-mopidy-port))
-
- (defun jao-player-seek-m-10 ()
- (interactive)
- (jao-player-seek -10 jao-mopidy-port))
-
-
(defun jao-player-level-cap () (interactive) (jao-mixer-level "Capture"))
(use-package jao-random-album :demand t)
(transient-define-prefix jao-transient-spotify ()
- [["Search"
+ [:description
+ (lambda () (format "Spotify using %s" (if jao-spt-on "spt" "MPRIS")))
+ ["Search"
("a" "album" jao-spotify-album)
("A" "artist" jao-spotify-artist)
("t" "track" jao-spotify-track)
@@ -3043,12 +3066,16 @@
("n" "next" jao-spotify-next)
("p" "previous" jao-spotify-prev)]
["Seek"
- ("f" "seek fwd" jao-player-seek-m10 :transient t)
- ("F" "seek bwd" jao-player-seek-m-10 :transient t)]
+ ("f" "seek fwd" jao-spotify-seek :transient t)
+ ("F" "seek bwd" jao-spotify-seek-back :transient t)]
+ ["Volume"
+ ("u" "" "up" jao-spotify-volume :transient t)
+ ("d" "down" jao-spotify-volume-down :transient t)]
["Browse"
- ("l" "playing list" jao-exwm-ncmpcpp)
- ("T" "show times" jao-mpris-status-times)
- ("w" "currently playing" jao-spotify-current)]])
+ ("l" "playing list" jao-spotify-list)
+ ("L" "lyrics" jao-spotify-lyrics)
+ ("w" "currently playing" jao-spotify-current)
+ ("t" "toggle player" jao-spotify-toggle-player)]])
(transient-define-prefix jao-transient-media ()
[["Play"
diff --git a/lib/media/jao-mpris.el b/lib/media/jao-mpris.el
index 8f5d0de..d34480a 100644
--- a/lib/media/jao-mpris.el
+++ b/lib/media/jao-mpris.el
@@ -1,6 +1,6 @@
;;; jao-mpris.el --- mpris players control -*- lexical-binding: t; -*-
-;; Copyright (C) 2020, 2021 jao
+;; Copyright (C) 2020, 2021, 2022 jao
;; Author: jao <mail@jao.io>
;; Keywords: multimedia
@@ -39,6 +39,24 @@
(jao-playerctl--def jao-mpris-next "next")
(jao-playerctl--def jao-mpris-previous "previous")
+(defun jao-mpris-seek (secs)
+ (interactive "p")
+ (let ((secs (if (zerop secs) 10 secs)))
+ (jao-mpris--playerctl "position" (format "%d" secs))))
+
+(defun jao-mpris-seek-back (secs)
+ (interactive "p")
+ (jao-mpris-seek (- secs)))
+
+(defun jao-mpris-vol (n)
+ (interactive "p")
+ (let ((secs (if (zerop n) 10 n)))
+ (jao-mpris--playerctl "volume" (format "%d" n))))
+
+(defun jao-mpris-vol-down (n)
+ (interactive "p")
+ (jao-mpris-vol (- n)))
+
(defun jao-playerctl--status (&optional sep)
(let* ((sep (or sep " ||| "))
(fmt (mapconcat 'identity
diff --git a/lib/media/jao-spt.el b/lib/media/jao-spt.el
index 1fdee83..9cdd93e 100644
--- a/lib/media/jao-spt.el
+++ b/lib/media/jao-spt.el
@@ -85,16 +85,32 @@
(jao-spt--pb* "--dislike"))
;;;###autoload
-(defun jao-spt-seek (secs)
+(defun jao-spt-seek (&optional secs)
(interactive "p")
- (let ((secs (if (zerop secs) 10 secs)))
- (jao-spt--pb* "--seek" (format "%s%s" (if (> secs 0) "+" "-") secs))))
+ (let ((secs (if (zerop (or secs 0)) 10 secs)))
+ (jao-spt--pb* "--seek" (format "%d" secs))))
;;;###autoload
-(defun jao-spt-seek-back (secs)
+(defun jao-spt-seek-back (&optional secs)
(interactive "p")
(jao-spt-seek (- secs)))
+(defun jao-spt--get-vol (delta)
+ (let* ((jao-spt-format "%v")
+ (v (string-to-number (jao-spt--pb))))
+ (number-to-string (max 0 (+ delta v)))))
+
+;;;###autoload
+(defun jao-spt-vol (&optional n)
+ (interactive "p")
+ (let ((n (or n 10)))
+ (jao-spt--pb* "--volume" (jao-spt--get-vol (if (zerop n) 10 n)))))
+
+;;;###autoload
+(defun jao-spt-vol-down (&optional n)
+ (interactive "p")
+ (jao-spt-vol (- (or n 10))))
+
;;;###autoload
(defun jao-spt-echo-current ()
(interactive)