navidrome/conf/configuration.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

88 lines
2.6 KiB
Go
Raw Normal View History

2016-03-30 06:05:57 +02:00
package conf
import (
"fmt"
2016-03-30 06:05:57 +02:00
"os"
"path/filepath"
2020-07-02 22:41:54 +02:00
"time"
2016-03-30 06:05:57 +02:00
2020-01-24 01:44:08 +01:00
"github.com/deluan/navidrome/consts"
"github.com/deluan/navidrome/log"
2020-07-02 22:34:21 +02:00
"github.com/spf13/viper"
2016-03-30 06:05:57 +02:00
)
2020-01-24 07:29:31 +01:00
type nd struct {
2020-07-02 22:34:21 +02:00
ConfigFile string
Port int
MusicFolder string
DataFolder string
DbPath string
LogLevel string
2020-07-02 22:41:54 +02:00
ScanInterval time.Duration
SessionTimeout time.Duration
2020-07-02 22:34:21 +02:00
BaseURL string
UILoginBackgroundURL string
IgnoredArticles string
IndexGroups string
EnableTranscodingConfig bool
TranscodingCacheSize string
ImageCacheSize string
ProbeCommand string
CoverArtPriority string
CoverJpegQuality int
// DevFlags. These are used to enable/disable debugging and incomplete features
2020-07-02 22:34:21 +02:00
DevLogSourceLine bool
DevAutoCreateAdminPassword string
2016-03-30 06:05:57 +02:00
}
var Server = &nd{}
2020-01-08 16:25:23 +01:00
2020-07-02 22:34:21 +02:00
func LoadFromFile(confFile string) {
// Use config file from the flag.
SetDefaults()
viper.SetConfigFile(confFile)
Load()
}
2020-07-02 22:34:21 +02:00
func Load() {
err := viper.Unmarshal(&Server)
if err != nil {
2020-07-02 22:34:21 +02:00
fmt.Println("Error parsing config:", err)
os.Exit(1)
}
2020-07-02 22:34:21 +02:00
Server.ConfigFile = viper.GetViper().ConfigFileUsed()
if Server.DbPath == "" {
Server.DbPath = filepath.Join(Server.DataFolder, consts.DefaultDbPath)
}
2020-07-02 22:34:21 +02:00
log.SetLevelString(Server.LogLevel)
log.SetLogSourceLine(Server.DevLogSourceLine)
2020-07-02 22:34:21 +02:00
log.Debug("Loaded configuration", "file", Server.ConfigFile, "config", fmt.Sprintf("%#v", Server))
2016-03-30 06:05:57 +02:00
}
2020-07-02 22:34:21 +02:00
func SetDefaults() {
viper.SetDefault("musicfolder", "./music")
viper.SetDefault("datafolder", "./")
viper.SetDefault("loglevel", "info")
viper.SetDefault("port", 4533)
2020-07-02 22:41:54 +02:00
viper.SetDefault("sessiontimeout", consts.DefaultSessionTimeout)
viper.SetDefault("scaninterval", time.Minute)
2020-07-02 22:34:21 +02:00
viper.SetDefault("baseurl", "")
viper.SetDefault("uiloginbackgroundurl", "")
viper.SetDefault("enabletranscodingconfig", false)
viper.SetDefault("transcodingcachesize", "100MB")
viper.SetDefault("imagecachesize", "100MB")
// Config options only valid for file configuration
viper.SetDefault("ignoredarticles", "The El La Los Las Le Les Os As O A")
viper.SetDefault("indexgroups", "A B C D E F G H I J K L M N O P Q R S T U V W X-Z(XYZ) [Unknown]([)")
viper.SetDefault("probecommand", "ffmpeg %s -f ffmetadata")
viper.SetDefault("coverartpriority", "embedded, cover.*, folder.*, front.*")
viper.SetDefault("coverjpegquality", 75)
// DevFlags. These are used to enable/disable debugging and incomplete features
viper.SetDefault("devlogsourceline", false)
viper.SetDefault("devautocreateadminpassword", "")
2016-03-30 06:05:57 +02:00
}