aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Bonnet <lucas@rincevent.net>2010-02-26 18:01:21 +0100
committerLucas Bonnet <lucas@rincevent.net>2010-02-26 18:01:21 +0100
commit886bfe0593e5ba0f419e499b8112cf4bb6b39679 (patch)
treeeab4ee8211ecbdd77f25e025ef91eecb3aa397af
parent8d104889afa240aa69a09124837bde832d955941 (diff)
* lisp/emms-player-mpd.el: new function to update all MPD tracks, then
clear local cache and fetch new updated cache from MusicPD Patch by David Engster <deng@randomsample.de>
-rw-r--r--lisp/emms-player-mpd.el46
1 files changed, 46 insertions, 0 deletions
diff --git a/lisp/emms-player-mpd.el b/lisp/emms-player-mpd.el
index a8f6b9e..7ba5742 100644
--- a/lisp/emms-player-mpd.el
+++ b/lisp/emms-player-mpd.el
@@ -1227,6 +1227,52 @@ the MusicPD database."
(interactive)
(emms-player-mpd-update-directory ""))
+(defvar emms-player-mpd-waiting-for-update-timer nil
+ "Timer object when waiting for MPD update to finish.")
+
+(defun emms-player-mpd-update-all-reset-cache ()
+ "Update all tracks in the MusicPD music directory.
+When update finishes, clear the EMMS cache and call
+`emms-cache-set-from-mpd-all' to dump the MusicPD data into the
+cache."
+ (interactive)
+ (if emms-player-mpd-waiting-for-update-timer
+ (message "Already waiting for an update to finish.")
+ (emms-player-mpd-send
+ "update" nil
+ 'emms-player-mpd-wait-for-update)))
+
+(defun emms-player-mpd-wait-for-update (&optional closure response)
+ "Wait for a currently running mpd update to finish.
+Afterwards, clear the EMMS cache and call
+`emms-cache-set-from-mpd-all'."
+ (if response
+ ;; This is the first call after the update command
+ (let ((id (cdr (assoc "updating_db"
+ (emms-player-mpd-get-alist
+ (emms-player-mpd-parse-response response))))))
+ (if id
+ (progn
+ (message "Updating DB with ID %s. Waiting for the update to finish..." id)
+ (setq emms-player-mpd-waiting-for-update-timer
+ (run-at-time 1 nil 'emms-player-mpd-wait-for-update)))
+ (message "Could not update the DB")))
+ ;; Otherwise, check if update is still in progress
+ (emms-player-mpd-get-status-part
+ nil
+ (lambda (closure updating)
+ (if updating
+ ;; MPD update still in progress, so wait another second
+ (run-at-time 1 nil 'emms-player-mpd-wait-for-update)
+ ;; MPD update finished
+ (setq emms-player-mpd-waiting-for-update-timer nil)
+ (message "MPD update finished.")
+ (sit-for 1)
+ (clrhash emms-cache-db)
+ (emms-cache-set-from-mpd-all)))
+ "updating_db")))
+
+
(provide 'emms-player-mpd)
;;; emms-player-mpd.el ends here