From 902f31d32b61d0e7e73d5429334fa945e2eece37 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Wed, 29 Sep 2021 07:12:37 +0200 Subject: [PATCH] New user option mpc-cover-image-re * lisp/mpc.el (mpc-cover-image-re): New user option. (mpc-format): Find cover image based on regexp given by above new user option. Treat "folder.png" as a valid cover image name. --- etc/NEWS | 6 ++++++ lisp/mpc.el | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index bf942cb1872..fb3d79bb3af 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2999,6 +2999,12 @@ Set rcirc-omit-responses-after-join analogously to rcirc-omit-responses. *** Implement repeated reconnection strategy See rcirc-reconnect-attempts. +** MPC + +--- +*** New user option 'mpc-cover-image-re'. +If non-nil, it is a regexp that should match a valid cover image. + ** Miscellaneous --- diff --git a/lisp/mpc.el b/lisp/mpc.el index 494a4b9d888..ad32ce8d331 100644 --- a/lisp/mpc.el +++ b/lisp/mpc.el @@ -962,6 +962,11 @@ If PLAYLIST is t or nil or missing, use the main playlist." ;;; Formatter ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defcustom mpc-cover-image-re nil ; (rx (or ".jpg" ".jpeg" ".png") string-end) + "If non-nil, it is a regexp that should match a valid cover image." + :type '(regexp) + :version "28.1") + (defun mpc-secs-to-time (secs) ;; We could use `format-seconds', but it doesn't seem worth the trouble ;; because we'd still need to check (>= secs (* 60 100)) since the special @@ -1034,15 +1039,18 @@ If PLAYLIST is t or nil or missing, use the main playlist." (and (funcall oldpred info) (equal dir (file-name-directory (cdr (assq 'file info)))))))) - (if-let* ((covers '(".folder.png" "cover.jpg" "folder.jpg")) + (if-let* ((covers '(".folder.png" "folder.png" "cover.jpg" "folder.jpg")) (cover (cl-loop for file in (directory-files (mpc-file-local-copy dir)) - if (member (downcase file) covers) + if (or (member (downcase file) covers) + (and mpc-cover-image-re + (string-match mpc-cover-image-re file))) return (concat dir file))) (file (with-demoted-errors "MPC: %s" (mpc-file-local-copy cover)))) (let (image) (if (null size) (setq image (create-image file)) (let ((tempfile (make-temp-file "mpc" nil ".jpg"))) + ;; FIXME: Use native image scaling instead. (call-process "convert" nil nil nil "-scale" size file tempfile) (setq image (create-image tempfile)) -- 2.39.5