diff --git a/main.go b/main.go index 037971f..25fd832 100644 --- a/main.go +++ b/main.go @@ -72,10 +72,9 @@ func Recursive(ctx context.Context) error { p := path.Join(d, YamlFile) if _, err := os.Stat(p); err != nil { } else if err := func() error { - var y Yaml - b, _ := os.ReadFile(path.Join(d, YamlFile)) - if err := yaml.Unmarshal(b, &y); err != nil { - return fmt.Errorf("%s: %w", p, err) + y, err := NewYaml(path.Join(d, YamlFile)) + if err != nil { + return err } was, err := os.Getwd() @@ -280,3 +279,35 @@ func readDir(d string) ([]fs.DirEntry, error) { } return result, err } + +func NewYaml(p string) (Yaml, error) { + var y Yaml + b, _ := os.ReadFile(path.Join(d, YamlFile)) + if err := yaml.Unmarshal(b, &y); err != nil { + return y, fmt.Errorf("%s: %w", p, err) + } + + if v := os.Getenv("YAML_C_TITLE"); v != "" { + y.C.Title = v + } + if v := os.Getenv("YAML_C_SEASON"); v != "" { + y.C.Season = v + } + if v := os.Getenv("YAML_C_EPISODE"); v != "" { + y.C.Episode = v + } + + if v := os.Getenv("YAML_O"); v != "" { + y.O = v + } + + if v := os.Getenv("YAML_D"); v == "true" { + y.D = true + } + + if v := os.Getenv("YAML_P"); v != "" { + y.P = strings.Split(v, ",") + } + + return y, nil +}