Function: mpc-cmd-find

mpc-cmd-find is a byte-compiled function defined in mpc.el.gz.

Signature

(mpc-cmd-find TAG VALUE)

Documentation

Return a list of all songs whose tag TAG has value VALUE.

The songs are returned as alists.

Source Code

;; Defined in /usr/src/emacs/lisp/mpc.el.gz
(defun mpc-cmd-find (tag value)
  "Return a list of all songs whose tag TAG has value VALUE.
The songs are returned as alists."
  (or (gethash (cons tag value) mpc--find-memoize)
      (puthash (cons tag value)
               (cond
                ((eq tag 'Playlist)
                 ;; Special case for pseudo-tag playlist.
                 (let ((l (condition-case nil
                              (mpc-proc-buf-to-alists
                               (mpc-proc-cmd (list "listplaylistinfo" value)))
                            (mpc-proc-error
                             ;; "[50@0] {listplaylistinfo} No such playlist"
                             nil)))
                       (i 0))
                   (mapcar (lambda (s)
                             (prog1 (cons (cons 'Pos (number-to-string i)) s)
                               (cl-incf i)))
                           l)))
                ((eq tag 'Search)
                 (mpc-proc-buf-to-alists
                  (mpc-proc-cmd (list "search" "any" value))))
                ((eq tag 'Directory)
                 (let ((pairs
                        (mpc-proc-buf-to-alist
                         (mpc-proc-cmd (list "listallinfo" value)))))
                   (mpc--proc-alist-to-alists
                    ;; Strip away the `directory' entries.
                    (delq nil (mapcar (lambda (pair)
                                        (if (eq (car pair) 'directory)
                                            nil pair))
                                      pairs)))))
                ((string-match "|" (symbol-name tag))
                 (add-to-list 'mpc--find-memoize-union-tags tag)
                 (let ((tag1 (intern (substring (symbol-name tag)
                                                0 (match-beginning 0))))
                       (tag2 (intern (substring (symbol-name tag)
                                                (match-end 0)))))
                   (mpc-union (mpc-cmd-find tag1 value)
                              (mpc-cmd-find tag2 value))))
                (t
                 (condition-case nil
                     (mpc-proc-buf-to-alists
                      (mpc-proc-cmd (list "find" (symbol-name tag) value)))
                   (mpc-proc-error
                    ;; If `tag' is not one of the expected tags, MPD burps
                    ;; about not having the relevant table.  FIXME: check
                    ;; the kind of error.
                    (error "Unknown tag %s" tag)
                    (let ((res ()))
                      (setq value (cons tag value))
                      (dolist (song (mpc-proc-buf-to-alists
                                     (mpc-proc-cmd "listallinfo")))
                        (if (member value song) (push song res)))
                      res)))))
               mpc--find-memoize)))