1
0

Added most listened song and song list length. Also removed a year 2022 from a version string.

This commit is contained in:
Alexander Andreev 2023-10-01 04:17:49 +04:00
parent 07d11ce3ff
commit 5a058aa706
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -5,6 +5,7 @@ import (
"dwelling-radio/internal/radio" "dwelling-radio/internal/radio"
"flag" "flag"
"fmt" "fmt"
"io/fs"
"log" "log"
"net/http" "net/http"
"os" "os"
@ -15,11 +16,10 @@ import (
) )
var ( 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)")
playlist = flag.String("playlist", "", "path to a playlist") playlist = flag.String("playlist", "", "path to a playlist")
icecastUrl = flag.String("ic-url", "", "URL to an Icecast's status-json.xsl") songListLen = flag.Int("list-length", 10, "number of songs to show in last N songs table")
icecastPlaylistPath = flag.String("ic-playlist", "/var/log/icecast/playlist.log", "path to an Icecast's playlist.log file") 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")
showVersion = flag.Bool("v", false, "show version") showVersion = flag.Bool("v", false, "show version")
) )
@ -31,7 +31,7 @@ func main() {
log.SetFlags(log.Lshortfile) log.SetFlags(log.Lshortfile)
if *showVersion { if *showVersion {
fmt.Println("dwelling-radio ver.", version, "\nCopyright (c) 2022,2023 Alexander \"Arav\" Andreev <me@arav.su>") fmt.Println("dwelling-radio ver.", version, "\nCopyright (c) 2023 Alexander \"Arav\" Andreev <me@arav.su>")
return return
} }
@ -43,7 +43,13 @@ func main() {
log.Fatalln(err) log.Fatalln(err)
} }
djh := ihttp.NewDJHandlers(lstnrs, plylst) mlsf, err := os.ReadFile(*mostListenedSongPath)
if err != nil {
log.Fatalln(err)
}
radio.LoadMostListenedSong(mlsf)
djh := ihttp.NewDJHandlers(lstnrs, plylst, *songListLen)
s := r.Sub("/listener") s := r.Sub("/listener")
s.Handler(http.MethodGet, "/", djh.ListenersGet) s.Handler(http.MethodGet, "/", djh.ListenersGet)
@ -63,6 +69,14 @@ func main() {
} }
defer func() { defer func() {
fileData := radio.StoreMostListenedSong()
if fileData != nil {
err := os.WriteFile(*mostListenedSongPath, fileData, fs.ModePerm)
if err != nil {
log.Println("failed to store a most listened song:", err)
}
}
if err := srv.Stop(); err != nil { if err := srv.Stop(); err != nil {
log.Fatalln(err) log.Fatalln(err)
} }