Populate a freshly created cache with songs if there are any.
This commit is contained in:
parent
7df94bef12
commit
075e171b40
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user