Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 0 additions & 88 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,94 +112,6 @@ func TestMatchRECacheLimit(t *testing.T) {
}
}

func TestReleasePredicates(t *testing.T) {
parsed := func(s string) Release { return ParseString(s) }

repackCleared := parsed("Show.S01E02.1080p.WEB.REPACK.h264-GRP")
repackCleared.Other = nil
// Other is what the predicates follow, not the tags of the name
repackSet := parsed("Show.S01E02.1080p.WEB.h264-GRP")
repackSet.Other = []string{"REPACK"}

tests := []struct {
name string
r Release
proper, repack, remux, hybrid bool
}{
{"plain", parsed("Show.S01E02.1080p.WEB.h264-GRP"), false, false, false, false},
{"repack2 set by hand", Release{Other: []string{"REPACK2"}}, false, true, false, false},
{"repack1 set by hand", Release{Other: []string{"REPACK1"}}, false, false, false, false},
{"proper", parsed("Show.S01E02.PROPER.1080p.WEB.h264-GRP"), true, false, false, false},
{"real proper", parsed("Show.S01E02.REAL.PROPER.1080p.WEB.h264-GRP"), true, false, false, false},
{"repack", parsed("Show.S01E02.REPACK.1080p.WEB.h264-GRP"), false, true, false, false},
{"repacked", parsed("Show.S01E02.Repacked.1080p.WEB.h264-GRP"), false, true, false, false},
{"rerepack", parsed("Show.S01E02.REREPACK.1080p.WEB.h264-GRP"), false, true, false, false},
{"repack2", parsed("Show.S01E02.REPACK2.1080p.WEB.h264-GRP"), false, true, false, false},
{"re-pack", parsed("Show.S01E02.Re-Pack.1080p.WEB.h264-GRP"), false, true, false, false},
{"repack3", parsed("Show.S01E02.REPACK3.1080p.WEB.h264-GRP"), false, true, false, false},
{"repack10", parsed("Show.S01E02.REPACK10.1080p.WEB.h264-GRP"), false, true, false, false},
{"repack25", parsed("Show.S01E02.1080p.WEB.REPACK25.h264-GRP"), false, true, false, false},
{"repack10 set by hand", Release{Other: []string{"repack10"}}, false, true, false, false},
{"repack05 set by hand", Release{Other: []string{"REPACK05"}}, false, false, false, false},
{"repack100 set by hand", Release{Other: []string{"REPACK100"}}, false, false, false, false},
{"repack1x set by hand", Release{Other: []string{"REPACK1x"}}, false, false, false, false},
{"repack9 in lower case", parsed("Show.S01E02.repack9.1080p.WEB.h264-GRP"), false, true, false, false},
{"rerip", parsed("Show.S01E02.RERIP.1080p.WEB.h264-GRP"), false, false, false, false},
{"hybrid remux", parsed("Movie.2020.Hybrid.1080p.BluRay.REMUX.AVC.DTS-HD.MA.5.1-GRP"), false, false, true, true},
{"proper and repack", parsed("Show.S01E02.PROPER.REPACK.1080p.WEB.h264-GRP"), true, true, false, false},
{"lower case proper", parsed("Show.S01E02.proper.1080p.WEB.h264-GRP"), true, false, false, false},

{"proper as a title word", parsed("Proper.Show.S01E02.1080p.WEB.h264-GRP"), false, false, false, false},
{"proper as the group", parsed("Show.S01E02.1080p.WEB.h264-PROPER"), false, false, false, false},
{"hybrid as the group", parsed("Movie.2020.1080p.BluRay.x264-HYBRiD"), false, false, false, false},
{"real proper with a hyphen", parsed("Show.S01E02.Real-Proper.1080p.WEB.h264-GRP"), true, false, false, false},
{"remux before the group", parsed("Movie.2020.2160p.UHD.BluRay.HEVC.TrueHD.7.1.Remux-GRP"), false, false, true, false},
{"bdremux in one word", parsed("Movie.2020.1080p.BDRemux.AVC.DTS-HD.MA.5.1-GRP"), false, false, true, false},
// a trailing bracket of the flag is the flag, not the site
{"repack2 in a trailing bracket", parsed("Movie (2020) (1080p BluRay x265 - GRP) [REPACK2]"), false, true, false, false},
{"repack3 in a trailing bracket", parsed("Movie (2020) (1080p BluRay x265 - GRP) [Repack3]"), false, true, false, false},
{"re-pack in a trailing bracket", parsed("Movie.2020.1080p.BluRay.x264-GRP[RE-PACK]"), false, true, false, false},
{"real proper in a trailing bracket", parsed("Movie.2020.1080p.BluRay.x264-GRP[REAL.PROPER]"), true, false, false, false},
// and so is a leading one, in front of the group's bracket too
{"repack2 in a leading bracket", parsed("[REPACK2] Movie.2020.1080p.BluRay.x264-GRP"), false, true, false, false},
{"proper in a leading bracket", parsed("[PROPER][Group] Show - 01 [1080p]"), true, false, false, false},

{"zero", Release{}, false, false, false, false},
{"hand proper", Release{Other: []string{"proper"}}, true, false, false, false},
{"hand hybrid", Release{Other: []string{"HYBRID"}}, false, false, false, true},
{"hand remux repack", Release{Other: []string{"REMUX", "REPACK"}}, false, true, true, false},
{"hand rerip", Release{Other: []string{"RERiP"}}, false, false, false, false},
{"other cleared after parse", repackCleared, false, false, false, false},
{"hand real proper", Release{Other: []string{"real.proper"}}, true, false, false, false},
{"hand rerepack", Release{Other: []string{"ReRePack"}}, false, true, false, false},
{"other set after parse", repackSet, false, true, false, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := [4]bool{tt.r.IsProper(), tt.r.IsRepack(), tt.r.IsRemux(), tt.r.IsHybrid()}
want := [4]bool{tt.proper, tt.repack, tt.remux, tt.hybrid}
if got != want {
t.Errorf("proper/repack/remux/hybrid = %v, want %v (Other=%q)", got, want, tt.r.Other)
}
})
}
}

