diff --git a/internal/radio/mostlistened.go b/internal/radio/mostlistened.go index f38395c..7e6d397 100644 --- a/internal/radio/mostlistened.go +++ b/internal/radio/mostlistened.go @@ -2,6 +2,7 @@ package radio import ( "bytes" + "encoding/json" "errors" "strconv" "time" @@ -21,6 +22,17 @@ func (mls *MostListenedSong) DateString() string { return mls.Date.Format(MostListenedDateFormat) } +func (mls *MostListenedSong) MarshalJSON() ([]byte, error) { + return json.Marshal(&struct { + Song string `json:"song"` + Listeners int `json:"listeners"` + Date string `json:"date"` + }{ + Song: mls.Song, + Listeners: mls.Listeners, + Date: mls.Date.UTC().Format(time.RFC3339)}) +} + var mostListened MostListenedSong // CheckAndUpdateMostListenedSong compares current most played song with