From d2c6a0057dcf7d02434418ad98a70789f1458e8d Mon Sep 17 00:00:00 2001 From: jao Date: Tue, 15 Sep 2026 15:39:24 +0100 Subject: mpc fixes --- lib/media/jao-mpc.el | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/media/jao-mpc.el b/lib/media/jao-mpc.el index 238a06c..23b2dda 100644 --- a/lib/media/jao-mpc.el +++ b/lib/media/jao-mpc.el @@ -212,19 +212,21 @@ (accept-process-output nil 0.5) (setq jao-random-album-active st))) +(defun jao-mpc--time-to-secs (str) + (if-let* ((ts (string-split (or str "") ":")) + (mins (string-to-number (car ts))) + (secs (string-to-number (or (cadr ts) "0")))) + (+ secs (* 60 mins)) + 0)) + (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)) + (total (- (jao-mpc--time-to-secs (alist-get 'currenttime current))))) (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)))))) + (setq total (+ total (jao-mpc--time-to-secs time)))))) ;;;###autoload (defun jao-mpc-playlist-duration-string (&optional current) -- cgit v1.2.3