+(defvar emus-tags nil)
+
+(defun emus-update-tags ()
+ "Get ID3 tags for given filename"
+ (let ((proc (emus-get-process))
+ (depth 0)
+ (tagstr "")
+ (filenames (emus-get-audio-files)))
+ (setq emus-tags nil)
+ (set-process-filter proc (lambda (proc string)
+ (setq tagstr (concat tagstr string))
+ (cond
+ ((string-suffix-p "}\n" string) (setq depth (- depth 1)))
+ ((string-suffix-p "{\n" string) (setq depth (+ depth 1))))
+ (when (and (= depth 0) (string-suffix-p "\n" string))
+ (add-to-list 'emus-tags `(,(car filenames) ,tagstr))
+ (setq tagstr "")
+ (setq filenames (cdr filenames))
+ (if filenames
+ (emus-send-cmd "lp" (car filenames))
+ (set-process-filter proc nil)))))
+ (emus-send-cmd "lp" (car filenames))))
+
+(defun emus-get-process ()
+ "Return current or new mpg123 process."
+ (let* ((emus-process-raw (get-process "emus-process"))
+ (emus-process (if emus-process-raw
+ (if (process-live-p emus-process-raw)
+ emus-process-raw
+ (kill-process emus-process-raw)
+ nil))))
+ (if emus-process
+ emus-process
+ (make-process :name "emus-process"
+ ;; :buffer (get-buffer-create "*emus-process*")
+ :command `(,emus-mpg123-program "-R")))))
+
+(defun emus-send-cmd (cmd &rest args)
+ (process-send-string (emus-get-process)
+ (concat
+ (seq-reduce (lambda (s1 s2) (concat s1 " " s2)) args cmd)
+ "\n")))
+
+;;; Browser
+;;
+
+(defun emus-browse ()
+ "Switch to *emus* audio library browser."