about summary refs log tree commit diff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/mpd-stats/go.mod5
-rw-r--r--tools/mpd-stats/go.sum2
-rw-r--r--tools/mpd-stats/internal/scrobbler/record.go34
3 files changed, 40 insertions, 1 deletions
diff --git a/tools/mpd-stats/go.mod b/tools/mpd-stats/go.mod
index cafa7bc..6ffe974 100644
--- a/tools/mpd-stats/go.mod
+++ b/tools/mpd-stats/go.mod
@@ -2,4 +2,7 @@ module golang.fcuny.net/mpd-stats
 
 go 1.17
 
-require github.com/fhs/gompd/v2 v2.2.0
+require (
+	github.com/fhs/gompd/v2 v2.2.0
+	github.com/google/uuid v1.3.0
+)
diff --git a/tools/mpd-stats/go.sum b/tools/mpd-stats/go.sum
index 1c3cda7..127090d 100644
--- a/tools/mpd-stats/go.sum
+++ b/tools/mpd-stats/go.sum
@@ -1,2 +1,4 @@
 github.com/fhs/gompd/v2 v2.2.0 h1:zdSYAAOzQ5cCCgYa5CoXkL0Vr0Cqb/b5JmTobirLc90=
 github.com/fhs/gompd/v2 v2.2.0/go.mod h1:nNdZtcpD5VpmzZbRl5rV6RhxeMmAWTxEsSIMBkmMIy4=
+github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
+github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
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
+}