diff --git a/internal/radio/icecast.go b/internal/radio/icecast.go index 117787c..2ad69b9 100644 --- a/internal/radio/icecast.go +++ b/internal/radio/icecast.go @@ -22,7 +22,7 @@ const ( ) var ( - lastPlayedCache []Song = make([]Song, 10) + lastPlayedCache []Song lastPlayedCacheMutex sync.Mutex ) @@ -204,8 +204,15 @@ 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 { - lastPlayedCache = songs + if lastPlayedCache == nil { + lastPlayedCache = make([]Song, n) + } + 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 {