[Music] Make updating playlists keep tracks outside of source directory
This commit is contained in:
parent
ed285c87d2
commit
f671a44939
|
@ -39,13 +39,31 @@ exist anymore are removed from it."
|
||||||
(dolist (track db/playlist)
|
(dolist (track db/playlist)
|
||||||
(when (file-exists-p (car track))
|
(when (file-exists-p (car track))
|
||||||
(puthash (car track) (cdr track) playlist-hash)))
|
(puthash (car track) (cdr track) playlist-hash)))
|
||||||
|
|
||||||
(let (new-playlist)
|
(let (new-playlist)
|
||||||
|
;; iterate over files in DIRECTORY and add them to the playlist, with the
|
||||||
|
;; already known state whenever possible
|
||||||
(dolist (file (directory-files-recursively directory ""))
|
(dolist (file (directory-files-recursively directory ""))
|
||||||
(message "Checking %s" file)
|
(message "Checking %s" file)
|
||||||
(push (if-let ((state (gethash file playlist-hash nil)))
|
(push (if-let ((state (gethash file playlist-hash nil)))
|
||||||
(cons file state)
|
(cons file state)
|
||||||
(cons file :undecided))
|
(cons file :undecided))
|
||||||
new-playlist))
|
new-playlist)
|
||||||
|
(remhash file playlist-hash))
|
||||||
|
|
||||||
|
;; keep all other tracks that are not in DIRECTORY
|
||||||
|
(maphash #'(lambda (track state)
|
||||||
|
(push (cons track state) new-playlist))
|
||||||
|
playlist-hash)
|
||||||
|
|
||||||
|
;; sort to keep version control happy
|
||||||
|
(setq new-playlist
|
||||||
|
(sort new-playlist
|
||||||
|
#'(lambda (track-1 track-2)
|
||||||
|
(string< (car track-1)
|
||||||
|
(car track-2)))))
|
||||||
|
|
||||||
|
;; save it
|
||||||
(customize-save-variable 'db/playlist new-playlist))))
|
(customize-save-variable 'db/playlist new-playlist))))
|
||||||
|
|
||||||
(provide 'db-music)
|
(provide 'db-music)
|
||||||
|
|
Loading…
Reference in New Issue