1
0

Populate a freshly created cache with songs if there are any.

This commit is contained in:
Alexander Andreev 2023-08-20 03:26:14 +04:00
parent 7df94bef12
commit 075e171b40
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -5,6 +5,7 @@ import (
"dwelling-radio/pkg/watcher" "dwelling-radio/pkg/watcher"
"encoding/json" "encoding/json"
"io" "io"
"log"
"net/http" "net/http"
"os" "os"
"sync" "sync"
@ -129,6 +130,8 @@ func icecastLastPlayedSongs(playlistPath string, n int) ([]Song, error) {
return nil, err return nil, err
} }
log.Println(playlistPath, buf)
lines := bytes.Split(buf, []byte("\n")) lines := bytes.Split(buf, []byte("\n"))
if len(lines) < 2 { if len(lines) < 2 {
@ -185,6 +188,9 @@ func (pw *PlaylistLogWatcher) Watch(playlistPath string, n int) (err error) {
if lastPlayedCache == nil { if lastPlayedCache == nil {
lastPlayedCache = make([]Song, 0, n) lastPlayedCache = make([]Song, 0, n)
if songs, err := icecastLastPlayedSongs(playlistPath, n); err == nil && len(songs) > 0 {
lastPlayedCache = append(lastPlayedCache, songs...)
}
} }
go func() { go func() {