diff options
| author | Julian Hurst <julian.hurst92@gmail.com> | 2020-07-06 20:58:02 +0200 |
|---|---|---|
| committer | Julian Hurst <julian.hurst92@gmail.com> | 2020-07-06 20:58:02 +0200 |
| commit | 7f375f1a5aea467550939a769d583c72eca4e8fe (patch) | |
| tree | 3cad98a3e59521b8de0bd63a8a1cc7923b64749b /statusbar.go | |
| parent | bf06d88d6b342c67f8b5d8cbdba0055256a61c65 (diff) | |
| download | statusbar-7f375f1a5aea467550939a769d583c72eca4e8fe.tar.gz | |
Add host and port support for MPD
Diffstat (limited to 'statusbar.go')
| -rw-r--r-- | statusbar.go | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/statusbar.go b/statusbar.go index a12c2ce..7cbbf18 100644 --- a/statusbar.go +++ b/statusbar.go @@ -19,7 +19,11 @@ type MusicPlayer interface { status() int } -type MPD struct{} +type MPD struct{ + Host string + Port int +} + type MOCP struct{} type Config struct { @@ -48,6 +52,8 @@ type MusicConfig struct { LabelPaused string `toml:"labelpaused"` LabelStopped string `toml:"labelstopped"` Type string + Host string + Port int } type ClockConfig struct { @@ -135,7 +141,7 @@ func clock(format string) string { } func (mpd MPD) nowPlaying() string { - cmd := exec.Command("mpc", "current") + cmd := exec.Command("mpc", "-h", mpd.Host, "-p", strconv.Itoa(mpd.Port), "current") out, err := cmd.Output() if err != nil { panic(err) @@ -147,7 +153,7 @@ func (mpd MPD) nowPlaying() string { // Returns 0 if playing, 1 if paused and 2 otherwise func (mpd MPD) status() int { - cmd := exec.Command("mpc", "status") + cmd := exec.Command("mpc", "-h", mpd.Host, "-p", strconv.Itoa(mpd.Port), "status") out, err := cmd.Output() if err != nil { return -1 @@ -221,7 +227,15 @@ func buildMusic(config MusicConfig) string { var player MusicPlayer switch config.Type { case "mpd": - player = MPD{} + host := config.Host + if host == "" { + host = "127.0.0.1" + } + port := config.Port + if port == 0 { + port = 6600 + } + player = MPD{Host: host, Port: port} case "mocp": player = MOCP{} default: |
