emms-patches
[Top][All Lists]
Advanced

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

[Emms-patches] [PATCH] emms-player-mpd: acceptd formats scanning for mpd


From: jao
Subject: [Emms-patches] [PATCH] emms-player-mpd: acceptd formats scanning for mpd 0.17
Date: Sun, 14 Oct 2012 23:57:12 +0200

From: Jose Antonio Ortega Ruiz <address@hidden>

* emms-player-mpd.el (emms-player-mpd-get-supported-regexp): extend
  the supported formats scanning to the new (0.17) output of `mpd
  --version', keeping the previous scanners for earlier versions.  We
  include not only file extensions, but also supported network
  protocols, which are also reported by mpd.
---
 lisp/emms-player-mpd.el |   63 +++++++++++++++++++++++++++++------------------
 1 file changed, 39 insertions(+), 24 deletions(-)

diff --git a/lisp/emms-player-mpd.el b/lisp/emms-player-mpd.el
index ae43aa1..5744515 100644
--- a/lisp/emms-player-mpd.el
+++ b/lisp/emms-player-mpd.el
@@ -140,30 +140,45 @@ leave it set to nil."
 (defun emms-player-mpd-get-supported-regexp ()
   "Returns a regexp of file extensions that MusicPD supports,
 or nil if we cannot figure it out."
-  (let ((out (shell-command-to-string "mpd --version"))
-        (found-start nil)
-        (supported nil))
-    ;; Get supported formats
-    ;; New version (0.15.x)
-    (if (string-match "Supported decoders:\\([^0]+?\\)Supported outputs:" out)
-       (setq supported (replace-regexp-in-string "\\[.+?\\]" ""
-                                                 (match-string 1 out)))
-      ;; Older versions
-      (setq out (split-string out "\n"))
-      (while (car out)
-       (cond ((string= (car out) "Supported formats:")
-              (setq found-start t))
-             ((string= (car out) "")
-              (setq found-start nil))
-             (found-start
-              (setq supported (concat supported (car out)))))
-       (setq out (cdr out))))
-    ;; Create regexp
-    (when (and (stringp supported)
-               (not (string= supported "")))
-      (concat "\\`http://\\|\\.\\(m3u\\|pls\\|"
-              (regexp-opt (delq nil (split-string supported)))
-              "\\)\\'"))))
+  (let ((out (shell-command-to-string "mpd --version")))
+    ;; 0.17.x
+    (if (string-match "Decoders plugins:$" out)
+        (let* ((b (match-end 0))
+               (e (string-match "Output plugins:$" out))
+               (plugs (split-string (substring out b e) "\n" t))
+               (plugs (mapcan (lambda (x)
+                                (and (string-match " +\\[.*\\] +\\(.+\\)$" x)
+                                     (split-string (match-string 1 x) nil t)))
+                              plugs))
+               (b (and (string-match "Protocols:$" out) (match-end 0)))
+               (prots (and b (substring out (+ 2 b) -1)))
+               (prots (split-string (or prots "") nil t)))
+          (concat "\\(\\.\\(m3u\\|pls\\|"
+                  (regexp-opt (delq nil plugs))
+                  "\\)\\'\\)\\|\\(\\`"
+                  (regexp-opt (delete "file://" prots)) "\\)"))
+      (let ((found-start nil)
+            (supported nil))
+        (if (string-match "Supported decoders:\\([^0]+?\\)Supported outputs:" 
out)
+            ;; 0.15.x
+            (setq supported (replace-regexp-in-string "\\[.+?\\]" ""
+                                                      (match-string 1 out)))
+          ;; < 0.15
+          (setq out (split-string out "\n"))
+          (while (car out)
+            (cond ((string= (car out) "Supported formats:")
+                   (setq found-start t))
+                  ((string= (car out) "")
+                   (setq found-start nil))
+                  (found-start
+                   (setq supported (concat supported (car out)))))
+            (setq out (cdr out))))
+        ;; Create regexp
+        (when (and (stringp supported)
+                   (not (string= supported "")))
+          (concat "\\`http://\\|\\.\\(m3u\\|pls\\|"
+                  (regexp-opt (delq nil (split-string supported)))
+                  "\\)\\'"))))))
 
 (defcustom emms-player-mpd-supported-regexp
   ;; Use a sane default, just in case
-- 
1.7.10.4




reply via email to

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