aboutsummaryrefslogtreecommitdiff
path: root/cmd/mpd-scrobbler/main.go
blob: 99292257845b9629a521899154bf5991704bfeee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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)
		}
	}
}