1
0

Added handlers and flags and instantiated all need stuff. Removed flags for icecast.

This commit is contained in:
Alexander Andreev 2023-10-02 03:16:17 +04:00
parent 5e8e9943f9
commit d0722131df
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -18,11 +18,10 @@ import (
var (
listenAddress = flag.String("listen", "/var/run/dwelling-radio/sock", "listen address (ip:port|unix_path)")
icecastUrl = flag.String("ic-url", "", "URL to an Icecast's status-json.xsl")
icecastPlaylistPath = flag.String("ic-playlist", "/var/log/icecast/playlist.log", "path to an Icecast's playlist.log 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")
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("lst-len", 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")
showVersion = flag.Bool("v", false, "show version")
)
@ -44,20 +43,18 @@ func main() {
}
}
playlistWatcher := radio.NewPlaylistLogWatcher()
if err := playlistWatcher.Watch(*icecastPlaylistPath, *songListLen); err != nil {
songList := radio.NewSongList(*songListLen)
lstnrs := radio.NewListenerCounter()
plylst, err := radio.NewPlaylist(*playlist, true)
if err != nil {
log.Fatalln(err)
}
defer playlistWatcher.Close()
hand := ihttp.NewHandlers(*icecastUrl, *icecastPlaylistPath, *filelistPath, *songListLen)
hand := ihttp.NewHandlers(*filelistPath, songList, lstnrs)
r := httpr.New()
r.Handler(http.MethodGet, "/", hand.Index)
r.Handler(http.MethodGet, "/status", hand.Status)
r.Handler(http.MethodGet, "/lastsong", hand.LastSong)
r.Handler(http.MethodGet, "/playlist", hand.Playlist)
r.Handler(http.MethodGet, "/filelist", hand.Filelist)
@ -67,6 +64,21 @@ func main() {
r.ServeStatic("/assets/*filepath", web.Assets())
djh := ihttp.NewDJHandlers(lstnrs, plylst, songList, *songListLen)
s := r.Sub("/api/listener")
s.Handler(http.MethodGet, "/", djh.ListenersGet)
s.Handler(http.MethodPost, "/", djh.ListenersInc)
s.Handler(http.MethodDelete, "/", djh.ListenersDec)
s = r.Sub("/api")
s.Handler(http.MethodGet, "/playlist", djh.PlaylistNext)
s.Handler(http.MethodGet, "/song", djh.Song)
s.Handler(http.MethodGet, "/songs", djh.Songs)
s.Handler(http.MethodGet, "/status", djh.Status)
s.Handler(http.MethodGet, "/mostlistenedsong", djh.MostListenedSong)
srv := ihttp.NewHttpServer(r)
if err := srv.Start(*listenAddress); err != nil {