From 075e171b40a92df99447cef7419cff04e544456b Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 20 Aug 2023 03:26:14 +0400 Subject: [PATCH] Populate a freshly created cache with songs if there are any. --- internal/radio/icecast.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/radio/icecast.go b/internal/radio/icecast.go index 362b969..ad33636 100644 --- a/internal/radio/icecast.go +++ b/internal/radio/icecast.go @@ -5,6 +5,7 @@ import ( "dwelling-radio/pkg/watcher" "encoding/json" "io" + "log" "net/http" "os" "sync" @@ -129,6 +130,8 @@ func icecastLastPlayedSongs(playlistPath string, n int) ([]Song, error) { return nil, err } + log.Println(playlistPath, buf) + lines := bytes.Split(buf, []byte("\n")) if len(lines) < 2 { @@ -185,6 +188,9 @@ func (pw *PlaylistLogWatcher) Watch(playlistPath string, n int) (err error) { if lastPlayedCache == nil { lastPlayedCache = make([]Song, 0, n) + if songs, err := icecastLastPlayedSongs(playlistPath, n); err == nil && len(songs) > 0 { + lastPlayedCache = append(lastPlayedCache, songs...) + } } go func() {