[Music] A simple helper function to update ‘db/playlist’
This commit is contained in:
parent
f2c0847ffa
commit
037f0cfbee
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue