98 lines
2.5 KiB
Go
98 lines
2.5 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
type WatchConfig struct {
|
|
Dirs []string `yaml:"dirs"`
|
|
StableSeconds int `yaml:"stable_seconds"`
|
|
IncludeExt []string `yaml:"include_ext"`
|
|
ExcludeExt []string `yaml:"exclude_ext"`
|
|
}
|
|
|
|
type StructureConfig struct {
|
|
MoviesDir string `yaml:"movies_dir"`
|
|
TVDir string `yaml:"tv_dir"`
|
|
MiscDir string `yaml:"misc_dir"`
|
|
UnknownDir string `yaml:"unknown_dir"`
|
|
AutoCreate bool `yaml:"auto_create"`
|
|
}
|
|
|
|
type RsyncTarget struct {
|
|
Host string `yaml:"host"`
|
|
Port int `yaml:"port"`
|
|
User string `yaml:"user"`
|
|
DestBase string `yaml:"dest_base"`
|
|
ExtraArgs []string `yaml:"extra_args"`
|
|
}
|
|
|
|
type SyncConfig struct {
|
|
Enabled bool `yaml:"enabled"`
|
|
RsyncBinary string `yaml:"rsync_binary"`
|
|
Targets []RsyncTarget `yaml:"targets"`
|
|
}
|
|
|
|
type NotifierEndpoint struct {
|
|
Name string `yaml:"name"`
|
|
Method string `yaml:"method"`
|
|
URL string `yaml:"url"`
|
|
Headers map[string]string `yaml:"headers"`
|
|
Body string `yaml:"body"`
|
|
}
|
|
|
|
type NotifierConfig struct {
|
|
Enabled bool `yaml:"enabled"`
|
|
Endpoints []NotifierEndpoint `yaml:"endpoints"`
|
|
}
|
|
|
|
type LoggingConfig struct {
|
|
Level string `yaml:"level"`
|
|
}
|
|
|
|
type Config struct {
|
|
Watch WatchConfig `yaml:"watch"`
|
|
Structure StructureConfig `yaml:"structure"`
|
|
Sync SyncConfig `yaml:"sync"`
|
|
Notifier NotifierConfig `yaml:"notifier"`
|
|
Logging LoggingConfig `yaml:"logging"`
|
|
}
|
|
|
|
func Load(path string) (*Config, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("read config: %w", err)
|
|
}
|
|
|
|
var cfg Config
|
|
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
|
return nil, fmt.Errorf("parse yaml: %w", err)
|
|
}
|
|
|
|
if cfg.Watch.StableSeconds <= 0 {
|
|
cfg.Watch.StableSeconds = 15
|
|
}
|
|
|
|
if cfg.Sync.RsyncBinary == "" {
|
|
cfg.Sync.RsyncBinary = "/usr/bin/rsync"
|
|
}
|
|
|
|
if cfg.Structure.MoviesDir == "" {
|
|
cfg.Structure.MoviesDir = "/srv/media/incoming/movies"
|
|
}
|
|
if cfg.Structure.TVDir == "" {
|
|
cfg.Structure.TVDir = "/srv/media/incoming/tv"
|
|
}
|
|
if cfg.Structure.MiscDir == "" {
|
|
cfg.Structure.MiscDir = "/srv/media/incoming/misc"
|
|
}
|
|
if cfg.Structure.UnknownDir == "" {
|
|
cfg.Structure.UnknownDir = "/srv/media/incoming/unknown"
|
|
}
|
|
|
|
return &cfg, nil
|
|
}
|