about summary refs log tree commit diff
path: root/tools/mpd-stats/internal
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tools/mpd-stats/internal/mpd/mpd.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/tools/mpd-stats/internal/mpd/mpd.go b/tools/mpd-stats/internal/mpd/mpd.go
new file mode 100644
index 0000000..8991adc
--- /dev/null
+++ b/tools/mpd-stats/internal/mpd/mpd.go
@@ -0,0 +1,38 @@
+package mpd
+
+import (
+	"log"
+	"time"
+
+	"github.com/fhs/gompd/v2/mpd"
+)
+
+type player struct {
+	Watcher *mpd.Watcher
+	Client  *mpd.Client
+}
+
+func NewMPD(net string, addr string) (*player, error) {
+	var (
+		p   player
+		err error
+	)
+
+	p.Watcher, err = mpd.NewWatcher(net, addr, "", "player")
+	if err != nil {
+		log.Fatalf("failed to create a watcher: %v", err)
+	}
+
+	p.Client, err = mpd.Dial(net, addr)
+	if err != nil {
+		log.Fatalf("failed to start mpd client: %v", err)
+	}
+
+	go func() {
+		for range time.Tick(30 * time.Second) {
+			p.Client.Ping()
+		}
+	}()
+
+	return &p, nil
+}