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.
This commit is contained in:
Stefan Kangas 2021-09-29 07:12:37 +02:00
parent dcabf95275
commit 902f31d32b
2 changed files with 16 additions and 2 deletions

View file

@ -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
---

View file

@ -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))