diff options
Diffstat (limited to 'internal/scrobbler/record.go')
| -rw-r--r-- | internal/scrobbler/record.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/internal/scrobbler/record.go b/internal/scrobbler/record.go new file mode 100644 index 0000000..e252fd3 --- /dev/null +++ b/internal/scrobbler/record.go @@ -0,0 +1,42 @@ +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 + Timestamp time.Time +} + +func NewRecord(attrs mpd.Attrs) (*Record, error) { + record := Record{ + Id: uuid.New(), + Title: attrs["Title"], + Album: attrs["Album"], + Artist: attrs["Artist"], + Timestamp: time.Now(), + } + + dur, err := strconv.ParseFloat(attrs["duration"], 32) + if err != nil { + return nil, err + } + + record.Duration = time.Second * time.Duration(dur) + return &record, nil +} + +func (r *Record) EqualAttrs(attrs mpd.Attrs) bool { + return r.Title == attrs["Title"] && + r.Album == attrs["Album"] && + r.Artist == attrs["Artist"] +} |
