Added a fallback song option. Altered a PlaylistNext() header to use it.
This commit is contained in:
parent
e0e5e314f1
commit
f0aa00b932
@ -20,6 +20,7 @@ var (
|
|||||||
listenAddress = flag.String("listen", "/var/run/dwelling-radio/sock", "listen address (ip:port|unix_path)")
|
listenAddress = flag.String("listen", "/var/run/dwelling-radio/sock", "listen address (ip:port|unix_path)")
|
||||||
filelistPath = flag.String("filelist", "/mnt/data/appdata/radio/filelist.html", "path to a filelist.html file")
|
filelistPath = flag.String("filelist", "/mnt/data/appdata/radio/filelist.html", "path to a filelist.html file")
|
||||||
playlist = flag.String("playlist", "", "path to a playlist")
|
playlist = flag.String("playlist", "", "path to a playlist")
|
||||||
|
fallbackSong = flag.String("fallback-song", "", "path to a fallbacl song")
|
||||||
mostListenedSongPath = flag.String("mls-file", "/mnt/data/appdata/radio/mostlistenedsong", "path to a file that stores info about the most listened song")
|
mostListenedSongPath = flag.String("mls-file", "/mnt/data/appdata/radio/mostlistenedsong", "path to a file that stores info about the most listened song")
|
||||||
songListLen = flag.Int("list-length", 10, "number of songs to show in last N songs table")
|
songListLen = flag.Int("list-length", 10, "number of songs to show in last N songs table")
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ func main() {
|
|||||||
|
|
||||||
r.ServeStatic("/assets/*filepath", web.Assets())
|
r.ServeStatic("/assets/*filepath", web.Assets())
|
||||||
|
|
||||||
djh := ihttp.NewDJHandlers(lstnrs, plylst, songList, &mostListenedSong)
|
djh := ihttp.NewDJHandlers(lstnrs, plylst, songList, &mostListenedSong, *fallbackSong)
|
||||||
|
|
||||||
s := r.Sub("/api/listener")
|
s := r.Sub("/api/listener")
|
||||||
s.Handler(http.MethodGet, "/", djh.ListenersGet)
|
s.Handler(http.MethodGet, "/", djh.ListenersGet)
|
||||||
|
@ -15,10 +15,13 @@ type DJHandlers struct {
|
|||||||
playlist *radio.Playlist
|
playlist *radio.Playlist
|
||||||
songList *radio.SongList
|
songList *radio.SongList
|
||||||
mostLSong *radio.MostListenedSong
|
mostLSong *radio.MostListenedSong
|
||||||
|
fallbackSong string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDJHandlers(l *radio.ListenerCounter, p *radio.Playlist, sl *radio.SongList, mls *radio.MostListenedSong) *DJHandlers {
|
func NewDJHandlers(l *radio.ListenerCounter, p *radio.Playlist,
|
||||||
return &DJHandlers{listeners: l, playlist: p, songList: sl, mostLSong: mls}
|
sl *radio.SongList, mls *radio.MostListenedSong, fS string) *DJHandlers {
|
||||||
|
return &DJHandlers{listeners: l, playlist: p, songList: sl,
|
||||||
|
mostLSong: mls, fallbackSong: fS}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dj *DJHandlers) ListenersGet(w http.ResponseWriter, _ *http.Request) {
|
func (dj *DJHandlers) ListenersGet(w http.ResponseWriter, _ *http.Request) {
|
||||||
@ -51,7 +54,13 @@ func (dj *DJHandlers) PlaylistNext(w http.ResponseWriter, _ *http.Request) {
|
|||||||
nxt := dj.playlist.Next()
|
nxt := dj.playlist.Next()
|
||||||
if nxt == "" {
|
if nxt == "" {
|
||||||
log.Println("the end of a playlist has been reached")
|
log.Println("the end of a playlist has been reached")
|
||||||
} else {
|
if nxt = dj.fallbackSong; nxt == "" {
|
||||||
|
log.Println("a fallback song is not set")
|
||||||
|
http.Error(w, "a playlist is empty and a fallback song is not set", http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
oggf, err := oggtag.NewOggFile(nxt)
|
oggf, err := oggtag.NewOggFile(nxt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -73,7 +82,6 @@ func (dj *DJHandlers) PlaylistNext(w http.ResponseWriter, _ *http.Request) {
|
|||||||
|
|
||||||
dj.songList.Add(song)
|
dj.songList.Add(song)
|
||||||
}()
|
}()
|
||||||
}
|
|
||||||
fmt.Fprintln(w, nxt)
|
fmt.Fprintln(w, nxt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user