From 037f0cfbeef8512de8ecaf75a8722e345d88c70b Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 2 Mar 2019 14:36:40 +0100 Subject: [PATCH] =?UTF-8?q?[Music]=20A=20simple=20helper=20function=20to?= =?UTF-8?q?=20update=20=E2=80=98db/playlist=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- site-lisp/db-music.el | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/site-lisp/db-music.el b/site-lisp/db-music.el index 569c2ec..8b2edc2 100644 --- a/site-lisp/db-music.el +++ b/site-lisp/db-music.el @@ -25,8 +25,28 @@ (emms-playlist-select-first) (emms-start))))) - -;; End +(defun db/update-playlist-from-directory (directory) + "Recursively traverse DIRECTORY and update `db/playlist’. + +Files not present `db/playlist’ but that are found in DIRECTORY +are added to `db/playlist’ with tag :undecided, to show the user +that these files are new. Tracks in `db/playlist’ that are not +found in DIRECTORY are currently removed from it." + (interactive (list (expand-file-name "songs/" + emms-source-file-default-directory))) + ;; First convert to hash table for performance + (let ((playlist-hash (make-hash-table :test #'equal))) + (dolist (track db/playlist) + (when (file-exists-p (car track)) + (puthash (car track) (cdr track) playlist-hash))) + (let (new-playlist) + (dolist (file (directory-files-recursively directory "")) + (message "Checking %s" file) + (push (if-let ((state (gethash file playlist-hash nil))) + (cons file state) + (cons file :undecided)) + new-playlist)) + (customize-save-variable 'db/playlist new-playlist)))) (provide 'db-music)