From b82ad75ec46005f15f7349e01b4d6c2773e2dbd4 Mon Sep 17 00:00:00 2001 From: Wijnand Modderman-Lenstra Date: Thu, 29 Oct 2026 17:28:13 +0100 Subject: [PATCH] Add rAudio detection and MPD playback support --- beatglow.conf | 4 ++++ player/all/all.go | 1 + player/raudio/detect.go | 17 +++++++++++++++++ player/raudio/detect_test.go | 27 +++++++++++++++++++++++++++ player/raudio/player.go | 30 ++++++++++++++++++++++++++++++ player/raudio/player_test.go | 17 +++++++++++++++++ 6 files changed, 96 insertions(+) create mode 100644 player/raudio/detect.go create mode 100644 player/raudio/detect_test.go create mode 100644 player/raudio/player.go create mode 100644 player/raudio/player_test.go diff --git a/beatglow.conf b/beatglow.conf index 31fcb13..4ebddc3 100644 --- a/beatglow.conf +++ b/beatglow.conf @@ -139,6 +139,10 @@ player { # Auto detect the player. type = "auto" + ## rAudio (also detected automatically on local installations) + # type = "raudio" + # host = "localhost:6600" + ## Music Player Daemon # type = "mpd" # host = "localhost:6600" diff --git a/player/all/all.go b/player/all/all.go index 15adfa5..df16526 100644 --- a/player/all/all.go +++ b/player/all/all.go @@ -4,6 +4,7 @@ package all import ( _ "github.com/BeatGlow/beatglow/player/moode" _ "github.com/BeatGlow/beatglow/player/mpd" + _ "github.com/BeatGlow/beatglow/player/raudio" _ "github.com/BeatGlow/beatglow/player/runeaudio" _ "github.com/BeatGlow/beatglow/player/volumio" ) diff --git a/player/raudio/detect.go b/player/raudio/detect.go new file mode 100644 index 0000000..dab32f3 --- /dev/null +++ b/player/raudio/detect.go @@ -0,0 +1,17 @@ +package raudio + +import ( + "io/fs" + "os" +) + +// Detect reports whether rAudio is installed locally. +func Detect() bool { + return detect(os.DirFS("/")) +} + +func detect(root fs.FS) bool { + // rAudio stores its core environment variables in this configuration file. + info, err := fs.Stat(root, "srv/http/data/system/system.conf") + return err == nil && info.Mode().IsRegular() +} diff --git a/player/raudio/detect_test.go b/player/raudio/detect_test.go new file mode 100644 index 0000000..8efd6f6 --- /dev/null +++ b/player/raudio/detect_test.go @@ -0,0 +1,27 @@ +package raudio + +import ( + "io/fs" + "testing" + "testing/fstest" +) + +func TestDetect(t *testing.T) { + for _, tt := range []struct { + name string + root fstest.MapFS + want bool + }{ + {"installed", fstest.MapFS{"srv/http/data/system/system.conf": {}}, true}, + {"missing", fstest.MapFS{}, false}, + {"directory", fstest.MapFS{"srv/http/data/system/system.conf": {Mode: fs.ModeDir}}, false}, + {"idle handler only", fstest.MapFS{"srv/http/bash/mpdidle.sh": {}}, false}, + {"RuneAudio", fstest.MapFS{"srv/http/command/rune_shutdown": {}}, false}, + } { + t.Run(tt.name, func(t *testing.T) { + if got := detect(tt.root); got != tt.want { + t.Fatalf("detect() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/player/raudio/player.go b/player/raudio/player.go new file mode 100644 index 0000000..d1cfa22 --- /dev/null +++ b/player/raudio/player.go @@ -0,0 +1,30 @@ +// Package raudio detects rAudio installations and controls playback through MPD. +package raudio + +import ( + "github.com/BeatGlow/beatglow/config" + "github.com/BeatGlow/beatglow/player" + "github.com/BeatGlow/beatglow/player/mpd" +) + +func init() { + player.Register("raudio", func(config *config.Player) (player.Player, error) { + return New(config) + }, Detect, 1) +} + +type Player struct { + *mpd.Player +} + +func New(config *config.Player) (*Player, error) { + p, err := mpd.New(config.Host, config.Password) + if err != nil { + return nil, err + } + return &Player{Player: p}, nil +} + +func (p *Player) Name() string { return "rAudio" } + +func (p *Player) String() string { return "rAudio@" + p.Player.String() } diff --git a/player/raudio/player_test.go b/player/raudio/player_test.go new file mode 100644 index 0000000..8044f90 --- /dev/null +++ b/player/raudio/player_test.go @@ -0,0 +1,17 @@ +package raudio + +import ( + "github.com/BeatGlow/beatglow/config" + "github.com/BeatGlow/beatglow/player" + "testing" +) + +func TestRegisteredPlayer(t *testing.T) { + p, err := player.New(&config.Player{Type: "raudio", Host: "localhost:6601"}) + if err != nil { + t.Fatal(err) + } + if p.Name() != "rAudio" || p.String() != "rAudio@mpd@localhost:6601" { + t.Fatalf("unexpected player: %s (%s)", p.Name(), p.String()) + } +}