Files
av1dae/internal/config/config.go
T
Esa Kataja aa8a341069 add: live encode progress tracking and read-only status web UI
Stream ffmpeg -progress during the video encode into an in-memory tracker
(internal/status) so the long-running step is no longer a black box: percent,
fps, speed, and ETA are derived from the source duration and updated ~1/s.
Progress prints to stdout only (no logs.db row) to avoid burying real events.

Expose it over HTTP (internal/server, default :8080, set http_addr to "" to
disable): GET /status returns the live snapshot, the pending input queue, and
recent non-debug events; GET / serves an embedded dashboard that polls /status
every second. The server shuts down on the same SIGINT/SIGTERM context as the
watcher.
2026-06-21 17:43:00 +03:00

99 lines
2.0 KiB
Go

package config
import (
"fmt"
"os"
"path/filepath"
"gopkg.in/yaml.v3"
"videnc-vibe/pkg/types"
)
const (
appName = "videnc-vibe"
configName = "config.yaml"
)
func Load(configPath string) (*types.Config, error) {
var configFile string
if configPath != "" {
configFile = configPath
} else {
homeDir, err := os.UserHomeDir()
if err != nil {
return nil, fmt.Errorf("getting home directory: %w", err)
}
configFile = filepath.Join(homeDir, ".config", appName, configName)
}
data, err := os.ReadFile(configFile)
if err != nil {
return nil, fmt.Errorf("reading config file %s: %w", configFile, err)
}
var cfg types.Config
if err := yaml.Unmarshal(data, &cfg); err != nil {
return nil, fmt.Errorf("parsing config file: %w", err)
}
if cfg.Paths.Input == "" {
cfg.Paths.Input = "./input"
}
if cfg.Paths.Output == "" {
cfg.Paths.Output = "./output"
}
if cfg.Paths.Originals == "" {
cfg.Paths.Originals = "./originals"
}
if cfg.Paths.Failed == "" {
cfg.Paths.Failed = "./failed"
}
if cfg.Paths.Work == "" {
cfg.Paths.Work = "./work"
}
if cfg.Encoding.DVD.CRF == 0 {
cfg.Encoding.DVD.CRF = 30
}
if cfg.Encoding.DVD.Preset == 0 {
cfg.Encoding.DVD.Preset = 2
}
if cfg.Encoding.Bluray.CRF == 0 {
cfg.Encoding.Bluray.CRF = 29
}
if cfg.Encoding.Bluray.Preset == 0 {
cfg.Encoding.Bluray.Preset = 3
}
if cfg.Encoding.WebDL.CRF == 0 {
cfg.Encoding.WebDL.CRF = 30
}
if cfg.Encoding.WebDL.Preset == 0 {
cfg.Encoding.WebDL.Preset = 3
}
if cfg.Encoding.TVRip.CRF == 0 {
cfg.Encoding.TVRip.CRF = 32
}
if cfg.Encoding.TVRip.Preset == 0 {
cfg.Encoding.TVRip.Preset = 2
}
if cfg.LogRetentionDays == 0 {
cfg.LogRetentionDays = 7
}
if cfg.HTTPAddr == nil {
def := ":8080"
cfg.HTTPAddr = &def
}
return &cfg, nil
}
func EnsureDirs(cfg *types.Config) error {
dirs := []string{cfg.Paths.Input, cfg.Paths.Output, cfg.Paths.Originals, cfg.Paths.Failed, cfg.Paths.Work}
for _, dir := range dirs {
if err := os.MkdirAll(dir, 0755); err != nil {
return fmt.Errorf("creating directory %s: %w", dir, err)
}
}
return nil
}