feat: allow for custom music folder path alias

closes #259
This commit is contained in:
sentriz
2022-11-21 20:17:55 +00:00
parent 92a73b2d61
commit 7e097c9bdf
6 changed files with 81 additions and 32 deletions

View File

@@ -9,6 +9,7 @@ import (
"log"
"os"
"path"
"path/filepath"
"regexp"
"strings"
"time"
@@ -20,6 +21,7 @@ import (
"go.senan.xyz/gonic"
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/paths"
"go.senan.xyz/gonic/server"
)
@@ -48,7 +50,7 @@ func main() {
confHTTPLog := set.Bool("http-log", true, "http request logging (optional)")
confShowVersion := set.Bool("version", false, "show gonic version")
var confMusicPaths musicPaths
var confMusicPaths paths.MusicPaths
set.Var(&confMusicPaths, "music-path", "path to music")
_ = set.String("config-path", "", "path to config (optional)")
@@ -77,8 +79,8 @@ func main() {
log.Fatalf("please provide a music directory")
}
for _, confMusicPath := range confMusicPaths {
if _, err := os.Stat(confMusicPath); os.IsNotExist(err) {
log.Fatalf("music directory %q not found", confMusicPath)
if _, err := os.Stat(confMusicPath.Path); os.IsNotExist(err) {
log.Fatalf("music directory %q not found", confMusicPath.Path)
}
}
if _, err := os.Stat(*confPodcastPath); os.IsNotExist(err) {
@@ -109,7 +111,7 @@ func main() {
defer dbc.Close()
err = dbc.Migrate(db.MigrationContext{
OriginalMusicPath: confMusicPaths[0],
OriginalMusicPath: confMusicPaths[0].Path,
})
if err != nil {
log.Panicf("error migrating database: %v\n", err)
@@ -120,11 +122,11 @@ func main() {
server, err := server.New(server.Options{
DB: dbc,
MusicPaths: confMusicPaths,
CachePath: cacheDirAudio,
CachePath: filepath.Clean(cacheDirAudio),
CoverCachePath: cacheDirCovers,
ProxyPrefix: *confProxyPrefix,
GenreSplit: *confGenreSplit,
PodcastPath: *confPodcastPath,
PodcastPath: filepath.Clean(*confPodcastPath),
HTTPLog: *confHTTPLog,
JukeboxEnabled: *confJukeboxEnabled,
})
@@ -158,14 +160,3 @@ func main() {
log.Panicf("error in job: %v", err)
}
}
type musicPaths []string
func (m musicPaths) String() string {
return strings.Join(m, ", ")
}
func (m *musicPaths) Set(value string) error {
*m = append(*m, value)
return nil
}