Added most listened song and song list length. Also removed a year 2022 from a version string.
This commit is contained in:
parent
07d11ce3ff
commit
5a058aa706
@ -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"
|
||||||
@ -17,9 +18,8 @@ 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")
|
|
||||||
icecastPlaylistPath = flag.String("ic-playlist", "/var/log/icecast/playlist.log", "path to an Icecast's playlist.log file")
|
|
||||||
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")
|
||||||
|
mostListenedSongPath = flag.String("mls-file", "/mnt/data/appdata/radio/mostlistenedsong", "path to a file that stores info about the most listened song")
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user