diff --git a/internal/radio/icecast.go b/internal/radio/icecast.go index 905e5b9..018674f 100644 --- a/internal/radio/icecast.go +++ b/internal/radio/icecast.go @@ -65,19 +65,20 @@ func IcecastGetStatus(icecastURL string) (*IcecastStatus, error) { } func IcecastLastPlayedSongs(lastNSongs int, playlistPath string) ([]Song, error) { - if len(lastPlayedCache) > 0 { - if lastNSongs > len(lastPlayedCache) { - lastNSongs = len(lastPlayedCache) + + if lpcLen := len(lastPlayedCache); lpcLen > 0 { + if lastNSongs > lpcLen { + lastNSongs = lpcLen } - return lastPlayedCache[len(lastPlayedCache)-lastNSongs:], nil + return lastPlayedCache[lpcLen-lastNSongs:], nil } return lastPlayedSongs(lastNSongs, playlistPath) } func IcecastLastSong(playlistPath string) (Song, error) { - if len(lastPlayedCache) > 0 { - return lastPlayedCache[len(lastPlayedCache)-1], nil + if lpcLen := len(lastPlayedCache); lpcLen > 0 { + return lastPlayedCache[lpcLen-1], nil } songs, err := lastPlayedSongs(1, playlistPath)