Compare commits
15 Commits
5f5015e152
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dad5803297 | ||
|
|
2e4e4b9b06 | ||
|
|
61f9b9c724 | ||
|
|
5b9bead96f | ||
|
|
54bbca8fea | ||
|
|
3e8e33816e | ||
|
|
00fdd4f976 | ||
|
|
1e3d6ee0a2 | ||
|
|
d3c9b1a564 | ||
|
|
e653c35275 | ||
|
|
596865ede3 | ||
|
|
62ea963807 | ||
|
|
82a13aea65 | ||
|
|
d40a1f8fd4 | ||
|
|
e85fec9bbf |
198
main.go
198
main.go
@@ -6,9 +6,12 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
@@ -20,6 +23,18 @@ import (
|
|||||||
yaml "gopkg.in/yaml.v3"
|
yaml "gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
Debug = os.Getenv("DEBUG") == "true"
|
||||||
|
ConstTitle = os.Getenv("YAML_C_TITLE")
|
||||||
|
ConstSeason = os.Getenv("YAML_C_SEASON")
|
||||||
|
ConstEpisode = os.Getenv("YAML_C_EPISODE")
|
||||||
|
ConstOutd = os.Getenv("YAML_O")
|
||||||
|
Dry = os.Getenv("YAML_D") == "true" || os.Getenv("DRY") == "true"
|
||||||
|
ConstPatterns = os.Getenv("YAML_P")
|
||||||
|
WebhookOnRecursiveMiss = os.Getenv("RECURSIVE_MISSING_WEBHOOK")
|
||||||
|
WebhookOnRecursiveMissCacheD = os.Getenv("RECURSIVE_MISSING_WEBHOOK_CACHE_D")
|
||||||
|
)
|
||||||
|
|
||||||
type Yaml struct {
|
type Yaml struct {
|
||||||
C Fields
|
C Fields
|
||||||
O string
|
O string
|
||||||
@@ -71,11 +86,47 @@ func Recursive(ctx context.Context) error {
|
|||||||
|
|
||||||
p := path.Join(d, YamlFile)
|
p := path.Join(d, YamlFile)
|
||||||
if _, err := os.Stat(p); err != nil {
|
if _, err := os.Stat(p); err != nil {
|
||||||
|
log.Printf("%s has no %s", d, YamlFile)
|
||||||
|
if WebhookOnRecursiveMiss != "" && WebhookOnRecursiveMissCacheD != "" {
|
||||||
|
cacheP := regexp.MustCompile(`[^a-zA-Z0-9]`).ReplaceAllString(p, `_`)
|
||||||
|
cacheP = path.Join(WebhookOnRecursiveMissCacheD, cacheP)
|
||||||
|
if _, err := os.Stat(cacheP); err != nil {
|
||||||
|
req, err := http.NewRequest(http.MethodPut, WebhookOnRecursiveMiss, strings.NewReader(p))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
u, err := url.Parse(WebhookOnRecursiveMiss)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("WebhookOnRecursiveMiss (%s) invalid: %w", WebhookOnRecursiveMiss, err)
|
||||||
|
}
|
||||||
|
user := u.User
|
||||||
|
u.User = nil
|
||||||
|
if username := user.Username(); username != "" {
|
||||||
|
password, _ := user.Password()
|
||||||
|
req.SetBasicAuth(username, password)
|
||||||
|
}
|
||||||
|
req.URL = u
|
||||||
|
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to call %s for missing %s: %w", WebhookOnRecursiveMiss, p, err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
defer io.Copy(io.Discard, resp.Body)
|
||||||
|
if resp.StatusCode > 250 {
|
||||||
|
b, _ := io.ReadAll(resp.Body)
|
||||||
|
return fmt.Errorf("unexpected status code from %s for %s: (%d) %s", WebhookOnRecursiveMiss, p, resp.StatusCode, b)
|
||||||
|
}
|
||||||
|
|
||||||
|
os.MkdirAll(path.Dir(cacheP), os.ModePerm)
|
||||||
|
ioutil.WriteFile(cacheP, []byte{}, os.ModePerm)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if err := func() error {
|
} else if err := func() error {
|
||||||
var y Yaml
|
y, err := NewYaml(path.Join(d, YamlFile))
|
||||||
b, _ := os.ReadFile(path.Join(d, YamlFile))
|
if err != nil {
|
||||||
if err := yaml.Unmarshal(b, &y); err != nil {
|
return err
|
||||||
return fmt.Errorf("%s: %w", p, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
was, err := os.Getwd()
|
was, err := os.Getwd()
|
||||||
@@ -88,7 +139,7 @@ func Recursive(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
defer os.Chdir(was)
|
defer os.Chdir(was)
|
||||||
|
|
||||||
log.Printf("Run(%s, %s, %+v, %+v, %v)", y.O, d, y.P, y.C, y.D)
|
log.Printf("Run(outd=%s, ind=%s, patterns=%+v, const=%+v, dry=%v)", y.O, d, y.P, y.C, y.D)
|
||||||
if err := Run(ctx, y.O, "./", y.P, y.C, y.D); err != nil {
|
if err := Run(ctx, y.O, "./", y.P, y.C, y.D); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -133,6 +184,15 @@ func Main(ctx context.Context) error {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
PatternGroupTitleHyphenSEDual = `^(\[[^\]]*\] )?(?P<title>.*?)( -)?[ \.](S(?P<season>[0-9]{2})E)?(?P<episode>[0-9]{2})[^0-9].*[dD][uU][aA][lL].*`
|
||||||
|
PatternGroupTitleHyphenSE = `^(\[[^\]]*\] )?(?P<title>.*?)( -)?[ \.](S(?P<season>[0-9]{2})E)?(?P<episode>[0-9]{2})[^0-9].*`
|
||||||
|
PatternTitleSEDual = `^(?P<title>.*) S(?P<season>[0-9]+)E(?P<episode>[0-9]+).*[dD][uU][aA][lL].*`
|
||||||
|
PatternTitleSE = `^(?P<title>.*) S(?P<season>[0-9]+)E(?P<episode>[0-9]+).*`
|
||||||
|
SEDual = `^S(?P<season>[0-9]+)E(?P<episode>[0-9]+).*[dD][uU][aA][lL].*`
|
||||||
|
SE = `^S(?P<season>[0-9]+)E(?P<episode>[0-9]+).*`
|
||||||
|
)
|
||||||
|
|
||||||
func Run(ctx context.Context, outd, ind string, patterns []string, overrides Fields, dry bool) error {
|
func Run(ctx context.Context, outd, ind string, patterns []string, overrides Fields, dry bool) error {
|
||||||
mvNLn := RealMvNLn
|
mvNLn := RealMvNLn
|
||||||
if dry {
|
if dry {
|
||||||
@@ -142,8 +202,12 @@ func Run(ctx context.Context, outd, ind string, patterns []string, overrides Fie
|
|||||||
outd,
|
outd,
|
||||||
ind,
|
ind,
|
||||||
append(patterns,
|
append(patterns,
|
||||||
`^\[[^\]]*\] (?P<title>.*) - (?P<episode>[0-9]+).*`,
|
PatternGroupTitleHyphenSEDual,
|
||||||
`^(?P<title>.*) S(?P<season>[0-9]+)E(?P<episode>[0-9]+).*`,
|
PatternGroupTitleHyphenSE,
|
||||||
|
PatternTitleSEDual,
|
||||||
|
PatternTitleSE,
|
||||||
|
SEDual,
|
||||||
|
SE,
|
||||||
),
|
),
|
||||||
overrides,
|
overrides,
|
||||||
mvNLn,
|
mvNLn,
|
||||||
@@ -155,40 +219,34 @@ func RunWith(ctx context.Context, outd, ind string, patterns []string, overrides
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, entry := range entries {
|
done := map[int]bool{}
|
||||||
if !entry.Type().IsRegular() {
|
for _, pattern := range patterns {
|
||||||
continue
|
for i, entry := range entries {
|
||||||
}
|
if done[i] {
|
||||||
if err := one(ctx, outd, path.Join(ind, entry.Name()), patterns, overrides, mvNLn); err != nil {
|
continue
|
||||||
return err
|
}
|
||||||
|
if !entry.Type().IsRegular() && !(Debug && Dry) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if match, err := one(ctx, outd, path.Join(ind, entry.Name()), []string{pattern}, overrides, mvNLn); err != nil {
|
||||||
|
return err
|
||||||
|
} else if match {
|
||||||
|
done[i] = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func one(ctx context.Context, outd, inf string, patterns []string, overrides Fields, mvNLn MvNLn) error {
|
func one(ctx context.Context, outd, inf string, patterns []string, overrides Fields, mvNLn MvNLn) (bool, error) {
|
||||||
f := path.Base(inf)
|
f := path.Base(inf)
|
||||||
for _, pattern := range patterns {
|
for _, pattern := range patterns {
|
||||||
re := regexp.MustCompile(pattern)
|
found, match := Parse(f, pattern)
|
||||||
if !re.MatchString(f) {
|
if !match {
|
||||||
continue
|
if Debug {
|
||||||
}
|
log.Printf("%q does not match %q", pattern, f)
|
||||||
|
|
||||||
var found Fields
|
|
||||||
groupNames := re.SubexpNames()
|
|
||||||
groups := re.FindStringSubmatch(f)
|
|
||||||
for i := 1; i < len(groupNames); i++ {
|
|
||||||
v := groups[i]
|
|
||||||
switch groupNames[i] {
|
|
||||||
case "title":
|
|
||||||
found.Title = v
|
|
||||||
case "season":
|
|
||||||
found.Season = v
|
|
||||||
case "episode":
|
|
||||||
found.Episode = v
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("unexpected capture group %q", groupNames[i])
|
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, wr := range [][2]*string{
|
for _, wr := range [][2]*string{
|
||||||
@@ -202,13 +260,45 @@ func one(ctx context.Context, outd, inf string, patterns []string, overrides Fie
|
|||||||
}
|
}
|
||||||
|
|
||||||
if found.Title == "" || found.Season == "" || found.Episode == "" {
|
if found.Title == "" || found.Season == "" || found.Episode == "" {
|
||||||
|
if Debug {
|
||||||
|
log.Printf("%q does not match all %q: %+v", pattern, f, found)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
found.Title = strings.ReplaceAll(found.Title, ".", " ")
|
||||||
found.Title = strings.Join(strings.Fields(found.Title), "_")
|
found.Title = strings.Join(strings.Fields(found.Title), "_")
|
||||||
|
|
||||||
return foundOne(ctx, outd, inf, found, mvNLn)
|
if Debug {
|
||||||
|
log.Printf("%q matches %q as %+v", pattern, f, found)
|
||||||
|
}
|
||||||
|
return true, foundOne(ctx, outd, inf, found, mvNLn)
|
||||||
}
|
}
|
||||||
return nil
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Parse(f string, pattern string) (Fields, bool) {
|
||||||
|
re := regexp.MustCompile(pattern)
|
||||||
|
if !re.MatchString(f) {
|
||||||
|
return Fields{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
var found Fields
|
||||||
|
groupNames := re.SubexpNames()
|
||||||
|
groups := re.FindStringSubmatch(f)
|
||||||
|
for i := 1; i < len(groupNames); i++ {
|
||||||
|
v := groups[i]
|
||||||
|
switch groupNames[i] {
|
||||||
|
case "title":
|
||||||
|
found.Title = v
|
||||||
|
case "season":
|
||||||
|
found.Season = v
|
||||||
|
case "episode":
|
||||||
|
found.Episode = v
|
||||||
|
default:
|
||||||
|
//return fmt.Errorf("unexpected capture group %q", groupNames[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return found, true
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
@@ -245,10 +335,16 @@ func DryMvNLn() func(string, string) error {
|
|||||||
outd := map[string]struct{}{}
|
outd := map[string]struct{}{}
|
||||||
return func(outf, inf string) error {
|
return func(outf, inf string) error {
|
||||||
if _, err := os.Stat(outf); err == nil {
|
if _, err := os.Stat(outf); err == nil {
|
||||||
|
if Debug {
|
||||||
|
fmt.Fprintf(os.Stderr, "no mv %q\n %q\n", inf, outf)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := outd[outf]; ok {
|
if _, ok := outd[outf]; ok {
|
||||||
|
if Debug {
|
||||||
|
fmt.Fprintf(os.Stderr, "no mv %q\n %q\n", inf, outf)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
outd[outf] = struct{}{}
|
outd[outf] = struct{}{}
|
||||||
@@ -268,3 +364,35 @@ func readDir(d string) ([]fs.DirEntry, error) {
|
|||||||
}
|
}
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewYaml(p string) (Yaml, error) {
|
||||||
|
var y Yaml
|
||||||
|
b, _ := os.ReadFile(p)
|
||||||
|
if err := yaml.Unmarshal(b, &y); err != nil {
|
||||||
|
return y, fmt.Errorf("%s: %w", p, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ConstTitle != "" {
|
||||||
|
y.C.Title = ConstTitle
|
||||||
|
}
|
||||||
|
if ConstSeason != "" {
|
||||||
|
y.C.Season = ConstSeason
|
||||||
|
}
|
||||||
|
if ConstEpisode != "" {
|
||||||
|
y.C.Episode = ConstEpisode
|
||||||
|
}
|
||||||
|
|
||||||
|
if ConstOutd != "" {
|
||||||
|
y.O = ConstOutd
|
||||||
|
}
|
||||||
|
|
||||||
|
if Dry {
|
||||||
|
y.D = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if ConstPatterns != "" {
|
||||||
|
y.P = strings.Split(ConstPatterns, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
return y, nil
|
||||||
|
}
|
||||||
|
|||||||
168
main_test.go
168
main_test.go
@@ -3,6 +3,9 @@ package main_test
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"slices"
|
"slices"
|
||||||
@@ -79,6 +82,17 @@ func TestRunWith(t *testing.T) {
|
|||||||
"Australian_Survivor_S12E12.mkv",
|
"Australian_Survivor_S12E12.mkv",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"hard w group": {
|
||||||
|
given: []string{
|
||||||
|
"[Yameii] Dr. Stone - S04E12 [English Dub] [CR WEB-DL 720p] [F6EF1948].mkv",
|
||||||
|
},
|
||||||
|
patterns: []string{
|
||||||
|
main.PatternGroupTitleHyphenSE,
|
||||||
|
},
|
||||||
|
want: []string{
|
||||||
|
"Dr_Stone_S04E12.mkv",
|
||||||
|
},
|
||||||
|
},
|
||||||
"easy w group": {
|
"easy w group": {
|
||||||
given: []string{
|
given: []string{
|
||||||
"[SubsPlease] Tokidoki Bosotto Russia-go de Dereru Tonari no Alya-san - 01 (720p) [A12844D5].mkv",
|
"[SubsPlease] Tokidoki Bosotto Russia-go de Dereru Tonari no Alya-san - 01 (720p) [A12844D5].mkv",
|
||||||
@@ -149,6 +163,44 @@ func TestRunWith(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRecursive(t *testing.T) {
|
func TestRecursive(t *testing.T) {
|
||||||
|
webhooks := []string{}
|
||||||
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method != http.MethodPut {
|
||||||
|
t.Errorf("unexpected webhook method %s", r.Method)
|
||||||
|
}
|
||||||
|
if r.URL.User.String() != "" {
|
||||||
|
t.Errorf("unexpected auth on url %s", r.URL.String())
|
||||||
|
}
|
||||||
|
if u, p, _ := r.BasicAuth(); u != "u" || p != "p" {
|
||||||
|
t.Errorf("webhook didnt translate u:p to basic auth")
|
||||||
|
}
|
||||||
|
b, _ := ioutil.ReadAll(r.Body)
|
||||||
|
t.Logf("%s { %s }", r.URL.String(), b)
|
||||||
|
webhooks = append(webhooks, string(b))
|
||||||
|
}))
|
||||||
|
t.Cleanup(s.Close)
|
||||||
|
t.Cleanup(func() {
|
||||||
|
t.Logf("webhooks: %+v", webhooks)
|
||||||
|
if len(webhooks) == 0 {
|
||||||
|
t.Errorf("expected webhook calls but got none")
|
||||||
|
}
|
||||||
|
deduped := slices.Clone(webhooks)
|
||||||
|
slices.Sort(deduped)
|
||||||
|
slices.Compact(deduped)
|
||||||
|
if len(deduped) != len(webhooks) {
|
||||||
|
t.Errorf("expected no duplicate webhooks but got %+v", webhooks)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
u, _ := url.Parse(s.URL)
|
||||||
|
u.User = url.UserPassword("u", "p")
|
||||||
|
main.WebhookOnRecursiveMiss = u.String()
|
||||||
|
main.WebhookOnRecursiveMissCacheD = t.TempDir()
|
||||||
|
t.Cleanup(func() {
|
||||||
|
main.WebhookOnRecursiveMiss = ""
|
||||||
|
main.WebhookOnRecursiveMissCacheD = ""
|
||||||
|
})
|
||||||
|
|
||||||
was, _ := os.Getwd()
|
was, _ := os.Getwd()
|
||||||
t.Cleanup(func() { os.Chdir(was) })
|
t.Cleanup(func() { os.Chdir(was) })
|
||||||
os.Chdir(t.TempDir())
|
os.Chdir(t.TempDir())
|
||||||
@@ -194,8 +246,16 @@ func TestRecursive(t *testing.T) {
|
|||||||
os.MkdirAll("./dirB/showE", os.ModePerm)
|
os.MkdirAll("./dirB/showE", os.ModePerm)
|
||||||
write("./dirB/showE/title S03E06.e")
|
write("./dirB/showE/title S03E06.e")
|
||||||
|
|
||||||
|
// defaults
|
||||||
|
write("./dirA/showF/.show-ingestion.yaml", `{
|
||||||
|
"o": "`+outd+`/F"
|
||||||
|
}`)
|
||||||
|
write("./dirA/showF/[Yameii] Dr. Stone - S04E12 [English Dub] [CR WEB-DL 720p] [F6EF1948].mkv")
|
||||||
|
|
||||||
if err := main.Recursive(context.Background()); err != nil {
|
if err := main.Recursive(context.Background()); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
} else if err := main.Recursive(context.Background()); err != nil {
|
||||||
|
t.Fatalf("failed second run: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
exists(t, path.Join(outd, "A", "A_SAEA.a"))
|
exists(t, path.Join(outd, "A", "A_SAEA.a"))
|
||||||
@@ -203,6 +263,8 @@ func TestRecursive(t *testing.T) {
|
|||||||
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"))
|
||||||
|
exists(t, path.Join(outd, "F", "Dr_Stone_S04E12.mkv"))
|
||||||
|
notExists(t, path.Join(outd, "F", "[Yameii]_Dr_Stone_-_S04E12.mkv"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func write(f string, b ...string) {
|
func write(f string, b ...string) {
|
||||||
@@ -242,3 +304,109 @@ func ls(d string) []string {
|
|||||||
slices.Sort(result)
|
slices.Sort(result)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParse(t *testing.T) {
|
||||||
|
cases := map[string]struct {
|
||||||
|
pattern string
|
||||||
|
want main.Fields
|
||||||
|
}{
|
||||||
|
"[SubsPlease] Tokidoki Bosotto Russia-go de Dereru Tonari no Alya-san - 01 (720p) [A12844D5].mkv": {
|
||||||
|
pattern: main.PatternGroupTitleHyphenSE,
|
||||||
|
want: main.Fields{
|
||||||
|
Title: "Tokidoki Bosotto Russia-go de Dereru Tonari no Alya-san",
|
||||||
|
Season: "",
|
||||||
|
Episode: "01",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Survivor.AU.S12E11.1080p.HEVC.x265-MeGusta[EZTVx.to].mkv": {
|
||||||
|
pattern: main.PatternGroupTitleHyphenSE,
|
||||||
|
want: main.Fields{
|
||||||
|
Title: "Survivor.AU",
|
||||||
|
Season: "12",
|
||||||
|
Episode: "11",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"DAN DA DAN (2024) S01E01v2 (1080p WEB-DL H264 AAC DDP 2.0 Dual-Audio) [MALD].mkv": {
|
||||||
|
pattern: main.PatternGroupTitleHyphenSE,
|
||||||
|
want: main.Fields{
|
||||||
|
Title: "DAN DA DAN (2024)",
|
||||||
|
Season: "01",
|
||||||
|
Episode: "01",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"ZENSHU.S01E01.1080p.AMZN.WEB-DL.MULTi.DDP2.0.H.264.MSubs-ToonsHub.mkv": {
|
||||||
|
pattern: main.PatternGroupTitleHyphenSE,
|
||||||
|
want: main.Fields{
|
||||||
|
Title: "ZENSHU",
|
||||||
|
Season: "01",
|
||||||
|
Episode: "01",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"[Yameii] My Hero Academia - S07E08 [English Dub] [CR WEB-DL 720p] [DE5FFC3E].mkv": {
|
||||||
|
pattern: main.PatternGroupTitleHyphenSE,
|
||||||
|
want: main.Fields{
|
||||||
|
Title: "My Hero Academia",
|
||||||
|
Season: "07",
|
||||||
|
Episode: "08",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Ranma1-2.2024.S01E03.Because.Theres.Someone.He.Likes.1080p.NF.WEB-DL.AAC2.0.H.264-VARYG.mkv": {
|
||||||
|
pattern: main.PatternGroupTitleHyphenSE,
|
||||||
|
want: main.Fields{
|
||||||
|
Title: "Ranma1-2.2024",
|
||||||
|
Season: "01",
|
||||||
|
Episode: "03",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"[Yameii] The Apothecary Diaries - S02E03 [English Dub] [CR WEB-DL 720p] [FD3E7434].mkv": {
|
||||||
|
pattern: main.PatternGroupTitleHyphenSE,
|
||||||
|
want: main.Fields{
|
||||||
|
Title: "The Apothecary Diaries",
|
||||||
|
Season: "02",
|
||||||
|
Episode: "03",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"The.Dinner.Table.Detective.S01E01.Welcome.to.the.murderous.party.File.1.1080p.AMZN.WEB-DL.DDP2.0.H.264-VARYG.mkv": {
|
||||||
|
pattern: main.PatternGroupTitleHyphenSE,
|
||||||
|
want: main.Fields{
|
||||||
|
Title: "The.Dinner.Table.Detective",
|
||||||
|
Season: "01",
|
||||||
|
Episode: "01",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"[Reza] Wistoria Wand and Sword - S01E01.mkv": {
|
||||||
|
pattern: main.PatternGroupTitleHyphenSE,
|
||||||
|
want: main.Fields{
|
||||||
|
Title: "Wistoria Wand and Sword",
|
||||||
|
Season: "01",
|
||||||
|
Episode: "01",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"[EMBER] Ao no Hako - 01.mkv": {
|
||||||
|
pattern: main.PatternGroupTitleHyphenSE,
|
||||||
|
want: main.Fields{
|
||||||
|
Title: "Ao no Hako",
|
||||||
|
Season: "",
|
||||||
|
Episode: "01",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Niehime to Kemono no Ou - 12 [darkflux].mkv": {
|
||||||
|
pattern: main.PatternGroupTitleHyphenSE,
|
||||||
|
want: main.Fields{
|
||||||
|
Title: "Niehime to Kemono no Ou",
|
||||||
|
Season: "",
|
||||||
|
Episode: "12",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for f, d := range cases {
|
||||||
|
c := d
|
||||||
|
t.Run(f, func(t *testing.T) {
|
||||||
|
got, _ := main.Parse(f, c.pattern)
|
||||||
|
if got != c.want {
|
||||||
|
t.Errorf("expected \n\t%+v but got \n\t%+v", c.want, got)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user