about summary refs log tree commit diff
path: root/tools/mpd-stats/internal
diff options
context:
space:
mode:
Diffstat (limited to 'tools/mpd-stats/internal')
-rw-r--r--tools/mpd-stats/internal/scrobbler/record.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/tools/mpd-stats/internal/scrobbler/record.go b/tools/mpd-stats/internal/scrobbler/record.go
new file mode 100644
index 0000000..927ed27
--- /dev/null
+++ b/tools/mpd-stats/internal/scrobbler/record.go
@@ -0,0 +1,34 @@
+package scrobbler
+
+import (
+	"strconv"
+	"time"
+
+	"github.com/fhs/gompd/v2/mpd"
+	"github.com/google/uuid"
+)
+
+type Record struct {
+	Id       uuid.UUID
+	Title    string
+	Album    string
+	Artist   string
+	Duration time.Duration
+}
+
+func NewRecord(attrs mpd.Attrs) (*Record, error) {
+	record := Record{
+		Id:     uuid.New(),
+		Title:  attrs["Title"],
+		Album:  attrs["Album"],
+		Artist: attrs["Artist"],
+	}
+
+	dur, err := strconv.ParseFloat(attrs["duration"], 32)
+	if err != nil {
+		return nil, err
+	}
+
+	record.Duration = time.Second * time.Duration(dur)
+	return &record, nil
+}