Source kind is now declared per-file via a `dvd` / `bluray` / `webdl` / `tvrip` token in the basename (case-insensitive, word-bounded). Matches the existing `tt…` / `tvm…` filename convention. When no token is present, falls back to the pixel-count guess in DetectMediaType, which still only chooses between DVD and Blu-ray. The parsed media type drives both ORIGINAL_MEDIA_TYPE in the muxed metadata and the CRF/preset profile used for encoding. EncodingConfig gains `webdl` and `tvrip` sub-blocks with conservative defaults (WebDL 30/3, TVRip 32/2); user can override in config.yaml. Manual updated with the new tokens, config fields, and pipeline description.
89 lines
1.9 KiB
Go
89 lines
1.9 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.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
|
|
}
|
|
|
|
return &cfg, nil
|
|
}
|
|
|
|
func EnsureDirs(cfg *types.Config) error {
|
|
dirs := []string{cfg.Paths.Input, cfg.Paths.Output, cfg.Paths.Originals, cfg.Paths.Failed}
|
|
for _, dir := range dirs {
|
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
|
return fmt.Errorf("creating directory %s: %w", dir, err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|