diff --git a/internal/radio/icecast.go b/internal/radio/icecast.go index c6ce53c..9deb94e 100644 --- a/internal/radio/icecast.go +++ b/internal/radio/icecast.go @@ -181,10 +181,7 @@ func (pw *PlaylistLogWatcher) Watch(playlistPath string, n int) (err error) { pw.watcher.WatchForMask(pw.changed, watcher.ModIgnMask) - lastPlayedCache, err = icecastLastPlayedSongs(playlistPath, n) - if err != nil { - return errors.Wrap(err, "cannot instantiate last played cache") - } + lastPlayedCache = make([]Song, 0, n) go func() { for { @@ -192,8 +189,12 @@ func (pw *PlaylistLogWatcher) Watch(playlistPath string, n int) (err error) { case mask := <-pw.changed: if mask&syscall.IN_MODIFY > 0 { lastPlayedCacheMutex.Lock() - if songs, err := icecastLastPlayedSongs(playlistPath, n); err == nil && len(songs) > 0 { - lastPlayedCache = songs + if songs, err := icecastLastPlayedSongs(playlistPath, 1); err == nil && len(songs) > 0 { + if len(lastPlayedCache) == n { + lastPlayedCache = append(lastPlayedCache[1:], songs...) + } else { + lastPlayedCache = append(lastPlayedCache, songs...) + } } lastPlayedCacheMutex.Unlock() } else if mask&syscall.IN_IGNORED > 0 {