func TestReleasePredicatesAllocs(t *testing.T) {
r := ParseString("Movie.2020.Hybrid.PROPER.REPACK.1080p.BluRay.REMUX.AVC.DTS-HD.MA.5.1-GRP")
preds := map[string]func() bool{
"IsProper": r.IsProper,
"IsRepack": r.IsRepack,
"IsRemux": r.IsRemux,
"IsHybrid": r.IsHybrid,
}
for name, f := range preds {
if n := testing.AllocsPerRun(100, func() { f() }); n != 0 {
t.Errorf("%s allocates %v times, want 0", name, n)
}
}
}

func TestCompareResolution(t *testing.T) {
for _, test := range []struct {
a, b string
Expand Down
24 changes: 24 additions & 0 deletions cmd/rls/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,27 @@ func TestRunDynamicRange(t *testing.T) {
}
}
}

// TestRunFlags checks the flags and the repack, and the two keys read from
// them.
func TestRunFlags(t *testing.T) {
tests := []struct {
name string
exp []string
}{
{"Show.S01E02.1080p.WEB.h264-GRP", []string{`"flags":[]`, `"repack":0`, `"is_proper":false`, `"is_repack":false`}},
{"Show.S01E02.REAL.PROPER.REPACK2.1080p.WEB.h264-GRP", []string{`"flags":["PROPER","REAL"]`, `"repack":2`, `"is_proper":true`, `"is_repack":true`}},
{"Movie.2020.1080p.BluRay.REMUX.AVC.DTS-HD.MA.5.1-GRP", []string{`"flags":["REMUX"]`, `"repack":0`, `"is_proper":false`, `"is_repack":false`}},
}
for _, tt := range tests {
var buf bytes.Buffer
if err := run(&buf, nil, []string{tt.name}); err != nil {
t.Fatalf("expected no error, got: %v", err)
}
for _, s := range tt.exp {
if !strings.Contains(buf.String(), s) {
t.Errorf("%q: expected output to contain %s, got: %s", tt.name, s, buf.String())
}
}
}
}
124 changes: 64 additions & 60 deletions cmd/rls/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,22 @@ type releaseOutput struct {
Edition []string `json:"edition"`
Language []string `json:"language"`

Size string `json:"size"`
Region string `json:"region"`
Container string `json:"container"`
Genre string `json:"genre"`
ID string `json:"id"`
Group string `json:"group"`
Meta []string `json:"meta"`
Site string `json:"site"`
Sum string `json:"sum"`
Pass string `json:"pass"`
Req bool `json:"req"`
Ext string `json:"ext"`
IsProper bool `json:"is_proper"`
IsRepack bool `json:"is_repack"`
Size string `json:"size"`
Region string `json:"region"`
Container string `json:"container"`
Genre string `json:"genre"`
ID string `json:"id"`
Group string `json:"group"`
Meta []string `json:"meta"`
Site string `json:"site"`
Sum string `json:"sum"`
Pass string `json:"pass"`
Req bool `json:"req"`
Ext string `json:"ext"`
Flags rls.Flags `json:"flags"`
Repack int `json:"repack"`
IsProper bool `json:"is_proper"`
IsRepack bool `json:"is_repack"`
}

