diff --git a/cmd/dwelling-radio/main.go b/cmd/dwelling-radio/main.go index 721f246..30a3810 100644 --- a/cmd/dwelling-radio/main.go +++ b/cmd/dwelling-radio/main.go @@ -13,18 +13,17 @@ import ( "net/http" "os" "os/signal" + "path" "syscall" "git.arav.su/Arav/httpr" ) var ( - 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") - playlistPath = flag.String("playlist", "", "path to a playlist") - fallbackSong = flag.String("fallback-song", "", "path to a fallback song") - statisticsDbPath = flag.String("db", "/mnt/data/appdata/radio/statistics.db3", "path to a statistics database") - songListLen = flag.Int64("list-length", 10, "number of songs to show in last N songs table") + listenAddress = flag.String("listen", "/var/run/dwelling-radio/sock", "listen address (ip:port|unix_path)") + workDirPath = flag.String("work-dir", "/mnt/data/appdata/radio", "path to a working directory") + playlistName = flag.String("playlist", "all-rand", "a playlist name") + songListLen = flag.Int64("list-length", 10, "number of songs to show in last N songs table") showVersion = flag.Bool("v", false, "show version") ) @@ -40,7 +39,7 @@ func main() { return } - stats, err := sqlite_stats.New(*statisticsDbPath) + stats, err := sqlite_stats.New(path.Join(*workDirPath, "statistics.db3")) if err != nil { log.Fatalln("Statistics:", err) } @@ -49,7 +48,7 @@ func main() { currentSong := radio.Song{} lstnrs := radio.NewListenerCounter() - plylst, err := radio.NewPlaylist(*playlistPath, true) + plylst, err := radio.NewPlaylist(path.Join(*workDirPath, "playlists", *playlistName), true) if err != nil { log.Fatalln(err) } @@ -68,14 +67,14 @@ func main() { }) r.Handler(http.MethodGet, "/filelist", func(w http.ResponseWriter, r *http.Request) { - if *filelistPath == "" { - http.Error(w, "no filelist", http.StatusNotFound) + data, err := os.ReadFile(path.Join(*workDirPath, "filelist.html")) + if err != nil { + http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return } w.Header().Add("Content-Type", "text/html") w.Header().Add("Link", "<"+utils.Site(r.Host)+"/filelist>; rel=\"canonical\"") - data, _ := os.ReadFile(*filelistPath) w.Write(data) }) @@ -87,7 +86,7 @@ func main() { r.ServeStatic("/assets/*filepath", web.Assets()) - djh := ihttp.NewDJHandlers(lstnrs, plylst, stats, ¤tSong, *songListLen, *fallbackSong) + djh := ihttp.NewDJHandlers(lstnrs, plylst, stats, ¤tSong, *songListLen, path.Join(*workDirPath, "fallback.ogg")) s := r.Sub("/api") diff --git a/init/radio.service b/init/radio.service index 29f1f9b..34fbf45 100755 --- a/init/radio.service +++ b/init/radio.service @@ -8,10 +8,8 @@ Type=simple Restart=on-failure DynamicUser=yes ExecStart=/usr/bin/dwelling-radio -listen /var/run/dwelling-radio/sock \ - -filelist /mnt/data/appdata/radio/filelist.html \ - -playlist /mnt/data/appdata/radio/playlists/all-rand \ - -fallback-song /mnt/data/appdata/radio/fallback.ogg \ - -db /mnt/data/appdata/radio/statistics.db3 \ + -work-dir /mnt/data/appdata/radio \ + -playlist all-rand \ -lst-len 10 ReadOnlyPaths=/