diff options
Diffstat (limited to 'tools/mpd-stats/cmd')
-rw-r--r-- | tools/mpd-stats/cmd/mpd-scrobbler/main.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/mpd-stats/cmd/mpd-scrobbler/main.go b/tools/mpd-stats/cmd/mpd-scrobbler/main.go new file mode 100644 index 0000000..9929225 --- /dev/null +++ b/tools/mpd-stats/cmd/mpd-scrobbler/main.go @@ -0,0 +1,35 @@ +package main + +import ( + "log" + + "golang.fcuny.net/mpd-stats/internal/mpd" +) + +func main() { + net := "tcp" + addr := "localhost:6600" + + c, err := mpd.NewMPD(net, addr) + if err != nil { + log.Fatalf("failed to create a client: %v", err) + } + + defer c.Watcher.Close() + defer c.Client.Close() + + for { + e := <-c.Watcher.Event + if e != "" { + attrs, err := c.Client.CurrentSong() + if err != nil { + log.Fatalf("could not get current song: %v", err) + } + currentAlbum := attrs["Album"] + artist := attrs["Artist"] + song := attrs["Title"] + duration := attrs["duration"] + log.Printf("we're playing %s/%s/%s [%s]\n", artist, currentAlbum, song, duration) + } + } +} |