summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2026-09-11 16:31:47 +0100
committerjao <jao@gnu.org>2026-09-11 16:31:47 +0100
commit5d4588421ffe4b14086781c357ce3cfe7fbec274 (patch)
treec609de0ffdfd1fb3aacb35f6289601fa635fad96 /lib
parent249f42208bff568bd0ad4592e08f36911a772b6a (diff)
downloadelibs-5d4588421ffe4b14086781c357ce3cfe7fbec274.tar.gz
elibs-5d4588421ffe4b14086781c357ce3cfe7fbec274.tar.bz2
mpc: remaining playlist time
Diffstat (limited to 'lib')
-rw-r--r--lib/media/jao-mpc.el33
1 files changed, 29 insertions, 4 deletions
diff --git a/lib/media/jao-mpc.el b/lib/media/jao-mpc.el
index f2286a2..238a06c 100644
--- a/lib/media/jao-mpc.el
+++ b/lib/media/jao-mpc.el
@@ -81,13 +81,15 @@
(defun jao-mpc--current-timestr (playing-times &optional current)
(let* ((current (or current (jao-mpc--current)))
- (time (alist-get 'totaltime current "")))
+ (time (alist-get 'totaltime current ""))
+ (remaining (jao-mpc-playlist-duration-string current)))
(if playing-times
- (format "%s/%s%s"
+ (format "%s/%s%s - %s"
(alist-get 'currenttime current "")
time
- (alist-get 'percenttime current ""))
- (format "%s" time))))
+ (alist-get 'percenttime current "")
+ remaining)
+ (format "%s - %s" time remaining))))
(defun jao-mpc--current-str (&optional port times)
(if-let* ((current (jao-mpc--current port))
@@ -210,6 +212,29 @@
(accept-process-output nil 0.5)
(setq jao-random-album-active st)))
+(defun jao-mpc--playlist-duration (&optional current port)
+ (let* ((current (or current (jao-mpc--current)))
+ (times (string-split (jao-mpc--cmd "playlist -f %time%") nil t))
+ (offset (- (string-to-number (alist-get 'songpos current "1")) 1))
+ (times (drop offset times))
+ (times (cons (format "-%s" (alist-get 'currenttime current "0:0")) times))
+ (total 0))
+ (dolist (time times total)
+ (when-let* ((ts (string-split time ":"))
+ (mins (string-to-number (car ts)))
+ (secs (string-to-number (or (cadr ts) "0")))
+ (secs (if (< 0 mins) (- secs) secs)))
+ (setq total (+ total (* 60 mins) secs))))))
+
+;;;###autoload
+(defun jao-mpc-playlist-duration-string (&optional current)
+ (format-seconds "%hh %mm %ss" (jao-mpc--playlist-duration current)))
+
+;;;###autoload
+(defun jao-mpc-show-playlist-duration ()
+ (interactive)
+ (message (jao-mpc-playlist-duration-string)))
+
;;;###autoload
(defun jao-mpc-stop (&optional port)
(interactive)