emms-patches
[Top][All Lists]
Advanced

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

[Emms-patches] [PATCH] Fix for off-by-one errors in MPD cache


From: Jose Antonio Ortega Ruiz
Subject: [Emms-patches] [PATCH] Fix for off-by-one errors in MPD cache
Date: Wed, 5 Feb 2014 06:13:53 +0100

The result from MPD's listallinfo command now includes additional fields
for directories.  Those entries made detection of track limits
incorrect, because of duplicated keys in the alists.
---
 lisp/emms-player-mpd.el | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/lisp/emms-player-mpd.el b/lisp/emms-player-mpd.el
index 5744515..704c4b2 100644
--- a/lisp/emms-player-mpd.el
+++ b/lisp/emms-player-mpd.el
@@ -1,6 +1,6 @@
 ;;; emms-player-mpd.el --- MusicPD support for EMMS
 
-;; Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+;; Copyright (C) 2005, 2006, 2007, 2008, 2009, 2014 Free Software Foundation, 
Inc.
 
 ;; Author: Michael Olson <address@hidden>
 
@@ -1186,6 +1186,14 @@ The track should be an alist as per 
`emms-player-mpd-get-alist'."
         (emms-info-mpd-process track track-info)
         (funcall emms-cache-set-function 'file name track)))))
 
+(defun emms-cache--info-cleanup (info)
+  (let ((xs (mapcar (lambda (x)
+                      (and (stringp x)
+                           (not (string-match-p "\\`\\(Last-\\|direct\\)" x))
+                           x))
+                    info)))
+    (cons nil (delq nil xs))))
+
 (defun emms-cache-set-from-mpd-directory (dir)
   "Dump all MusicPD data from DIR into the EMMS cache.
 
@@ -1205,11 +1213,18 @@ This is useful to do when you have recently acquired 
new music."
          nil
          (lambda (closure response)
            (message "Dumping MusicPD data to cache...processing")
-           (let ((info (emms-player-mpd-get-alists
-                        (emms-player-mpd-parse-response response))))
-             (dolist (track-info info)
-               (emms-cache-set-from-mpd-track track-info))
-             (message "Dumping MusicPD data to cache...done")))))
+           (let ((info (emms-player-mpd-parse-response response)))
+             (when (null (car info))
+               (let* ((info (emms-cache--info-cleanup info))
+                      (info (emms-player-mpd-get-alists info))
+                      (track 1)
+                      (total (length info)))
+                 (dolist (track-info info)
+                   (message "Dumping MusicPD data to cache...%d/%d" track 
total)
+                   (emms-cache-set-from-mpd-track track-info)
+                   (setq track (+ 1 track)))
+                 (message "Dumping MusicPD data to cache... %d tracks 
processed"
+                          total)))))))
     (error "Caching is not enabled")))
 
 (defun emms-cache-set-from-mpd-all ()
-- 
1.9.rc1




reply via email to

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