emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 902f31d 1/2: New user option mpc-cover-image-re


From: Stefan Kangas
Subject: master 902f31d 1/2: New user option mpc-cover-image-re
Date: Wed, 29 Sep 2021 05:28:16 -0400 (EDT)

branch: master
commit 902f31d32b61d0e7e73d5429334fa945e2eece37
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>

    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 bf942cb..fb3d79b 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 494a4b9..ad32ce8 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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]