1
0

Added log for failed attempts on retrieving songs from playlist.log.

This commit is contained in:
Alexander Andreev 2023-08-20 18:03:51 +04:00
parent 48bbd32eb8
commit f9b2afdd50
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -5,6 +5,7 @@ import (
"dwelling-radio/pkg/watcher"
"encoding/json"
"io"
"log"
"net/http"
"os"
"sync"
@ -185,8 +186,11 @@ 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 {
songs, err := icecastLastPlayedSongs(playlistPath, n)
if err == nil && len(songs) > 0 {
lastPlayedCache = append(lastPlayedCache, songs...)
} else if err != nil {
log.Fatalln("Failed to retrieve last songs:", err)
}
}
@ -196,7 +200,8 @@ 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, 1); err == nil && len(songs) > 0 {
songs, err := icecastLastPlayedSongs(playlistPath, 1)
if err == nil && len(songs) > 0 {
CheckAndUpdateMostListenedSong(songs[0], currentlyPlaying)
if currentlyPlaying.Time == "" {
currentlyPlaying = songs[0]
@ -209,6 +214,8 @@ func (pw *PlaylistLogWatcher) Watch(playlistPath string, n int) (err error) {
}
currentlyPlaying = songs[0]
}
} else if err != nil {
log.Println("Failed to retrieve last songs:", err)
}
lastPlayedCacheMutex.Unlock()
} else if mask&syscall.IN_IGNORED > 0 {