Compare commits
2 Commits
d57206357e
...
984b53c6f1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
984b53c6f1 | ||
|
|
57d9b74c31 |
27
main.go
27
main.go
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
@@ -13,6 +14,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v3"
|
yaml "gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
@@ -95,7 +97,7 @@ func Main(ctx context.Context) error {
|
|||||||
flags := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
|
flags := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
|
||||||
overridesS := flags.String("c", `{"title":"","season":"","episode":""}`, "overrides")
|
overridesS := flags.String("c", `{"title":"","season":"","episode":""}`, "overrides")
|
||||||
ind := flags.String("i", "/dev/null", "in dir")
|
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")
|
dry := flags.Bool("d", true, "dry run")
|
||||||
if err := flags.Parse(os.Args[1:]); err != nil {
|
if err := flags.Parse(os.Args[1:]); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -154,7 +156,7 @@ func one(ctx context.Context, outd, inf string, patterns []string, overrides Fie
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
found := overrides
|
var found Fields
|
||||||
groupNames := re.SubexpNames()
|
groupNames := re.SubexpNames()
|
||||||
groups := re.FindStringSubmatch(f)
|
groups := re.FindStringSubmatch(f)
|
||||||
for i := 1; i < len(groupNames); i++ {
|
for i := 1; i < len(groupNames); i++ {
|
||||||
@@ -171,6 +173,16 @@ func one(ctx context.Context, outd, inf string, patterns []string, overrides Fie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, wr := range [][2]*string{
|
||||||
|
[2]*string{&found.Title, &overrides.Title},
|
||||||
|
[2]*string{&found.Season, &overrides.Season},
|
||||||
|
[2]*string{&found.Episode, &overrides.Episode},
|
||||||
|
} {
|
||||||
|
if *wr[1] != "" {
|
||||||
|
*wr[0] = *wr[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if found.Title == "" || found.Season == "" || found.Episode == "" {
|
if found.Title == "" || found.Season == "" || found.Episode == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -182,7 +194,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 {
|
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)
|
return mvNLn(outf, inf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -168,10 +168,11 @@ func TestRecursive(t *testing.T) {
|
|||||||
}`)
|
}`)
|
||||||
write("./showA/file.a")
|
write("./showA/file.a")
|
||||||
|
|
||||||
// parse files
|
// parse files and const wins
|
||||||
write("./showB/.show-ingestion.yaml", `{
|
write("./showB/.show-ingestion.yaml", `{
|
||||||
"o": "`+outd+`/B",
|
"o": "`+outd+`/B_{{.Title}}_{{.Season}}_{{.Episode}}",
|
||||||
"p": []
|
"p": [],
|
||||||
|
"c": {"title": "TITLE"}
|
||||||
}`)
|
}`)
|
||||||
write("./showB/title S01E02.b")
|
write("./showB/title S01E02.b")
|
||||||
|
|
||||||
@@ -198,7 +199,7 @@ func TestRecursive(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exists(t, path.Join(outd, "A", "A_SAEA.a"))
|
exists(t, path.Join(outd, "A", "A_SAEA.a"))
|
||||||
exists(t, path.Join(outd, "B", "title_S01E02.b"))
|
exists(t, path.Join(outd, "B_TITLE_01_02", "TITLE_S01E02.b"))
|
||||||
exists(t, path.Join(outd, "C", "t_SsEe.c"))
|
exists(t, path.Join(outd, "C", "t_SsEe.c"))
|
||||||
notExists(t, path.Join(outd, "D", "title_S02E04.d"))
|
notExists(t, path.Join(outd, "D", "title_S02E04.d"))
|
||||||
notExists(t, path.Join(outd, "title_S03E06.e"))
|
notExists(t, path.Join(outd, "title_S03E06.e"))
|
||||||
|
|||||||
Reference in New Issue
Block a user