// numberingOutput is the JSON form of the numbering of a release, field by
Expand Down Expand Up @@ -154,57 +156,59 @@ func episodes(n rls.Numbering) [][]int {
return slices.CompactFunc(v, slices.Equal[[]int])
}

func rlsToOutput(rls rls.Release) releaseOutput {
series, hasSeason := rls.Numbering.Season()
episode, hasEpisode := rls.Numbering.Episode()
func rlsToOutput(rel rls.Release) releaseOutput {
series, hasSeason := rel.Numbering.Season()
episode, hasEpisode := rel.Numbering.Episode()
return releaseOutput{
Artist: rls.Artist,
Type: rls.Type.String(),
Title: rls.Title,
Subtitle: rls.Subtitle,
Alt: orEmpty(rls.Alt),
Platform: rls.Platform,
Arch: rls.Arch,
Source: rls.Source,
Resolution: rls.Resolution,
FrameRate: rls.FrameRate,
Collection: rls.Collection,
Year: rls.Year,
Month: rls.Month,
Day: rls.Day,
YearEnd: rls.YearEnd,
Artist: rel.Artist,
Type: rel.Type.String(),
Title: rel.Title,
Subtitle: rel.Subtitle,
Alt: orEmpty(rel.Alt),
Platform: rel.Platform,
Arch: rel.Arch,
Source: rel.Source,
Resolution: rel.Resolution,
FrameRate: rel.FrameRate,
Collection: rel.Collection,
Year: rel.Year,
Month: rel.Month,
Day: rel.Day,
YearEnd: rel.YearEnd,
HasSeason: hasSeason,
Series: series,
Seasons: orEmpty(seasons(rls.Numbering)),
Seasons: orEmpty(seasons(rel.Numbering)),
HasEpisode: hasEpisode,
Episode: episode,
Episodes: orEmpty(episodes(rls.Numbering)),
Numbering: numberingToOutput(rls.Numbering),
Version: rls.Version,
Disc: rls.Disc,
Codec: orEmpty(rls.Codec),
DynamicRange: rls.DynamicRange,
BitDepth: rls.BitDepth,
Audio: orEmpty(rls.Audio),
Channels: rls.Channels,
Other: orEmpty(rls.Other),
Cut: orEmpty(rls.Cut),
Edition: orEmpty(rls.Edition),
Language: orEmpty(rls.Language),
Size: rls.Size,
Region: rls.Region,
Container: rls.Container,
Genre: rls.Genre,
ID: rls.ID,
Group: rls.Group,
Meta: orEmpty(rls.Meta),
Site: rls.Site,
Sum: rls.Sum,
Pass: rls.Pass,
Req: rls.Req,
Ext: rls.Ext,
IsProper: rls.IsProper(),
IsRepack: rls.IsRepack(),
Episodes: orEmpty(episodes(rel.Numbering)),
Numbering: numberingToOutput(rel.Numbering),
Version: rel.Version,
Disc: rel.Disc,
Codec: orEmpty(rel.Codec),
DynamicRange: rel.DynamicRange,
BitDepth: rel.BitDepth,
Audio: orEmpty(rel.Audio),
Channels: rel.Channels,
Other: orEmpty(rel.Other),
Cut: orEmpty(rel.Cut),
Edition: orEmpty(rel.Edition),
Language: orEmpty(rel.Language),
Size: rel.Size,
Region: rel.Region,
Container: rel.Container,
Genre: rel.Genre,
ID: rel.ID,
Group: rel.Group,
Meta: orEmpty(rel.Meta),
Site: rel.Site,
Sum: rel.Sum,
Pass: rel.Pass,
Req: rel.Req,
Ext: rel.Ext,
Flags: rel.Flags,
Repack: rel.Repack,
IsProper: rel.Flags.Has(rls.FlagProper),
IsRepack: rel.Repack != 0,
}
}

Expand Down
13 changes: 13 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,16 @@ func ExampleDynamicRange() {
// true
// false
}

func ExampleFlags() {
r := rls.ParseString("Movie.2020.REAL.PROPER.REPACK2.1080p.BluRay.x264-GRP")
fmt.Printf("%q\n", r.Other)
fmt.Println(r.Flags)
fmt.Println(r.Flags.Has(rls.FlagProper))
fmt.Println(r.Repack)
// Output:
// ["REAL.PROPER" "REREPACK"]
// PROPER,REAL
// true
// 2
}
Loading
Loading