updating readme
This commit is contained in:
parent
351b17db69
commit
9fb8d1f248
62
README.md
62
README.md
|
@ -28,7 +28,7 @@ Because I run an online D&D game, which includes a background music stream f
|
||||||
|
|
||||||
## Quick Start (Server)
|
## Quick Start (Server)
|
||||||
|
|
||||||
This assumes you have a functioning icecast2 installation already.
|
This assumes you have a functioning icecast2/whatever installation already.
|
||||||
|
|
||||||
```
|
```
|
||||||
% sudo apt install libshout3-dev
|
% sudo apt install libshout3-dev
|
||||||
|
@ -41,6 +41,8 @@ This assumes you have a functioning icecast2 installation already.
|
||||||
|
|
||||||
Now start the server, which will begin streaming the `session_start` playlist:
|
Now start the server, which will begin streaming the `session_start` playlist:
|
||||||
|
|
||||||
|
## Controlling The Server
|
||||||
|
|
||||||
```
|
```
|
||||||
% croaker start
|
% croaker start
|
||||||
INFO Daemonizing controller on (localhost, 8003); pidfile and logs in ~/.dnd/croaker
|
INFO Daemonizing controller on (localhost, 8003); pidfile and logs in ~/.dnd/croaker
|
||||||
|
@ -83,14 +85,14 @@ OK
|
||||||
Skip this track and move on to the next:
|
Skip this track and move on to the next:
|
||||||
|
|
||||||
```
|
```
|
||||||
FFWD
|
ffwd
|
||||||
OK
|
OK
|
||||||
```
|
```
|
||||||
|
|
||||||
Stop the music:
|
Stop the music:
|
||||||
|
|
||||||
```
|
```
|
||||||
STOP
|
stop
|
||||||
OK
|
OK
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -101,3 +103,57 @@ kthx
|
||||||
KBAI
|
KBAI
|
||||||
Connection closed by foreign host.
|
Connection closed by foreign host.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Python Client Implementation
|
||||||
|
|
||||||
|
Here's a sample client using Ye Olde Socket Library:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import socket
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from functools import cached_property
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class CroakerClient():
|
||||||
|
host: str
|
||||||
|
port: int
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def playlists(self):
|
||||||
|
return self.send("LIST").split("\n")
|
||||||
|
|
||||||
|
def list(self, *args):
|
||||||
|
if not args:
|
||||||
|
return self.playlists
|
||||||
|
return self.send(f"LIST {args[0]}")
|
||||||
|
|
||||||
|
def play(self, *args):
|
||||||
|
if not args:
|
||||||
|
return "Error: Must specify the playlist to play."
|
||||||
|
return self.send(f"PLAY {args[0]}")
|
||||||
|
|
||||||
|
def ffwd(self, *args):
|
||||||
|
return self.send("FFWD")
|
||||||
|
|
||||||
|
def stop(self, *args):
|
||||||
|
return self.send("STOP")
|
||||||
|
|
||||||
|
def send(self, msg: str):
|
||||||
|
BUFSIZE = 4096
|
||||||
|
data = bytearray()
|
||||||
|
with socket.create_connection((self.host, self.port)) as sock:
|
||||||
|
sock.sendall(f"{msg}\n".encode())
|
||||||
|
while True:
|
||||||
|
buf = sock.recv(BUFSIZE)
|
||||||
|
data.extend(buf)
|
||||||
|
if len(buf) < BUFSIZE:
|
||||||
|
break
|
||||||
|
sock.sendall(b'KTHX\n')
|
||||||
|
return data.decode()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
client = CroakerClient(host='localhost', port=1234)
|
||||||
|
client.play('session_start')
|
||||||
|
```
|
||||||
|
|
Loading…
Reference in New Issue
Block a user