about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tools/mpd-stats/cmd/mpd-scrobbler/main.go7
-rw-r--r--tools/mpd-stats/internal/mpd/mpd.go10
2 files changed, 15 insertions, 2 deletions
diff --git a/tools/mpd-stats/cmd/mpd-scrobbler/main.go b/tools/mpd-stats/cmd/mpd-scrobbler/main.go
index 3953123..ba7bb05 100644
--- a/tools/mpd-stats/cmd/mpd-scrobbler/main.go
+++ b/tools/mpd-stats/cmd/mpd-scrobbler/main.go
@@ -16,8 +16,11 @@ func main() {
 		log.Fatalf("failed to create a client: %v", err)
 	}
 
-	defer c.Watcher.Close()
-	defer c.Client.Close()
+	defer func() {
+		if err := c.Close(); err != nil {
+			log.Fatalf("failed to close the player: %v", err)
+		}
+	}()
 
 	var (
 		currentRecord  *scrobbler.Record
diff --git a/tools/mpd-stats/internal/mpd/mpd.go b/tools/mpd-stats/internal/mpd/mpd.go
index ed9d3c2..cebf2b2 100644
--- a/tools/mpd-stats/internal/mpd/mpd.go
+++ b/tools/mpd-stats/internal/mpd/mpd.go
@@ -36,3 +36,13 @@ func NewPlayer(net string, addr string) (*player, error) {
 
 	return &p, nil
 }
+
+func (p *player) Close() error {
+	if err := p.Watcher.Close(); err != nil {
+		return err
+	}
+	if err := p.Client.Close(); err != nil {
+		return err
+	}
+	return nil
+}