outd is a template
This commit is contained in:
15
main.go
15
main.go
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"syscall"
|
||||
"text/template"
|
||||
|
||||
yaml "gopkg.in/yaml.v3"
|
||||
)
|
||||
@@ -95,7 +97,7 @@ func Main(ctx context.Context) error {
|
||||
flags := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
|
||||
overridesS := flags.String("c", `{"title":"","season":"","episode":""}`, "overrides")
|
||||
ind := flags.String("i", "/dev/null", "in dir")
|
||||
outd := flags.String("o", "/dev/null", "out dir")
|
||||
outd := flags.String("o", "/dev/null", "out dir template accepts overrides format title case")
|
||||
dry := flags.Bool("d", true, "dry run")
|
||||
if err := flags.Parse(os.Args[1:]); err != nil {
|
||||
panic(err)
|
||||
@@ -182,7 +184,16 @@ func one(ctx context.Context, outd, inf string, patterns []string, overrides Fie
|
||||
}
|
||||
|
||||
func foundOne(ctx context.Context, outd, inf string, fields Fields, mvNLn MvNLn) error {
|
||||
outf := path.Join(outd, fmt.Sprintf("%s_S%sE%s%s", fields.Title, fields.Season, fields.Episode, path.Ext(inf)))
|
||||
tmpl, err := template.New(inf).Parse(outd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buff := bytes.NewBuffer(nil)
|
||||
if err := tmpl.Execute(buff, fields); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
outf := path.Join(string(buff.Bytes()), fmt.Sprintf("%s_S%sE%s%s", fields.Title, fields.Season, fields.Episode, path.Ext(inf)))
|
||||
return mvNLn(outf, inf)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user