diff options
author | jao <jao@gnu.org> | 2022-05-22 06:32:22 +0100 |
---|---|---|
committer | jao <jao@gnu.org> | 2022-05-22 06:32:22 +0100 |
commit | 8d98294a7acbd25e0943335babaaf80936940912 (patch) | |
tree | 0326092f739c46056c99ff1dc6550e64f9541462 /lib/media | |
parent | a32821d78893d654523b8f6f421408e756b7723b (diff) | |
download | elibs-8d98294a7acbd25e0943335babaaf80936940912.tar.gz elibs-8d98294a7acbd25e0943335babaaf80936940912.tar.bz2 |
mpc: better status (times)
Diffstat (limited to 'lib/media')
-rw-r--r-- | lib/media/jao-mpc.el | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/lib/media/jao-mpc.el b/lib/media/jao-mpc.el index e25cc46..a86795b 100644 --- a/lib/media/jao-mpc.el +++ b/lib/media/jao-mpc.el @@ -42,18 +42,30 @@ (r (shell-command-to-string (format "mpc -p %s %s" port cmd)))) (replace-regexp-in-string "^\\(warning: \\)?MPD .+\n" "" r))) +(defun jao-mpc--fformat (fields) + (mapconcat (lambda (f) (format "%s:::%%%s%%" f f)) fields "\n")) + (defconst jao-mpc--fields '(artist album composer originaldate genre title track position time name)) (defconst jao-mpc--stfmt - (mapconcat (lambda (f) (format "%s:::%%%s%%" f f)) jao-mpc--fields "\n")) + (jao-mpc--fformat + '(artist album composer originaldate genre title track name))) + +(defconst jao-mpc--stfmtt + (jao-mpc--fformat '(currenttime totaltime percenttime songpos length))) + +(defmacro jao-mpc--parse-fields (res-str res) + `(dolist (s (split-string ,res-str "\n" t " ") ,res) + (when (string-match "\\(.+\\):::\\(.+\\)" s) + (push (cons (intern (match-string 1 s)) (match-string 2 s)) ,res)))) (defun jao-mpc--current (&optional port) (let ((s (jao-mpc--cmd (format "-f '%s' current" jao-mpc--stfmt) port)) + (st (jao-mpc--cmd (format "status '%s'" jao-mpc--stfmtt))) (res)) - (dolist (s (split-string s "\n" t " ") res) - (when (string-match "\\(.+\\):::\\(.+\\)" s) - (push (cons (intern (match-string 1 s)) (match-string 2 s)) res))))) + (jao-mpc--parse-fields s res) + (jao-mpc--parse-fields st res))) (defun jao-mpc--playing-p (&optional port) (string-prefix-p "playing" (jao-mpc--cmd "status %state%" port))) @@ -65,16 +77,22 @@ (put-text-property 0 (length str) 'face face str) str) -(defun jao-mpc--current-str (&optional port current len) - (let* ((current (or current (jao-mpc--current port))) - (len (or len (jao-mpc--queue-len port))) +(defun jao-mpc--current-str (&optional port times) + (let* ((current (jao-mpc--current port)) + (len (alist-get 'length current "0")) (title (alist-get 'title current (alist-get 'name current ""))) (album (alist-get 'album current)) (artist (alist-get 'artist current)) (composer (alist-get 'composer current)) - (no (string-to-number (alist-get 'position current "0"))) - (time (alist-get 'time current ""))) - (format "> %s%s %s%s%s%s" ;; + (no (string-to-number (alist-get 'songpos current "0"))) + (time (alist-get 'totaltime current "")) + (tims (if times + (format " [%s/%s%s]" + (alist-get 'currenttime current "") + time + (alist-get 'percenttime current "")) + (format " [%s]" time)))) + (format "%s%s %s%s%s%s" ;; (jao--put-face (if (zerop no) "" (format "%02d/%s " no len)) 'jao-themes-f02) (jao--put-face title 'jao-themes-f00) @@ -82,9 +100,7 @@ (jao--put-face (if composer (format " [%s]" composer) "") 'jao-themes-f01) (jao--put-face (if album (format " (%s)" album) "") 'jao-themes-f11) - (if (string-blank-p time) - "" - (jao--put-face (format " [%s]" time) 'jao-themes-dimm))))) + (jao--put-face tims (if times 'jao-themes-f00 'jao-themes-dimm))))) (defvar jao-mpc-minibuffer-str "") @@ -212,7 +228,7 @@ ;;;###autoload (defun jao-mpc-echo-current (&optional port) (interactive) - (jao-notify (jao-mpc--current-str port))) + (message "%s" (jao-mpc--current-str port t))) ;;;###autoload (defun jao-mpc-add-url (url) |