summaryrefslogtreecommitdiffhomepage
path: root/lib/media
diff options
context:
space:
mode:
Diffstat (limited to 'lib/media')
-rw-r--r--lib/media/jao-lyrics.el4
-rw-r--r--lib/media/jao-mpc.el56
-rw-r--r--lib/media/jao-mpris.el34
-rw-r--r--lib/media/jao-random-album.el58
4 files changed, 86 insertions, 66 deletions
diff --git a/lib/media/jao-lyrics.el b/lib/media/jao-lyrics.el
index 985c9d9..f7b47ca 100644
--- a/lib/media/jao-lyrics.el
+++ b/lib/media/jao-lyrics.el
@@ -1,6 +1,6 @@
-;; jao-lyrics.el -- simple show lyrics using glyrc
+;; jao-lyrics.el -- simple show lyrics using glyrc -*- lexical-binding: t; -*-
-;; Copyright (C) 2009, 2010, 2017, 2019, 2020, 2022 Jose Antonio Ortega Ruiz
+;; Copyright (C) 2009, 2010, 2017, 2019, 2020, 2022, 2026 Jose Antonio Ortega Ruiz
;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
;; Start date: Sat Jul 04, 2009 13:41
diff --git a/lib/media/jao-mpc.el b/lib/media/jao-mpc.el
index 0f000da..43046b4 100644
--- a/lib/media/jao-mpc.el
+++ b/lib/media/jao-mpc.el
@@ -1,6 +1,6 @@
;;; jao-mpc.el --- Using mpc to interact with mpd -*- lexical-binding: t; -*-
-;; Copyright (C) 2021, 2022, 2024 jao
+;; Copyright (C) 2021, 2022, 2024, 2025, 2026 jao
;; Author: jao <mail@jao.io>
;; Keywords: convenience
@@ -30,6 +30,7 @@
(require 'jao-themes)
(require 'jao-lyrics)
(require 'jao-random-album)
+(require 'jao-notify)
(defconst jao-mpc--albums "*MPC Albums*")
(defconst jao-mpc--playlist "*MPC Playlist*")
@@ -46,11 +47,12 @@
(mapconcat (lambda (f) (format "%s:::%%%s%%" f f)) fields "\n"))
(defconst jao-mpc--fields
- '(artist album composer originaldate genre title track position time name))
+ '(artist album composer originaldate genre title track position time name
+ file))
(defconst jao-mpc--stfmt
(jao-mpc--fformat
- '(artist album composer originaldate genre title track name)))
+ '(artist album composer originaldate genre title track name file)))
(defconst jao-mpc--stfmtt
(jao-mpc--fformat '(currenttime totaltime percenttime songpos length)))
@@ -106,7 +108,8 @@
(jao--put-face (or artist "") 'jao-themes-f01)
(jao--put-face (if composer (format " [%s]" composer) "")
'jao-themes-f01)
- (jao--put-face (if album (format " (%s)" album) "") 'jao-themes-f11)
+ (jao--put-face (if album (format " (%s)" album) "")
+ 'jao-themes-f11)
(jao--put-face tims (if times 'jao-themes-f00 'jao-themes-dimm))))
""))
@@ -125,15 +128,17 @@
(defvar jao-mpc--idle-procs nil)
(defun jao-mpc--idle-loop (&optional port)
- (when-let (proc (alist-get port jao-mpc--idle-procs))
+ (when-let* ((proc (alist-get port jao-mpc--idle-procs)))
(ignore-errors (kill-process proc)))
(setf (alist-get port jao-mpc--idle-procs nil t)
(make-process :name (format "jao-mpc-idleloop (%s)" port)
:buffer nil
:noquery t
- :command `("mpc" "-p" ,(format "%s" (or port jao-mpc-port))
- "idleloop" "player")
- :filter (lambda (_p _s) (jao-mpc--set-current-str port)))))
+ :command
+ `("mpc" "-p" ,(format "%s" (or port jao-mpc-port))
+ "idleloop" "player")
+ :filter (lambda (_p _s)
+ (jao-mpc--set-current-str port)))))
(defvar jao-mpc--browser-port nil)
@@ -146,7 +151,7 @@
(read-only-mode 1))
(defun jao-mpc--album-buffer ()
- (if-let (b (get-buffer jao-mpc--albums))
+ (if-let* ((b (get-buffer jao-mpc--albums)))
b
(with-current-buffer (get-buffer-create jao-mpc--albums)
(jao-mpc-albums-mode)
@@ -157,7 +162,8 @@
(let ((a (or album (string-trim (thing-at-point 'line))))
(p (or port jao-mpc--browser-port)))
(jao-mpc--cmd "clear" p)
- (jao-mpc--cmd (if idp (concat "add " a) (format "findadd album \"%s\"" a)) p)
+ (jao-mpc--cmd (if idp (concat "add " a) (format "findadd album \"%s\"" a))
+ p)
(jao-mpc--cmd "play" p)))
(define-key jao-mpc-albums-mode-map (kbd "n") #'next-line)
@@ -190,7 +196,8 @@
(define-key jao-mpc-playlist-mode-map (kbd "n") #'next-line)
(define-key jao-mpc-playlist-mode-map (kbd "p") #'previous-line)
(define-key jao-mpc-playlist-mode-map (kbd "q") #'bury-buffer)
-(define-key jao-mpc-playlist-mode-map (kbd ".") #'jao-mpc--playlist-goto-current)
+(define-key jao-mpc-playlist-mode-map (kbd ".")
+ #'jao-mpc--playlist-goto-current)
(define-key jao-mpc-playlist-mode-map (kbd "RET") #'jao-mpc--playlist-play)
(define-key jao-mpc-playlist-mode-map (kbd "C") #'jao-mpc-clear)
@@ -217,6 +224,11 @@
(jao-mpc--with-delayed-random-album "toggle" port))
;;;###autoload
+(defun jao-mpc-pause (&optional port)
+ (interactive)
+ (jao-mpc--with-delayed-random-album "pause" port))
+
+;;;###autoload
(defun jao-mpc-play (&optional port)
(interactive)
(jao-mpc--cmd "play" port))
@@ -252,6 +264,23 @@
(message "Playing time: %s" (jao-mpc--current-timestr t)))
;;;###autoload
+(defun jao-mpc-notify (&optional port)
+ (interactive)
+ (when-let* ((current (jao-mpc--current)))
+ (let* ((artist (or (alist-get 'artist current) "Anonymous"))
+ (title (or (alist-get 'title current)
+ (when-let* ((tl (alist-get 'file current)))
+ (file-name-base tl))
+ ""))
+ (album (or (alist-get 'album current) ""))
+ (track (or (alist-get 'track current) ""))
+ (times (jao-mpc--current-timestr t current)))
+ (jao-notify (format "%s -- %s" artist times)
+ (format "%s %s" track title)
+ jao-notify-audio-icon
+ album))))
+
+;;;###autoload
(defun jao-mpc-add-url (url)
(interactive "sURL: ")
(jao-mpc--cmd (format "add %s" url)))
@@ -311,8 +340,7 @@
(setq jao-lyrics-info-function #'jao-mpc-lyrics-track-data)
(jao-random-album-setup #'jao-mpc--album-buffer
#'jao-mpc--add-and-play
- #'jao-mpc-stop
- jao-notify-audio-icon)
+ #'jao-mpc-stop)
(let ((jao-random-album-active nil)) (jao-mpc-connect))
(when secondary-port (jao-mpc-connect secondary-port))
(when priority
@@ -332,7 +360,7 @@
(jao-mpc--cmd jao-mpc--simple-albums-cmd port)
albums-str))
(albums (split-string albums-str "\n" t)))
- (when-let (album (completing-read "Play album: " albums nil t))
+ (when-let* ((album (completing-read "Play album: " albums nil t)))
(jao-mpc--add-and-play (car (split-string album "-" t " ")) port))))
(provide 'jao-mpc)
diff --git a/lib/media/jao-mpris.el b/lib/media/jao-mpris.el
index 3bb2636..7331cf3 100644
--- a/lib/media/jao-mpris.el
+++ b/lib/media/jao-mpris.el
@@ -1,6 +1,6 @@
;;; jao-mpris.el --- mpris players control -*- lexical-binding: t; -*-
-;; Copyright (C) 2020, 2021, 2022, 2024 jao
+;; Copyright (C) 2020, 2021, 2022, 2024, 2025, 2026 jao
;; Author: jao <mail@jao.io>
;; Keywords: multimedia
@@ -97,7 +97,7 @@
jao-mpris--current nil))
(defun jao-mpris--get (k &optional l)
- (when-let (v (alist-get k (or l jao-mpris--current)))
+ (when-let* ((v (alist-get k (or l jao-mpris--current))))
(if (consp v) (car v) v)))
(defun jao-mpris--set-current (k v)
@@ -158,25 +158,25 @@
(defun jao-mpris--handler (iname properties &rest _args)
(let ((inhibit-message t))
- (message "Received properties: %S from %s" properties iname))
- (when-let (md (caadr (assoc "Metadata" properties)))
- (let ((tno (caadr (assoc "xesam:trackNumber" md)))
- (tlt (caadr (assoc "xesam:title" md)))
- (art (caadr (assoc "xesam:artist" md)))
- (alb (caadr (assoc "xesam:album" md)))
- (len (caadr (assoc "mpris:length" md))))
- (if (string= (or tlt "") "TIDAL")
- (jao-mpris-reset)
+ (message "Received properties: %S from %s" properties iname)
+ (when-let* ((md (caadr (assoc "Metadata" properties))))
+ (let ((tno (caadr (assoc "xesam:trackNumber" md)))
+ (tlt (caadr (assoc "xesam:title" md)))
+ (art (caadr (assoc "xesam:artist" md)))
+ (alb (caadr (assoc "xesam:album" md)))
+ (len (caadr (assoc "mpris:length" md))))
(jao-mpris--set-current 'track tno)
(jao-mpris--set-current 'title tlt)
(jao-mpris--set-current 'artist art)
(jao-mpris--set-current 'album alb)
- (jao-mpris--set-current 'length len))))
- (when-let (st (caadr (assoc "PlaybackStatus" properties)))
- (jao-mpris--set-current 'status st)
- (when (string= st "Stopped")
- (dolist (k '(track title artist album length))
- (jao-mpris--del-current k))))
+ (jao-mpris--set-current 'length len)))
+ (when-let* ((st (caadr (assoc "PlaybackStatus" properties))))
+ (jao-mpris--set-current 'status st)
+ (when (string= st "Stopped")
+ (dolist (k '(track title artist album length))
+ (jao-mpris--del-current k))))
+ ;; (message "Current is: %S" jao-mpris--current)
+ )
(jao-mpris--track jao-mpris--current))
;;;###autoload
diff --git a/lib/media/jao-random-album.el b/lib/media/jao-random-album.el
index 5b10308..cfe9080 100644
--- a/lib/media/jao-random-album.el
+++ b/lib/media/jao-random-album.el
@@ -1,6 +1,6 @@
-;; jao-random-album.el -- play random albums
+;; jao-random-album.el -- play random albums -*- lexical-binding: t; -*-
-;; Copyright (C) 2009, 2010, 2017-2019, 2021-2022, 2024 Jose Antonio Ortega Ruiz
+;; Copyright (C) 2009, 2010, 2017-2019, 2021-2022, 2024, 2026 Jose Antonio Ortega Ruiz
;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
;; Start date: Sat Jul 04, 2009 13:06
@@ -18,38 +18,32 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
-(require 'jao-notify)
+(require 'multisession)
(defvar jao-random-album-active t)
-(defvar jao-random-lines nil)
-(defvar jao-random-lines-file (expand-file-name "~/.emacs.d/random-lines"))
-(defvar jao-random-album-notify t)
-(defvar jao-random-album-notify-icon jao-notify-audio-icon)
+(defvar jao-random-album-notify nil)
(defvar jao-random-album-skip-lines 2)
+(define-multisession-variable jao-random-lines nil)
+
+(defun jao-random-album--buffer-lines ()
+ (let ((lines nil))
+ (dotimes (n (1- (line-number-at-pos (point-max))) lines)
+ (when (> n jao-random-album-skip-lines)
+ (push (1+ n) lines)))))
+
(defun jao-random-lines ()
- (or jao-random-lines
- (and (file-exists-p jao-random-lines-file)
- (with-current-buffer
- (find-file-noselect jao-random-lines-file)
- (goto-char (point-min))
- (setq jao-random-lines (read (current-buffer)))))
- (dotimes (n (1- (line-number-at-pos (point-max)))
- jao-random-lines)
- (when (> n jao-random-album-skip-lines)
- (push (1+ n) jao-random-lines)))))
-
-(defun jao-random-lines-save ()
- (with-current-buffer (find-file-noselect jao-random-lines-file)
- (delete-region (point-min) (point-max))
- (insert (format "%s\n" jao-random-lines))
- (save-buffer)))
+ (or (multisession-value jao-random-lines)
+ (jao-random-lines-save (jao-random-album--buffer-lines))))
+
+(defun jao-random-lines-save (v)
+ (setf (multisession-value jao-random-lines) v))
(defun jao-goto-random-album ()
- (let* ((pos (random (length (jao-random-lines))))
- (line (nth pos jao-random-lines)))
- (setq jao-random-lines (remove line jao-random-lines))
- (jao-random-lines-save)
+ (let* ((lines (jao-random-lines))
+ (pos (random (length lines)))
+ (line (nth pos lines)))
+ (jao-random-lines-save (remove line lines))
(goto-line line)))
@@ -81,18 +75,16 @@
(let ((album (string-trim (thing-at-point 'line))))
(funcall jao-random-album-add-tracks-and-play album)
(when jao-random-album-notify
- (jao-notify album "Next album" jao-random-album-notify-icon)))))
+ (funcall jao-random-album-notify album)))))
(defun jao-random-album-reset ()
(interactive)
- (setq jao-random-lines nil)
- (jao-random-lines-save))
+ (jao-random-lines-save nil))
-(defun jao-random-album-setup (album-buffer add-and-play stop &optional icon)
+(defun jao-random-album-setup (album-buffer add-and-play stop)
(setq jao-random-album-buffer album-buffer
jao-random-album-add-tracks-and-play add-and-play
- jao-random-album-stop stop
- jao-random-album-notify-icon icon))
+ jao-random-album-stop stop))
(provide 'jao-random-album)