;;; emus.el --- Simple music player for Emacs. -*- lexical-binding:t -*- ;; Author: Tim Vaughan ;; Version: 1.0 ;; Keywords: multimedia ;; URL: http://github.com/tgvaughan/emus ;;; Commentary: ;; This is a simple package for playing audio from a local library ;; of audio files. ;;; Code: ;;; Customizations ;; (defgroup emus nil "Simple music player for Emacs inspired by CMUS." :group 'multimedia) (defcustom emus-directory "~/Music/" "Directory containing audio files for emus." :type '(string)) (defcustom emus-mpg123-program "mpg123" "Name of (and, optionally, path to) mpg123 binary." :type '(string)) ;;; Library ;; (defvar emus-library nil "Emus audio library.") (defun emus-get-audio-files () "Get all mp3 files in main emus directory." (directory-files-recursively emus-directory ".*\\.mp3")) (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." (interactive) (switch-to-buffer "*emus*") (emus-mode)) (define-derived-mode emus-mode special-mode "Emus" "Major mode for EMUS music player.") ;;; Debugging (defun emus-test () (message (emus-get-file-tags "/Users/vaughant/Music/Floex_-_Zorya/Floex - Zorya - 01 Ursa Major.mp3"))) (defun emus-test-play () (emus-send-cmd "lp" "/Users/vaughant/Music/Floex_-_Zorya/Floex - Zorya - 01 Ursa Major.mp3") (emus-send-cmd "silence") (emus-send-cmd "p")) ;;; emus.el ends here