aboutsummaryrefslogtreecommitdiff
path: root/internal/scrobbler
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2021-10-09 18:16:15 -0700
committerFranck Cuny <franck@fcuny.net>2021-10-09 18:21:58 -0700
commit49480621b580a4676109e2012d6949ce478b8c8c (patch)
tree4f6a6391fec9b8d15aa6c19f5fee1d7369f474df /internal/scrobbler
parentscrobbler: watch for events and print song details (diff)
downloadx-49480621b580a4676109e2012d6949ce478b8c8c.tar.gz
scrobbler: initial log record type
Define the type for a log record and add an helper function to create a new record.
Diffstat (limited to 'internal/scrobbler')
-rw-r--r--internal/scrobbler/record.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/scrobbler/record.go b/internal/scrobbler/record.go
new file mode 100644
index 0000000..927ed27
--- /dev/null
+++ b/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
+}