Add rAudio detection and MPD playback support
This commit is contained in:
6 files changed
+96
No files matched your search
@@ -139,6 +139,10 @@ player {
|
|||||||
# Auto detect the player.
|
# Auto detect the player.
|
||||||
type = "auto"
|
type = "auto"
|
||||||
|
|
||||||
|
## rAudio (also detected automatically on local installations)
|
||||||
|
# type = "raudio"
|
||||||
|
# host = "localhost:6600"
|
||||||
|
|
||||||
## Music Player Daemon
|
## Music Player Daemon
|
||||||
# type = "mpd"
|
# type = "mpd"
|
||||||
# host = "localhost:6600"
|
# host = "localhost:6600"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package all
|
|||||||
import (
|
import (
|
||||||
_ "github.com/BeatGlow/beatglow/player/moode"
|
_ "github.com/BeatGlow/beatglow/player/moode"
|
||||||
_ "github.com/BeatGlow/beatglow/player/mpd"
|
_ "github.com/BeatGlow/beatglow/player/mpd"
|
||||||
|
_ "github.com/BeatGlow/beatglow/player/raudio"
|
||||||
_ "github.com/BeatGlow/beatglow/player/runeaudio"
|
_ "github.com/BeatGlow/beatglow/player/runeaudio"
|
||||||
_ "github.com/BeatGlow/beatglow/player/volumio"
|
_ "github.com/BeatGlow/beatglow/player/volumio"
|
||||||
)
|
)
|
||||||
@@ -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()
|
||||||
|
}
|
||||||
@@ -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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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() }
|
||||||
@@ -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())
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user