From e5ff8adc294cecbe6c791e5c4e2c09cb95dd4e9c Mon Sep 17 00:00:00 2001 From: Bubblegumdrop Date: Sat, 28 Sep 2024 14:52:50 -0400 Subject: [PATCH] Initial commit for git.lain.church --- build.lisp | 3 ++ cl-mpd-runner.asd | 18 ++++++++ cl-mpd.diff | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ makefile | 14 ++++++ runner.lisp | 37 +++++++++++++++ test-client.lisp | 52 ++++++++++++++++++++++ 6 files changed, 255 insertions(+) create mode 100644 build.lisp create mode 100644 cl-mpd-runner.asd create mode 100644 cl-mpd.diff create mode 100644 makefile create mode 100644 runner.lisp create mode 100644 test-client.lisp diff --git a/build.lisp b/build.lisp new file mode 100644 index 0000000..8360610 --- /dev/null +++ b/build.lisp @@ -0,0 +1,3 @@ +(load "cl-mpd-runner.asd") +(asdf:load-system :cl-mpd-runner) +(asdf:make 'cl-mpd-runner) diff --git a/cl-mpd-runner.asd b/cl-mpd-runner.asd new file mode 100644 index 0000000..601d5b2 --- /dev/null +++ b/cl-mpd-runner.asd @@ -0,0 +1,18 @@ +(in-package #:cl-user) + +(defparameter +cl-mpd-directory+ + "/var/www/html/cgi/cl-mpd-runner/cl-mpd/") +(require 'asdf) +(pushnew +cl-mpd-directory+ asdf:*central-registry*) + +(asdf:defsystem :cl-mpd-runner + :version "0.0.1" + :author "Charlie Svitlik " + :description "CL-MPD-RUNNER: Music Player Daemon runner." + :defsystem-depends-on (:deploy) ;; so you need to quickload deploy sometime before. + :build-operation "deploy-op" ;; instead of program-op for asdf:make + :build-pathname "cl-mpd-runner" + :entry-point "cl-mpd-runner::main" + :depends-on (:mpd) + :components + ((:file "runner"))) diff --git a/cl-mpd.diff b/cl-mpd.diff new file mode 100644 index 0000000..693c63a --- /dev/null +++ b/cl-mpd.diff @@ -0,0 +1,131 @@ +diff --git a/mpdclient.lisp b/mpdclient.lisp +index 8398ff8..408ae44 100644 +--- a/mpdclient.lisp ++++ b/mpdclient.lisp +@@ -25,8 +25,8 @@ + (eval-when (:compile-toplevel :load-toplevel) + (declaim (optimize (speed 0) (space 0) (safety 1) (debug 3) (compilation-speed 0)))) + +-(defpackage #:mpd +- (:use #:cl)) ++;; (defpackage #:mpd ++;; (:use #:cl)) + + (in-package #:mpd) + +@@ -35,7 +35,7 @@ + #+sbcl (require :sb-bsd-sockets) + #+lispworks (require "comm")) + +-(defconstant +mpd-welcome-message+ "OK MPD ") ++(defvar +mpd-welcome-message+ "OK MPD ") + ;;; These aren't used yet, but will be soon. + (defconstant +mpd-error-not-list+ 1) + (defconstant +mpd-error-arg+ 2) +@@ -578,13 +578,11 @@ + + (defclass mpd-client () + ((iostream +- :initform nil + :initarg :iostream + :accessor mpd-iostream + :type iostream + :documentation "The input/output stream to MPD.") + (socket +- :initform nil + :initarg :socket + :accessor mpd-socket + :type socket +@@ -790,7 +788,6 @@ + :type integer + :documentation "Current song stopped on or playing, playlist songid.") + (time +- :initform 0 + :initarg :time + :accessor mpd-status-time + :type string +@@ -808,7 +805,6 @@ + :type integer + :documentation "Crossfade in seconds.") + (audio +- :initform nil + :initarg :audio + :accessor mpd-status-audio + :type string +@@ -881,55 +877,47 @@ + + (defclass mpd-song () + ((file +- :initform nil + :initarg :file + :accessor mpd-song-file + :type string + :documentation "Relative pathname of the the current playing/paused song.") + (artist +- :initform nil + :initarg :artist + :accessor mpd-song-artist + :type string + :documentation "Song artist, may be nil.") + (title +- :initform nil + :initarg :title + :accessor mpd-song-title + :type string + :documentation "Song title, may be nil.") + (album +- :initform nil + :initarg :album + :accessor mpd-song-album + :type string + :documentation "Song album, may be nil.") + (track +- :initform nil + :initarg :track + :accessor mpd-song-track + :type string + :documentation "Song track, may be nil.") + (name +- :initform nil ++ :initform "" + :initarg :name + :accessor mpd-song-name + :type string + :documentation "Song name, may be nil.") + (date +- :initform nil + :initarg :date + :accessor mpd-song-date + :type string + :documentation "I'm not sure wtf this is here for...?") + (genre +- :initform nil + :initarg :genre + :accessor mpd-song-genre + :type string + :documentation "Song's genre.") + (composer +- :initform nil + :initarg :composer + :accessor mpd-song-composer + :type string +@@ -941,7 +929,6 @@ + :type integer + :documentation "Song length in seconds.") + (position +- :initform nil + :initarg :position + :accessor mpd-song-position + :type integer +@@ -953,7 +940,7 @@ + :type integer + :documentation "Song ID for a song in the playlist.") + (initialized +- :initform nil ++ :initform 0 + :accessor mpd-song-initialized + :type integer + :documentation "0 or 1: Keeps tabs on if this object has been initialized."))) +diff --git a/systems.csv b/systems.csv +new file mode 100644 +index 0000000..e69de29 diff --git a/makefile b/makefile new file mode 100644 index 0000000..e5a394a --- /dev/null +++ b/makefile @@ -0,0 +1,14 @@ +all: install + +install: ../cl-mpd-runner.bin + +bin/cl-mpd-runner: build.lisp cl-mpd-runner.asd runner.lisp test-client.lisp + sbcl --load $^ + +../cl-mpd-runner.bin: bin/cl-mpd-runner + mv $< $@ + +clean: + $(RM) -rf *~ bin + +.PHONY: all install diff --git a/runner.lisp b/runner.lisp new file mode 100644 index 0000000..2d2ed48 --- /dev/null +++ b/runner.lisp @@ -0,0 +1,37 @@ +(in-package #:cl-user) + +(defpackage #:cl-mpd-runner + (:use #:cl) + (:export #:main)) + +(in-package #:cl-mpd-runner) + +(load #P"test-client.lisp") + +(defun content-type (type) + (format t "Content-Type:~a~%~%" type)) + +(defun setup-mpd-environment (&key (host "localhost") (port "6600")) + (setf (uiop:getenv "MPD_HOST") host + (uiop:getenv "MPD_PORT") port)) + +;; Excuse the mess. +(defun html-header () + (format t " + + Now Playing - MPD Status +
")) + +(defun html-footer () + (format t "
")) + +(defun main () + (setup-mpd-environment :host "10.99.99.2") + (content-type "text/html; charset=utf-8") + (html-header) + (mpd::clos-client) + (html-footer)) + ;; (format t "~{~a~^~%~}~%" (sb-ext:posix-environ))) +;; (format t "~a~%" (probe-file "/var/www/html/cgi/cl-mpd/")) +;; (format t "~a~%" asdf:*central-registry*) +;; (format t "~a" (sb-unix::posix-getenv "HTTP_USER_AGENT"))) diff --git a/test-client.lisp b/test-client.lisp new file mode 100644 index 0000000..26914bc --- /dev/null +++ b/test-client.lisp @@ -0,0 +1,52 @@ +(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 "~&

Now Playing

") + (format t "~&

Created with CL-MPD

") + (with-mpd-client-slots (client) + ;; L56 + (with-mpd-status-slots (status) + (mpd-update-status client status) + (format t "~&

Slot values for STATUS contains...

") + (format t "~&volume: ~S ~%repeat: ~S ~%random: ~S ~%playlist: ~S" + volume repeat random playlist) + (format t "~%playlistlength: ~S ~%xfade: ~S ~%state: ~S ~%song: ~S ~%songid: ~S" + playlist-length xfade state song songid) + (setf maybe-song-in-playlist-index song) + (format t "~%time: ~S ~%bitrate: ~S ~%audio: ~S ~%updating_db: ~S ~%error: ~S" + 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) + "> " + " ") + (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 "~&

Playlist

") + ;; L116 + (with-mpd-song-slots (song) + (mpd-update-song client song) + (format t "~&Artist:~A~A~%~&Title:~A~A~%Album:~A~A~%~%" + #\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)))