cl-mpd-runner/test-client.lisp
2024-10-03 00:14:06 -04:00

53 lines
2.2 KiB
Common Lisp

(in-package #:mpd)
(defparameter mpd::*debug-on* nil)
(defun clos-client ()
(let ((client (make-instance 'mpd-client))
(status (make-instance 'mpd-status))
(song (make-instance 'mpd-song :position 1))
(maybe-song-in-playlist-index 0))
(format t "~&<h1 class='title'>Now Playing</h1>")
(format t "~&<p class='subtitle'>Created with <a href='https://cl-mpd.common-lisp.dev/'>CL-MPD</a></p>")
(with-mpd-client-slots (client)
;; L56
(with-mpd-status-slots (status)
(mpd-update-status client status)
(format t "~&<p>Slot values for STATUS contains...<p>")
(format t "~&<code>volume: ~S ~%repeat: ~S ~%random: ~S ~%playlist: ~S</code>"
volume repeat random playlist)
(format t "~%<code>playlistlength: ~S ~%xfade: ~S ~%state: ~S ~%song: ~S ~%songid: ~S</code>"
playlist-length xfade state song songid)
(setf maybe-song-in-playlist-index song)
(format t "~%<code>time: ~S ~%bitrate: ~S ~%audio: ~S ~%updating_db: ~S ~%error: ~S</code>"
time bitrate audio updating-db error))
;; L87
(let* ((cnt (mpd-status-playlist-length status))
(table (make-hash-table :size cnt))
(current-song-index 0))
(flet ((maybe-its-the-song ()
(if (= current-song-index maybe-song-in-playlist-index)
"&gt; "
" ")
(incf current-song-index)))
(dotimes (i cnt)
(let ((obj (make-instance 'mpd-song :position i)))
(mpd-update-song client obj)
(setf (gethash i table) obj)))
(format t "~&<h2>Playlist</h2><ul>~%")
(maphash #'(lambda (key value)
(format t "<li>~&~a~S ~A</li>" (maybe-its-the-song) key (mpd-song-file value)))
table)))
(format t "</ul>")
;; L116
(with-mpd-song-slots (song)
(mpd-update-song client song)
(format t "~&<code>Artist:~A~A~%~&Title:~A~A~%Album:~A~A~%~%</code>"
#\Tab artist #\Tab title #\Tab album))
(mpd-client-disconnect client))))
(defun my-source ()
(let ((content (uiop:read-file-string #P"test-client.lisp")))
(format t "~a~%" content)))