From 5d4588421ffe4b14086781c357ce3cfe7fbec274 Mon Sep 17 00:00:00 2001 From: jao Date: Fri, 11 Sep 2026 16:31:47 +0100 Subject: mpc: remaining playlist time --- lib/media/jao-mpc.el | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'lib') 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) -- cgit v1.2.3