[Music] Introduce ‘db/play-auto-playlist’

This is the main entry point to play automatically generated playlists (“auto
playlists”).  It is using the value of ‘db/auto-playlist-file-function’ to
generate a list of files to play.  This list if currently played using EMMS, via
‘db/-emms-playlist-from-files’.
This commit is contained in:
Daniel - 2019-06-10 14:11:52 +02:00
parent bc41e3c5be
commit 9e075d6e0c
No known key found for this signature in database
GPG Key ID: 1C7071A75BB72D64
3 changed files with 57 additions and 43 deletions

12
init.el
View File

@ -2145,10 +2145,14 @@ search commands like `db/helm-shortcuts."
(require 'helm-adaptive)))
(use-package db-music
:init (setq db/playlist-play-function #'db/play-playlist-from-git-annex-find)
:commands (db/play-playlist-from-cache
db/play-playlist-from-git-annex-find
db/update-playlist-from-directory))
:init (setq db/auto-playlist-file-function
#'(lambda ()
(db/playlist-files-from-git-annex-find
"--metadata db-playlist=include")))
:commands (db/play-auto-playlist
db/playlist-files-from-cache
db/playlist-files-from-git-annex-find
db/update-playlist-cache-from-directory))
;; * Shells and such

View File

@ -131,7 +131,7 @@ _RET_: ?RET? _M_: ?M?
("-" emms-volume-lower "lower volume")
("+" emms-volume-raise "raise volume")
("M" emms "show playlist")
("P" (call-interactively db/playlist-play-function)
("P" (db/play-auto-playlist)
"Play automatically generated playlist"))

View File

@ -13,18 +13,22 @@
:group 'convenience
:tag "db-music")
(defcustom db/playlist-play-function #'db/play-playlist-from-cache
"Function to use to automatically generate playlists"
(defcustom db/auto-playlist-file-function #'db/play-playlist-from-cache
"Function that has to return a list of all music files that
should be included in the auto playlist."
:group 'db-music
:type 'function)
(defcustom db/playlist nil
"List of songs to include in a random playlist."
:group 'db-music
:type '(alist :value-type (choice (const :tag "Undecided" :undecided)
(const :tag "Include" :include)
(const :tag "Exclude" :exclude))
:key-type file))
(defun db/play-auto-playlist ()
"Generate playlist using `db/auto-playlist-file-function and
start playing it.
Current backend is EMMS."
(interactive)
(db/-emms-playlist-from-files (funcall db/auto-playlist-file-function)))
;; Idea: make this customizable, so that we can later switch to another backend
;; if necessary
(defun db/-emms-playlist-from-files (files)
"Generate EMMS playlist from FILES.
@ -47,16 +51,23 @@ Shuffle it and start playing it afterwards."
(emms-playlist-select-first)
(emms-start)))))
(defun db/play-playlist-from-cache ()
"Start playing songs from `db/playlist"
(interactive)
(db/-emms-playlist-from-files
(->> db/playlist
(cl-remove-if-not #'(lambda (track)
(eq (cdr track) :include)))
(mapcar #'car))))
(defcustom db/playlist nil
"List of songs to include in a random playlist."
:group 'db-music
:type '(alist :value-type (choice (const :tag "Undecided" :undecided)
(const :tag "Include" :include)
(const :tag "Exclude" :exclude))
:key-type file))
(defun db/play-playlist-from-git-annex-find (match-expression)
(defun db/playlist-files-from-cache ()
"Generate files for auto playlist from `db/playlist cache."
(interactive)
(->> db/playlist
(cl-remove-if-not #'(lambda (track)
(eq (cdr track) :include)))
(mapcar #'car)))
(defun db/playlist-files-from-git-annex-find (match-expression)
"Generate playlist from git annex find on MATCH-EXPRESSION.
Prompts for MATCH-EXPRESSION when called interactively.
@ -65,27 +76,26 @@ are match it. Assumes `emms-source-file-default-directory to be
part of a git-annex repository, and will complain otherwise."
(interactive "smatch expression: ")
(let* ((default-directory emms-source-file-default-directory))
(db/-emms-playlist-from-files
(->> (split-string (with-output-to-string
(with-current-buffer standard-output
(let ((return-value (apply #'call-process
"git" nil t nil
"annex" "find"
(split-string match-expression))))
(unless (zerop return-value)
(error "Call to `git-annex-find failed: %s"
(buffer-string))))))
"\n")
(cl-remove-if-not #'(lambda (path)
(and (not (string-empty-p path))
(file-exists-p path)
(file-readable-p path))))
(mapcar #'(lambda (path)
(expand-file-name
path
emms-source-file-default-directory)))))))
(->> (split-string (with-output-to-string
(with-current-buffer standard-output
(let ((return-value (apply #'call-process
"git" nil t nil
"annex" "find"
(split-string match-expression))))
(unless (zerop return-value)
(error "Call to `git-annex-find failed: %s"
(buffer-string))))))
"\n")
(cl-remove-if-not #'(lambda (path)
(and (not (string-empty-p path))
(file-exists-p path)
(file-readable-p path))))
(mapcar #'(lambda (path)
(expand-file-name
path
emms-source-file-default-directory))))))
(defun db/update-playlist-from-directory (directory)
(defun db/update-playlist-cache-from-directory (directory)
"Recursively traverse DIRECTORY and update `db/playlist.
Files not present `db/playlist but that are found in DIRECTORY