diff --git a/accuracy_test.go b/accuracy_test.go index f9f8657..c4fdeee 100644 --- a/accuracy_test.go +++ b/accuracy_test.go @@ -157,9 +157,9 @@ func (t tally) pct() float64 { // down to a whole percent, and 99 where the measured value is 100: a change // that trades a case away has to lower its floor and say why. var floors = map[string]map[string]float64{ - "anitomy.json": {"title": 65, "group": 92, "episode": 64, "episodeTitle": 69, "season": 90, "checksum": 99, "ext": 99, "resolution": 90, "version": 92}, - "habari.json": {"title": 70, "group": 89, "episode": 63, "episodeTitle": 55, "season": 89, "checksum": 99, "ext": 99, "resolution": 93, "version": 71}, - "anitogo.json": {"title": 65, "group": 93, "episode": 63, "episodeTitle": 65, "season": 93, "checksum": 99, "ext": 99, "resolution": 90, "version": 92}, + "anitomy.json": {"title": 65, "group": 92, "episode": 65, "episodeTitle": 69, "season": 90, "checksum": 99, "ext": 99, "resolution": 90, "version": 92}, + "habari.json": {"title": 70, "group": 89, "episode": 65, "episodeTitle": 55, "season": 89, "checksum": 99, "ext": 99, "resolution": 93, "version": 71}, + "anitogo.json": {"title": 65, "group": 93, "episode": 64, "episodeTitle": 65, "season": 93, "checksum": 99, "ext": 99, "resolution": 90, "version": 92}, } // upstream are the SHA-256 sums of the committed fixtures, which are the files @@ -210,15 +210,18 @@ func TestAccuracyLabelled(t *testing.T) { if g := first(c.ReleaseGroup); g != "" { get("group").add(strings.EqualFold(r.Group, g)) } - if e := first(c.EpisodeNumber); e != "" { - get("episode").add(r.HasEpisode() && r.Episode == fixtureNum(e)) + // one label is one episode, and a list is the two ends of + // the episodes a batch gives + if v, _ := values(c.EpisodeNumber); len(v) != 0 && v[0] != "" { + get("episode").add(slices.Equal(episodes(r), sampleNums(v))) } season := first(c.AnimeSeason) if season == "" { season = first(c.SeasonNumber) } if season != "" { - get("season").add(r.Series == fixtureNum(season)) + n, _ := r.Numbering.Season() + get("season").add(n == fixtureNum(season)) } if s := first(c.FileChecksum); s != "" { get("checksum").add(strings.EqualFold(r.Sum, s)) @@ -259,37 +262,38 @@ var sampleFloors = map[string]map[string]int{ // episodes gives the episodes of r as a sample writes them: nothing for a // release with none, one number for one episode, the two ends of a range. -// Half an episode keeps its fraction at either end ('18.5', '1-11.5'). +// Half an episode keeps its fraction ('18.5', '1-11.5'). func episodes(r Release) []string { - first, last, ranged := r.EpisodeRange() + first, last, ranged := episodeRange(r.Numbering) if !ranged { - if !r.HasEpisode() { + episode, ok := r.Numbering.Episode() + if !ok { return nil } - first, last = r.Episode, r.Episode + first, last = episode, episode } - // the fraction is only in the digits the name wrote. The first span that - // writes the number has it, read from the end of the name for the end of - // a range, so that 'S01E12 + S01E12.5' is episode 12 and '1-11.5' ends - // at 11.5 + // the fraction is that of the first Ep that writes the number, read from + // the end of the name for the end of a range, so that 'S01E12 + + // S01E12.5' is episode 12 and '1-11.5' ends at 11.5. It belongs to the + // Last of an Ep, which is the episode itself when the Ep is no range frac := func(n int, end bool) string { - spans := r.EpisodeSpans() + eps := slices.Clone(r.Numbering.Episodes) if end { - slices.Reverse(spans) + slices.Reverse(eps) } - for _, span := range spans { - ends := []string{span.First, span.Last} + for _, e := range eps { + ends := []int{e.First, e.Last} if end { slices.Reverse(ends) } - for _, s := range ends { - if s != "" && wholeEpisode(s) == n { - _, f, _ := strings.Cut(s, ".") - if f = strings.TrimRight(f, "0"); f != "" { - return "." + f - } - return "" + for _, episode := range ends { + if episode != n { + continue + } + if e.Frac != 0 && n == e.Last { + return "." + strconv.Itoa(int(e.Frac)) } + return "" } } return "" @@ -349,11 +353,10 @@ func scoreSample(c labelledCase, r Release) map[string]bool { m["type"] = anyOf(v, r.Type.String(), strings.EqualFold) } if v, ok := values(c.AnimeSeason); ok { + // in rising order, as a sample lists them var got []string - if r.HasSeason() { - for _, n := range r.Seasons() { - got = append(got, strconv.Itoa(n)) - } + for _, n := range slices.Sorted(slices.Values(r.Numbering.Seasons)) { + got = append(got, strconv.Itoa(n)) } m["season"] = slices.Equal(got, sampleNums(v)) } @@ -630,8 +633,8 @@ func TestCorpusStructural(t *testing.T) { } // TestAbsoluteEpisode pins the distinction between the three ways a release can -// carry an episode number. Release.Episode alone cannot tell them apart, which -// is why Absolute exists. +// carry an episode number. Numbering.Episode alone cannot tell them apart, +// which is why Absolute exists. func TestAbsoluteEpisode(t *testing.T) { for _, test := range []struct { s string @@ -650,9 +653,9 @@ func TestAbsoluteEpisode(t *testing.T) { {"[Group] Show Title E05-E07 [1080p]", 0, 5, 0, false, "the ends of a range between two tags are not one episode"}, {"[Group] Show Title (E001-E130) (480p)", 0, 1, 0, false, "the same in a bracket"}, {"[Group] Show Title E05~E07 [1080p]", 0, 5, 0, false, "and with a tilde"}, - {"[Group] Show Title E07-E05 [1080p]", 0, 7, 7, true, "a lower number after the hyphen is no range"}, + {"[Group] Show Title E07-E05 [1080p]", 0, 7, 0, false, "a lower number after the hyphen is no range, and two episodes have no absolute number"}, {"[Group] Show Title - 21.5 (720p) [4191AC97].mkv", 0, 21, 0, false, "half an episode has no absolute number"}, - {"[Group] Show Title - 01 ~ 12 [1080p][BATCH]", 0, 0, 0, false, "a batch is a range, not an episode"}, + {"[Group] Show Title - 01 ~ 12 [1080p][BATCH]", 0, 1, 0, false, "a batch is a range, not an episode, and starts at its first"}, {"[SubsPlease] Hell Mode S2 - 04 (480p) [20BE14E8].mkv", 2, 4, 0, false, "season marker qualifies it: not absolute"}, {"Show.Title.S01E05.1080p.WEB-DL-GRP", 1, 5, 0, false, "SxxExx is qualified"}, {"Show.Title.S00E05.1080p.WEB-DL-GRP", 0, 5, 0, false, "S00Exx is a special, not an absolute number"}, @@ -660,11 +663,13 @@ func TestAbsoluteEpisode(t *testing.T) { {"Show.Title.2024.03.11.1080p.WEB-DL-GRP", 0, 0, 0, false, "date based, no episode at all"}, } { t.Run(test.desc, func(t *testing.T) { - r := ParseString(test.s) - absolute, ok := r.Absolute() - if r.Series != test.series || r.Episode != test.episode || absolute != test.absolute || ok != test.ok { + n := ParseString(test.s).Numbering + series, _ := n.Season() + episode, _ := n.Episode() + absolute, ok := n.Absolute() + if series != test.series || episode != test.episode || absolute != test.absolute || ok != test.ok { t.Errorf("%q\n expected series=%d episode=%d absolute=%d ok=%t\n got series=%d episode=%d absolute=%d ok=%t", - test.s, test.series, test.episode, test.absolute, test.ok, r.Series, r.Episode, absolute, ok) + test.s, test.series, test.episode, test.absolute, test.ok, series, episode, absolute, ok) } }) } @@ -676,30 +681,42 @@ func TestAbsoluteInvariants(t *testing.T) { if testing.Short() { t.Skip("skipping corpus walk in short mode") } - f, err := os.Open(corpusDir + "/nyaa.txt") - if err != nil { - t.Skipf("corpus not present: %v", err) - } - defer f.Close() - sc := bufio.NewScanner(f) - sc.Buffer(make([]byte, 1<<20), 1<<20) - var n, abs int - for sc.Scan() { - line := strings.TrimSpace(sc.Text()) - if line == "" { + var n, abs, second int + for _, line := range corpusNames(t, "nyaa.txt") { + n++ + num := ParseString(line).Numbering + absolute, ok := num.Absolute() + if !ok { continue } - n++ - r := ParseString(line) - switch absolute, ok := r.Absolute(); { - case !ok: - case absolute != r.Episode: - t.Fatalf("%q: Absolute %d does not match Episode %d", line, absolute, r.Episode) - case r.Series != 0: - t.Fatalf("%q: Absolute %d set alongside season %d", line, absolute, r.Series) - default: + // with no season the absolute episode is the one episode of the + // name, which Episode gives. Beside a season it is a second + // numbering, which is another number than the season's episode and + // not inside a range the name writes ('S04E29-31v2') + season, seasoned := num.Season() + episode, _ := num.Episode() + one := func(e Ep) bool { return e.First == absolute && e.Last == absolute && e.Frac == 0 } + ranged := slices.ContainsFunc(num.Episodes, func(e Ep) bool { + return e.First != e.Last && e.First <= absolute && absolute <= e.Last + }) + switch { + case !seasoned && absolute != episode: + t.Fatalf("%q: Absolute %d does not match Episode %d", line, absolute, episode) + case !seasoned && num.Shape() != ShapeEpisode: + t.Fatalf("%q: Absolute %d of more than one episode, %v", line, absolute, num.Episodes) + case !seasoned: abs++ + case season == 0: + t.Fatalf("%q: Absolute %d set alongside the specials", line, absolute) + case absolute == episode: + t.Fatalf("%q: Absolute %d is the episode of season %d", line, absolute, season) + case ranged: + t.Fatalf("%q: Absolute %d is inside a range of episodes of season %d", line, absolute, season) + case !slices.ContainsFunc(num.Alt, one): + t.Fatalf("%q: Absolute %d is no second numbering of %v", line, absolute, num.Alt) + default: + second++ } } - t.Logf("%d of %d names carry an absolute episode number", abs, n) + t.Logf("%d of %d names carry an absolute episode number, %d of them beside a season and an episode", abs+second, n, second) } diff --git a/bounds_test.go b/bounds_test.go index ae0efd3..d5daf61 100644 --- a/bounds_test.go +++ b/bounds_test.go @@ -429,9 +429,9 @@ func TestJoinReadings(t *testing.T) { {"Show.S01.S02.1080p.WEB-DL.x264-GRP", "Show", "GRP", "", []int{1, 2}}, } { r := ParseString(test.s) - if r.Title != test.title || r.Group != test.group || r.Genre != test.genre || fmt.Sprint(r.Seasons()) != fmt.Sprint(test.seasons) { + if r.Title != test.title || r.Group != test.group || r.Genre != test.genre || fmt.Sprint(r.Numbering.Seasons) != fmt.Sprint(test.seasons) { t.Errorf("%q expected title %q, group %q, genre %q, seasons %v, got: %q, %q, %q, %v", - test.s, test.title, test.group, test.genre, test.seasons, r.Title, r.Group, r.Genre, r.Seasons()) + test.s, test.title, test.group, test.genre, test.seasons, r.Title, r.Group, r.Genre, r.Numbering.Seasons) } } } diff --git a/cmd/rls/main_test.go b/cmd/rls/main_test.go index d9a39df..47015f8 100644 --- a/cmd/rls/main_test.go +++ b/cmd/rls/main_test.go @@ -198,3 +198,72 @@ func TestRunEmptyLists(t *testing.T) { t.Errorf("expected empty lists as [], got: %s", buf.String()) } } + +// TestRunNumbering checks the keys that give the seasons and the episodes of +// a release: those a line has always had, and the numbering object that +// spells the fields out. +func TestRunNumbering(t *testing.T) { + tests := []struct { + name string + exp []string + }{ + { + "Show.S01E02-E04.1080p.WEB.h264-GRP", + []string{ + `"has_season":true,"series":1,"seasons":[1],"has_episode":true,"episode":2,"episodes":[[1,2],[1,3],[1,4]]`, + `"numbering":{"scheme":"seasoned","shape":"episodes","seasons":[1],"episodes":[{"season":1,"first":2,"last":4,"frac":0,"kind":""}],"alt":[],"volume":0,"contents":[],"batch":false}`, + }, + }, + // an episode with no season is in season 0 under episodes, and in + // season -1 in the numbering + { + "[Grp] Show - 01-03 [1080p]", + []string{ + `"has_season":false,"series":0,"seasons":[],"has_episode":true,"episode":1,"episodes":[[0,1],[0,2],[0,3]]`, + `"numbering":{"scheme":"absolute","shape":"episodes","seasons":[],"episodes":[{"season":-1,"first":1,"last":3,"frac":0,"kind":""}],"alt":[]`, + }, + }, + // seasons are in rising order under seasons, and in the order of the + // name in the numbering + { + "[Grp] Show [Season 2 + Season 1 OVA] [BD 1080p]", + []string{ + `"has_season":true,"series":2,"seasons":[1,2],"has_episode":false,"episode":0,"episodes":[]`, + `"numbering":{"scheme":"seasoned","shape":"seasons","seasons":[2,1],"episodes":[],"alt":[]`, + }, + }, + { + "Show.S23E19.Episode.1174.1080p.WEB.h264-GRP", + []string{ + `"has_season":true,"series":23,"seasons":[23],"has_episode":true,"episode":19,"episodes":[[23,19]]`, + `"episodes":[{"season":23,"first":19,"last":19,"frac":0,"kind":""}],"alt":[{"season":-1,"first":1174,"last":1174,"frac":0,"kind":""}]`, + }, + }, + { + "[Grp] Show - 21.5 [1080p]", + []string{`"episodes":[{"season":-1,"first":21,"last":21,"frac":5,"kind":""}]`}, + }, + { + "Show.2024.03.11.1080p.WEB.h264-GRP", + []string{ + `"has_season":false,"series":0,"seasons":[],"has_episode":false,"episode":0,"episodes":[]`, + `"numbering":{"scheme":"daily","shape":"daily","seasons":[],"episodes":[],"alt":[],"volume":0,"contents":[],"batch":false}`, + }, + }, + { + "The.Matrix.1999.1080p.BluRay.x264-GROUP", + []string{`"numbering":{"scheme":"","shape":"","seasons":[],"episodes":[],"alt":[],"volume":0,"contents":[],"batch":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()) + } + } + } +} diff --git a/cmd/rls/parse.go b/cmd/rls/parse.go index a52c3c3..d624e1f 100644 --- a/cmd/rls/parse.go +++ b/cmd/rls/parse.go @@ -4,6 +4,7 @@ import ( "bufio" "encoding/json" "io" + "slices" "strings" "github.com/autobrr/rls" @@ -54,14 +55,15 @@ type releaseOutput struct { Day int `json:"day"` YearEnd int `json:"year_end"` - HasSeason bool `json:"has_season"` - Series int `json:"series"` - Seasons []int `json:"seasons"` - HasEpisode bool `json:"has_episode"` - Episode int `json:"episode"` - Episodes [][]int `json:"episodes"` - Version string `json:"version"` - Disc string `json:"disc"` + HasSeason bool `json:"has_season"` + Series int `json:"series"` + Seasons []int `json:"seasons"` + HasEpisode bool `json:"has_episode"` + Episode int `json:"episode"` + Episodes [][]int `json:"episodes"` + Numbering numberingOutput `json:"numbering"` + Version string `json:"version"` + Disc string `json:"disc"` Codec []string `json:"codec"` HDR []string `json:"dynamic_range"` @@ -89,7 +91,72 @@ type releaseOutput struct { IsRepack bool `json:"is_repack"` } +// numberingOutput is the JSON form of the numbering of a release, field by +// field. Shape is what the numbering covers, which the fields give together. +type numberingOutput struct { + Scheme string `json:"scheme"` + Shape string `json:"shape"` + Seasons []int `json:"seasons"` + Episodes []epOutput `json:"episodes"` + Alt []epOutput `json:"alt"` + Volume int `json:"volume"` + Contents []string `json:"contents"` + Batch bool `json:"batch"` +} + +// epOutput is the JSON form of one episode or range of episodes. Season is -1 +// for an episode the name gives no season for. +type epOutput struct { + Season int `json:"season"` + First int `json:"first"` + Last int `json:"last"` + Frac int `json:"frac"` + Kind string `json:"kind"` +} + +func numberingToOutput(n rls.Numbering) numberingOutput { + eps := func(v []rls.Ep) []epOutput { + out := make([]epOutput, 0, len(v)) + for _, e := range v { + out = append(out, epOutput{Season: e.Season, First: e.First, Last: e.Last, Frac: int(e.Frac), Kind: e.Kind.String()}) + } + return out + } + return numberingOutput{ + Scheme: n.Scheme.String(), + Shape: n.Shape().String(), + Seasons: orEmpty(n.Seasons), + Episodes: eps(n.Episodes), + Alt: eps(n.Alt), + Volume: n.Volume, + Contents: orEmpty(n.Contents), + Batch: n.Batch, + } +} + +// seasons returns the seasons of n in rising order, which is how the seasons +// key lists them. +func seasons(n rls.Numbering) []int { + v := slices.Clone(n.Seasons) + slices.Sort(v) + return v +} + +// episodes returns each season and episode of n once and in rising order, +// with the episodes inside a range, which is how the episodes key lists them. +// An episode the name gives no season for is in season 0 there. +func episodes(n rls.Numbering) [][]int { + var v [][]int + for season, episode := range n.All() { + v = append(v, []int{max(season, 0), episode}) + } + slices.SortFunc(v, slices.Compare[[]int]) + return slices.CompactFunc(v, slices.Equal[[]int]) +} + func rlsToOutput(rls rls.Release) releaseOutput { + series, hasSeason := rls.Numbering.Season() + episode, hasEpisode := rls.Numbering.Episode() return releaseOutput{ Artist: rls.Artist, Type: rls.Type.String(), @@ -106,12 +173,13 @@ func rlsToOutput(rls rls.Release) releaseOutput { Month: rls.Month, Day: rls.Day, YearEnd: rls.YearEnd, - HasSeason: rls.HasSeason(), - Series: rls.Series, - Seasons: orEmpty(rls.Seasons()), - HasEpisode: rls.HasEpisode(), - Episode: rls.Episode, - Episodes: orEmpty(rls.SeriesEpisodes()), + HasSeason: hasSeason, + Series: series, + Seasons: orEmpty(seasons(rls.Numbering)), + HasEpisode: hasEpisode, + Episode: episode, + Episodes: orEmpty(episodes(rls.Numbering)), + Numbering: numberingToOutput(rls.Numbering), Version: rls.Version, Disc: rls.Disc, Codec: orEmpty(rls.Codec), diff --git a/event.go b/event.go index 859e8e5..c172883 100644 --- a/event.go +++ b/event.go @@ -58,13 +58,24 @@ type Event struct { // A release parsed with Hint.Sports is an event on the caller's word. Event // then returns true for any name of any type, with an empty Competition when // it knows none, and with whatever round, session and part the name gives. +// +// Two things a parse knows are not in the exported fields: that hint, and +// whether the name writes an episode or the range of a batch. A Release with +// no tags, made by hand or decoded from a stored form, is read without the +// hint and by its Numbering alone, where every range with no season counts as +// a batch: 'UFC 300 - E01-E03 [1080p]' is a show when parsed, and an event +// once its tags are gone. func (r Release) Event() (Event, bool) { + season, _ := r.Numbering.Season() + episode, _ := r.Numbering.Episode() if !r.sports { switch r.Type { case App, Audiobook, Book, Comic, Education, Game, Magazine, Music: return Event{}, false } - if r.Series != 0 && r.Series < 1900 || r.Series == 0 && r.Episode != 0 { + // an episode of no season is a show ('WWE.Unreal.E02'), where the + // range of a batch is no episode ('UFC 300 - 01-03 [1080p]') + if season != 0 && season < 1900 || season == 0 && r.showEpisode() { return Event{}, false } } @@ -161,8 +172,8 @@ func (r Release) Event() (Event, bool) { } // 'Formula1.2024x05' and 'S2024E05' give the year as the season and the // round as the episode - if ev.Round == 0 && plain && r.Series >= 1900 && r.Episode != 0 { - ev.Round, ev.RoundKind, found = r.Episode, "Round", true + if ev.Round == 0 && plain && season >= 1900 && episode != 0 { + ev.Round, ev.RoundKind, found = episode, "Round", true } switch { case r.sports, found, ev.Number != 0, @@ -375,3 +386,21 @@ var eventNumberWords = map[string]int{ "first": 1, "second": 2, "third": 3, "fourth": 4, "fifth": 5, "sixth": 6, "seventh": 7, "erste": 1, "zweite": 2, "dritte": 3, "vierte": 4, } + +// showEpisode reports whether the release gives an episode other than 0 that +// is not the range of a batch, which makes a show of a name that starts with a +// competition. A parse knows it from its tags, where a range is that of a +// batch when its tag writes no episode in its first place ('01-12', and not +// 'E01-E03'). A release with no tags is read by its Numbering: an Ep counts +// when it is one episode or is in a season. +func (r Release) showEpisode() bool { + if r.tags != nil { + return r.numbered + } + for _, e := range r.Numbering.Episodes { + if e.Kind == EpRegular && (e.single() || e.Season != NoSeason) && (e.First != 0 || e.Last != 0) { + return true + } + } + return false +} diff --git a/event_test.go b/event_test.go index 6005533..77f6c8e 100644 --- a/event_test.go +++ b/event_test.go @@ -1,6 +1,7 @@ package rls import ( + "encoding/json" "strings" "testing" ) @@ -321,3 +322,65 @@ func TestEventHint(t *testing.T) { } } } + +// TestEventRoundTrip checks Event on a release that lost its tags: one decoded +// from its JSON holds the exported fields and nothing else a parse keeps. It +// gives the same event for every name of tests.yaml and of the corpora that +// are present, and for a batch after a competition. The one shape that +// differs is pinned: a range of episodes with no season that is written with +// an 'E', which only the tags tell from the range of a batch. +func TestEventRoundTrip(t *testing.T) { + trip := func(r Release) Release { + buf, err := json.Marshal(r) + if err != nil { + t.Fatalf("%q: %v", r, err) + } + var v Release + if err := json.Unmarshal(buf, &v); err != nil { + t.Fatalf("%q: %v", r, err) + } + return v + } + names := benchCorpus(t) + if !testing.Short() { + for _, file := range []string{"nyaa.txt", "sports.txt"} { + v, _ := readCorpus(file) + names = append(names, v...) + } + } + var events int + for _, name := range names { + r := ParseString(name) + ev, ok := r.Event() + if ok { + events++ + } + if ev2, ok2 := trip(r).Event(); ev2 != ev || ok2 != ok { + t.Errorf("%q: expected the event of the parse after a round trip, %+v %t, got: %+v %t", name, ev, ok, ev2, ok2) + } + } + t.Logf("%d names, %d events", len(names), events) + for _, test := range []struct { + name string + parsed, tripped bool + }{ + {"UFC.300.Prelims.1080p.WEB.h264-GRP", true, true}, + {"Formula1.2024x05.Miami.Grand.Prix.Race.1080p.WEB.h264-GRP", true, true}, + // a show about the sport + {"WWE.Unreal.E02.1080p.WEB.h264-GRP", false, false}, + {"WWE.Unreal.S01E02.1080p.WEB.h264-GRP", false, false}, + // the range of a batch is no episode + {"UFC 300 - 01-03 [1080p]", true, true}, + {"WWE Raw 2024 - 01-05 [1080p]", true, true}, + // and with no tags a range written with an 'E' reads as one + {"UFC 300 - E01-E03 [1080p]", false, true}, + } { + r := ParseString(test.name) + if _, ok := r.Event(); ok != test.parsed { + t.Errorf("%q: expected an event %t when parsed, got: %t", test.name, test.parsed, ok) + } + if _, ok := trip(r).Event(); ok != test.tripped { + t.Errorf("%q: expected an event %t after a round trip, got: %t", test.name, test.tripped, ok) + } + } +} diff --git a/fuzz_test.go b/fuzz_test.go index a4c5c8c..3ad34d7 100644 --- a/fuzz_test.go +++ b/fuzz_test.go @@ -11,8 +11,14 @@ import ( func exercise(r Release) { _ = r.String() _ = fmt.Sprintf("%o|%s|%e|%q", r, r, r, r) - _ = r.SeriesEpisodes() - _ = r.EpisodeSpans() + n := r.Numbering + _, _ = n.Season() + _, _ = n.Episode() + _, _ = n.Absolute() + _ = fmt.Sprint(n.Scheme, n.Shape()) + for season, episode := range n.All() { + _, _ = season, episode + } _, _ = r.Event() for _, tag := range r.Tags() { _ = tag.Normalize() @@ -93,7 +99,8 @@ func checkTags(tb testing.TB, s string) { // without tagging them loses part of the name silently, and nothing else would // notice. checkTags makes the same comparison on the tags straight out of // Parse, with no Build in between, so a failure names the lexing step. And it -// checks that no tag holds a delimiter outside its value, lexed or built. +// checks that no tag holds a delimiter outside its value, lexed or built, and +// that the numbering of the release agrees with itself and with its tags. // // Plain go test runs the seeds, which are every name in tests.yaml and the // inputs below, so both checks run without -fuzz. @@ -117,6 +124,11 @@ func FuzzParseString(f *testing.F) { // a range in the bracket that closes the name f.Add("[Grp] Show [1-13]") f.Add("Show (01-12).mkv") + // a range and the episode it ends at written again, and a second + // numbering beside a range + f.Add("e0-1 E1") + f.Add("S01E01-E03.Episode.2") + f.Add("S04E29-31v2") // a list of seasons, whole, cut short and at the end of the name f.Add("Show (Season 1+2+3) [1080p]") f.Add("Show S01+02 & 03, 04") @@ -138,6 +150,7 @@ func FuzzParseString(f *testing.F) { t.Errorf("round trip failed:\n in: %q\nout: %q", s, o) } checkEdges(t, s, r.Tags()) + checkNumbering(t, s, r) exercise(r) }) } diff --git a/hint_test.go b/hint_test.go index b50f412..72aeace 100644 --- a/hint_test.go +++ b/hint_test.go @@ -287,8 +287,8 @@ func TestNewParserWithLexers(t *testing.T) { t.Parallel() const name = "Show.S01E02.1080p.WEB.h264-GRP" r := NewParser(WithLexers(NewTrimWhitespaceLexer())).ParseRelease([]byte(name)) - if r.Series != 0 || r.Episode != 0 || r.Resolution != "" || r.Source != "" || len(r.Codec) != 0 { - t.Errorf("expected no season, episode, resolution, source or codec, got: %d %d %q %q %q", r.Series, r.Episode, r.Resolution, r.Source, r.Codec) + if r.Numbering.Shape() != ShapeNone || r.Resolution != "" || r.Source != "" || len(r.Codec) != 0 { + t.Errorf("expected no season, episode, resolution, source or codec, got: %+v %q %q %q", r.Numbering, r.Resolution, r.Source, r.Codec) } for _, tag := range r.Tags() { if !tag.Is(TagTypeText, TagTypeDelim, TagTypeWhitespace) { @@ -300,8 +300,8 @@ func TestNewParserWithLexers(t *testing.T) { } // a later option replaces an earlier one r = NewParser(WithLexers(NewTrimWhitespaceLexer()), WithLexers(DefaultLexers()...)).ParseRelease([]byte(name)) - if r.Series != 1 || r.Episode != 2 || r.Resolution != "1080p" { - t.Errorf("expected S01E02 in 1080p, got: %d %d %q", r.Series, r.Episode, r.Resolution) + if !slices.Equal(r.Numbering.Episodes, []Ep{ep(1, 2, 2)}) || r.Resolution != "1080p" { + t.Errorf("expected S01E02 in 1080p, got: %+v %q", r.Numbering, r.Resolution) } } diff --git a/numbering.go b/numbering.go new file mode 100644 index 0000000..be371f4 --- /dev/null +++ b/numbering.go @@ -0,0 +1,524 @@ +package rls + +import ( + "iter" + "slices" + "strings" +) + +// Numbering is the seasons and the episodes a name gives: 'S01E05' is episode +// 5 of season 1, '[Grp] Show - 01-12' the episodes 1 to 12 with no season, and +// 'Show.S01-S03' three seasons. The zero value is a name that gives neither. +// +// A parse fills it from the name. A Numbering made by hand holds what its +// maker put in the fields, and the methods read those fields and nothing +// else. +type Numbering struct { + // Scheme is how the name numbers its episodes. + Scheme Scheme + // Seasons are the seasons the name writes, each once and in the order it + // writes them. The seasons inside a range are included, up to + // maxRangeFill of them ('S01-S03', 'S01-03', 'Seasons 1~7', '(Season 1 - + // 3)'), and the seasons of a list are those it writes ('S01+S02', 'Season + // 1+2+3', 'Seasons 1 & 2'). A written season 0 is a season ('S00E05' + // gives one season, 0), and a name that writes no season gives nil. + Seasons []int + // Episodes are the episodes the name writes, in the order it writes + // them, with a range as one Ep. A hyphen or a tilde inside a tag makes a + // range ('S01E02-04', '01 ~ 12'), and so does a bare hyphen or tilde + // between two tags of one season when the end is the higher number + // ('E02-E04', 'S00E02-S00E04', 'E29~E31'). Episodes written one after + // the other are one Ep each ('S01E05E06'). The same episode written + // twice is listed once ('Show.S11E11-GRP/Show.S11E11-GRP.mkv'), and a + // season with no episode gives none ('S01'). + // + // An Ep that is not an EpRegular is an extra. It is listed here with its + // Kind for a caller that wants it, and Episode, Absolute, Shape and All + // pass over it. + Episodes []Ep + // Alt is a second numbering of the same episodes: the 1174 of + // 'S23E19.Episode.1174' and of '[Grp] Show - 1174 (S23E19)', the 13 of + // 'S2 - 13 (S02E01)' and the 6 of 'S02E06 [Episode 6]'. It is an episode + // written with no season in a name that writes the episode of that + // season too, and its Season is NoSeason. An 'E06' after a season and an + // episode is another episode and not a second numbering ('S01E05.E06'), + // and so is the end of a range ('S04E29-31v2'). + Alt []Ep + // Volume is the volume or the box a name gives in place of episodes. The + // parser leaves it 0. + Volume int + // Contents is what a pack says it holds besides its episodes. The parser + // leaves it nil. + Contents []string + // Batch is whether the name says it is a batch. The parser leaves it + // false. + Batch bool +} + +// Ep is one episode, or one range of episodes, as a name writes it: 'S01E05' +// is Season 1, First 5 and Last 5, and '01-12' is Season NoSeason, First 1 and +// Last 12. +// +// The zero Ep is episode 0 of season 0, and not an episode with no season. An +// Ep made by hand for a name that writes no season sets Season to NoSeason, as +// every Ep of a parse does. +type Ep struct { + // Season is the season the episode is in, and NoSeason when the name + // gives none for it. An episode written with no season is in the season + // written before it, as the '04' of 'S2 - 04' and of '2nd Season - 04' + // is in season 2. After a range or a list of seasons it is in none of + // them ('Season 1-4 (1-76)', 'S1+S2 (01-25)'). + Season int + // First is the episode, or the first episode of a range. Last is the + // last episode of a range, and the same as First for one episode. A Last + // below First, which no parse makes, is one episode too. + First, Last int + // Frac is the digits after the point of an episode written with one, + // read as a number without the zeros that end them: '21.5' is First 21, + // Last 21 and Frac 5, and so is '21.50'. A zero in front of them is not + // kept, so '21.05' reads as Frac 5 too. In a range it is the fraction of + // Last, so '1-11.5' is First 1, Last 11 and Frac 5. A whole episode has + // Frac 0. + Frac uint8 + // Kind is what kind of episode it is. Every Ep of a parse is an + // EpRegular. + Kind EpKind +} + +// single reports whether the Ep is one episode and no range. A parse makes +// Last the same as First for one episode. In a value made by hand a Last +// below First is no range either. +func (e Ep) single() bool { + return e.Last <= e.First +} + +// NoSeason is the Season of an Ep that the name gives no season for, as in +// '[Grp] Show - 05'. It tells such an episode from one of season 0 ('S00E05'). +const NoSeason = -1 + +// EpKind is what kind of episode an Ep is: one of the run of the show, or an +// extra beside it. +type EpKind uint8 + +// The kinds of an episode. +const ( + // EpRegular is an episode of the run of the show, and the zero value. + EpRegular EpKind = iota + // EpSpecial is a special. + EpSpecial + // EpOVA is an original video animation. + EpOVA + // EpOP is an opening. + EpOP + // EpED is an ending. + EpED + // EpPV is a promotional video. + EpPV +) + +// String returns the name of the kind in lower case ('special', 'ova'), and +// the empty string for EpRegular. +func (k EpKind) String() string { + return nameOf(k, "", "special", "ova", "op", "ed", "pv") +} + +// Scheme is how a name numbers its episodes. +type Scheme uint8 + +// The schemes of a numbering. +const ( + // SchemeNone is a name with no numbering ('Movie.2020.1080p'), and the + // zero value. + SchemeNone Scheme = iota + // SchemeSeasoned is a name that writes a season anywhere: with an + // episode ('S01E05', '1x05'), in front of one ('S2 - 04', '2nd Season - + // 08') or with none ('S01'). + SchemeSeasoned + // SchemeAbsolute is a name that writes episodes and no season ('Show - + // 1169', 'E1100', '01-12'). + SchemeAbsolute + // SchemeDaily is a name with a date where an episode would stand + // ('Show.2024.03.11'): an Episode by its year, month and day that writes + // no episode. A season written beside the date is still in Seasons + // ('Show.2024.05.06.Title.Season.1'). + SchemeDaily +) + +// String returns the name of the scheme in lower case ('seasoned'), and the +// empty string for SchemeNone. +func (s Scheme) String() string { + return nameOf(s, "", "seasoned", "absolute", "daily") +} + +// Shape is what a numbering covers: one episode, several, one season, +// several, or a day. +type Shape uint8 + +// The shapes of a numbering. +const ( + // ShapeNone is a numbering with no episode, no season and no date, and + // the zero value. + ShapeNone Shape = iota + // ShapeEpisode is one episode ('S01E05', 'Show - 1169', 'Show - 21.5'). + ShapeEpisode + // ShapeEpisodes is more than one episode ('S01E05E06', 'S01E02-04', + // '01-12'). + ShapeEpisodes + // ShapeSeason is one season and no episode ('S01'). + ShapeSeason + // ShapeSeasons is more than one season and no episode ('S01-S03', + // 'S01+S02'). + ShapeSeasons + // ShapeDaily is a date where an episode would stand ('Show.2024.03.11'). + ShapeDaily +) + +// String returns the name of the shape in lower case ('episodes'), and the +// empty string for ShapeNone. +func (s Shape) String() string { + return nameOf(s, "", "episode", "episodes", "season", "seasons", "daily") +} + +// nameOf returns the name of v among names, which are in the order of its +// constants, and the empty string for a value that is none of them. +func nameOf[T ~uint8](v T, names ...string) string { + if int(v) < len(names) { + return names[v] + } + return "" +} + +// Season returns the first season the name writes, which is the first of +// Seasons: 1 for 'S01E05', 2 for 'S2 - 04' and 1 for 'S01-S03'. A Numbering +// with no Seasons gives the season of its first episode that has one. ok is +// false when the name gives no season, which tells '[Grp] Show - 05' from a +// season 0 ('S00E05' gives 0 and true). +// +// It is not always the season of the episode that Episode gives: 'S01-S03E05' +// writes season 1 first, and its episode 5 is in season 3. The Season of each +// Ep says which season an episode is in. +func (n Numbering) Season() (season int, ok bool) { + if len(n.Seasons) != 0 { + return n.Seasons[0], true + } + for i := range n.Episodes { + if n.Episodes[i].Season != NoSeason { + return n.Episodes[i].Season, true + } + } + return 0, false +} + +// Episode returns the First of the first regular episode: 5 for 'S01E05', and +// 1 for the batch '[Grp] Show - 01-12' as for 'S01E01-E03', so Shape is what +// tells one episode from several. ok is false when the name gives no regular +// episode, which tells a pack ('S01') from a written episode 0 ('S01E00' and +// '[Grp] Show - 00' give 0 and true). An extra is no regular episode: a +// Numbering that holds extras alone gives 0 and false. +func (n Numbering) Episode() (episode int, ok bool) { + for i := range n.Episodes { + if n.Episodes[i].Kind == EpRegular { + return n.Episodes[i].First, true + } + } + return 0, false +} + +// Absolute returns the episode when the name numbers its episodes absolutely +// and not within a season, ie '[Group] One Piece - 1169', and Episode gives +// the same number. What Absolute adds is that no season qualifies it, so it is +// not comparable against a season's episode without an external mapping +// (AniDB, anime-relations, TheTVDB). ok is false for a season relative number +// ('Hell Mode S2 - 04') and for a special ('Show.S00E05'), both of which are +// already qualified. A written episode 0 is absolute like any other: '[Group] +// Show - 00' gives 0 and true, and a name with no episode 0 and false. +// +// The name has to give one regular episode and no more. A range has no +// absolute number ('01-12', 'E05-E07'), and neither have two episodes +// ('[Group] Show - 00 - 05', 'Episode 1 - 12'), half an episode ('21.5') or +// an extra. +// +// A name may write the absolute episode beside the season and episode, as a +// second numbering ('S23E19.Episode.1174', '[Group] One Piece - 1174 +// (S23E19)'). Absolute then gives it, 1174 and true, and Episode gives the +// season's episode, 19. The season's episode written again is no absolute +// number ('S02E06 [Episode 6]'), and neither is a second numbering beside the +// specials ('S00E05.Episode.12'). +func (n Numbering) Absolute() (episode int, ok bool) { + season, seasoned := n.Season() + if !seasoned { + for _, e := range n.Episodes { + switch { + case e.Kind != EpRegular: + case ok || !e.single() || e.Frac != 0: + return 0, false + default: + episode, ok = e.First, true + } + } + return episode, ok + } + // beside a season the first second numbering is the absolute episode, + // unless it writes the season's episode again or the season is the + // specials + first, _ := n.Episode() + for _, e := range n.Alt { + if e.Kind == EpRegular && e.single() && e.Frac == 0 { + if season == 0 || e.First == first { + return 0, false + } + return e.First, true + } + } + return 0, false +} + +// Shape returns what the numbering covers, by its regular episodes. It is +// ShapeEpisode for one regular Ep that is no range, and ShapeEpisodes for any +// other regular episodes. With none it is ShapeDaily for a SchemeDaily, and +// else ShapeSeason or ShapeSeasons by the number of Seasons. A second +// numbering does not count, so 'S23E19.Episode.1174' is one episode, and +// neither does an extra: a Numbering that holds extras alone has the shape of +// its seasons, or ShapeNone. +func (n Numbering) Shape() Shape { + // regular is how many regular episodes there are, counted up to two, and + // one whether the first of them is no range + var regular int + var one bool + for _, e := range n.Episodes { + if e.Kind != EpRegular { + continue + } + if regular++; regular == 2 { + break + } + one = e.single() + } + switch { + case regular == 1 && one: + return ShapeEpisode + case regular != 0: + return ShapeEpisodes + case n.Scheme == SchemeDaily: + return ShapeDaily + case len(n.Seasons) == 1: + return ShapeSeason + case len(n.Seasons) != 0: + return ShapeSeasons + } + return ShapeNone +} + +// All returns an iterator over the season and the episode of every regular +// Ep in Episodes, in their order, with the episodes inside a range filled in: +// 'S01E02-04' yields 1 and 2, 1 and 3, 1 and 4. The season is NoSeason for an +// episode that has none. A season with no episode yields nothing ('S01'), and +// neither does a second numbering or an extra. +// +// The ranges of a Numbering are filled with at most maxRangeFill episodes +// between them, and a range that does not fit in what is left yields its two +// ends alone ('E1-E99999'), which keeps a name such as +// 'E1-E99999.E1-E99999...' from growing into millions of episodes. +// +// All is safe on a value that no parse made, such as one decoded from a +// stored form. An Ep whose Last is not above its First yields its First +// alone, a number below 0 is yielded as it is, and no value yields more than +// two pairs for each Ep and maxRangeFill pairs beside them. +func (n Numbering) All() iter.Seq2[int, int] { + return func(yield func(int, int) bool) { + fill := uint64(maxRangeFill) + for _, e := range n.Episodes { + if e.Kind != EpRegular { + continue + } + if !yield(e.Season, e.First) { + return + } + if e.single() { + continue + } + // unsigned, as the distance between two ints may not fit in one + if between := uint64(e.Last) - uint64(e.First) - 1; between <= fill { + fill -= between + for episode := e.First + 1; episode < e.Last; episode++ { + if !yield(e.Season, episode) { + return + } + } + } + if !yield(e.Season, e.Last) { + return + } + } + } +} + +// numbering reads the seasons and the episodes of the release from its series +// tags. It also reports whether a tag that is no second numbering writes an +// episode other than 0 in its first place, which Release.numbered keeps. +// +// The tags are walked twice and nothing is looked up across the name for one +// of them, so that the time grows with the length of the name and not with +// its square: a name is untrusted input, and may be all numbering. +// +// An episode written with no season is a second numbering when the name +// writes the episode of its season too, and goes to Alt: the 'Episode.1174' +// of 'S23E19.Episode.1174' and the '1174' of '1174 (S23E19)'. Its season is +// the one written nearest before it, so the '13' of 'S2 - 13 (S02E01)' is +// one, and the 'Episode.2' of 'S01E01.S02.Episode.2' is episode 2 of season +// 2. With no season before it, any season written with an episode makes it +// one. Two kinds of tag are another episode and never a second numbering: an +// 'E06' continuation, and the end of a range ('S04E29-31v2'). +// +// A hyphen or a tilde makes a range of two episodes when the end is the +// higher number, inside a tag ('S01E02-04') or bare between two tags of one +// season ('E02-E04'). A second numbering starts no range and ends none: the +// episodes of 'S01E01.Episode.5-E07' are 1 and 7 with 5 in Alt, and those of +// 'S23E19-1174v2' are 19 with 1174 in Alt. +func (r Release) numbering() (n Numbering, numbered bool) { + // the room most names need, so that only what is kept is allocated + var wbuf, sbuf [4]int + var ebuf, abuf [4]Ep + // with are the seasons written with an episode, in rising order + with, series := wbuf[:0], false + for _, tag := range r.tags { + if tag.typ != TagTypeSeries { + continue + } + if series = true; tag.val(1) != "" && tag.wroteEpisode() { + with = append(with, atoi(tag.val(1))) + } + } + if !series { + return n, false + } + slices.Sort(with) + // what is not a second numbering, and what is + const ( + none = iota + regular + second + ) + seasons, eps, alt := sbuf[:0], ebuf[:0], abuf[:0] + // season is the season an episode written with none is in, and near the + // season written nearest before the tag, which a range or a list of + // seasons leaves as it is + season, near, fill := NoSeason, NoSeason, maxRangeFill + // open is which of the two the series tag before wrote its last episode + // as, which a hyphen may then make a range of + open := none + for i, tag := range r.tags { + if tag.typ != TagTypeSeries { + continue + } + bare := tag.val(1) == "" + if !bare { + s, start := atoi(tag.val(1)), r.seasonRange(i) + if start != -1 { + if prev := atoi(r.tags[start].val(1)); s-prev-1 <= fill { + for j := prev + 1; j < s; j++ { + seasons = append(seasons, j) + } + fill -= s - prev - 1 + } + } + seasons = append(seasons, s) + // an episode after a range or a list of seasons is in none of + // them + if season, near = s, s; start != -1 || r.seasonList(i) != -1 { + season = NoSeason + } + } + kind, in := regular, season + if bare && tag.wroteEpisode() && !tag.continuation() && !r.rangeEnd(i) { + again := len(with) != 0 + if near != NoSeason { + _, again = slices.BinarySearch(with, near) + } + if again { + kind, in = second, NoSeason + } + } + numbered = numbered || kind == regular && atoi(tag.val(2)) != 0 + ranged := open == kind && i >= 2 && r.tags[i-2].typ == TagTypeSeries && r.tags[i-1].rangeDelim() && + (bare || tag.val(1) == r.tags[i-2].val(1)) + open = none + vals := tag.rest(2) + for k, b := range vals { + switch b { + case "": + continue + case "-": + ranged = open != none + continue + } + e := Ep{Season: in, First: atoi(b), Last: atoi(b)} + // the fraction follows the last number of the tag, and '.50' + // is the half that '.5' is + if k == len(vals)-1 { + if f := tag.fraction(); f != "" { + e.Frac = uint8(atoi(strings.TrimRight(f[1:], "0"))) + } + } + if kind == second { + alt = extend(alt, e, ranged) + } else { + eps = extend(eps, e, ranged) + } + ranged, open = false, kind + } + } + n = Numbering{Seasons: kept(unique(seasons)), Episodes: kept(unique(eps)), Alt: kept(unique(alt))} + switch { + case n.Seasons != nil: + n.Scheme = SchemeSeasoned + case n.Episodes != nil: + n.Scheme = SchemeAbsolute + } + return n, numbered +} + +// extend adds the episode e to v: as the new end of the last Ep of v when the +// two are the ends of a range and e is the higher one, and else as an Ep of +// its own. +func extend(v []Ep, e Ep, ranged bool) []Ep { + if last := len(v) - 1; ranged && e.First > v[last].Last { + v[last].Last, v[last].Frac = e.Last, e.Frac + return v + } + return append(v, e) +} + +// unique drops from v every value that one before it equals, and keeps the +// order of the others. It writes them over the start of v. +func unique[T comparable](v []T) []T { + // one comparison with each value before is the least work for the few + // values of a name, and a set keeps the time linear in a name that + // repeats thousands ('E1.E2.E3...') + const few = 32 + if len(v) > few { + seen, k := make(map[T]struct{}, len(v)), 0 + for _, x := range v { + if _, ok := seen[x]; !ok { + seen[x], v[k], k = struct{}{}, x, k+1 + } + } + return v[:k] + } + k := min(len(v), 1) + for i := 1; i < len(v); i++ { + if !slices.Contains(v[:k], v[i]) { + v[k], k = v[i], k+1 + } + } + return v[:k] +} + +// kept returns a copy of v with no room to spare, which is what a release +// holds on to, and nil for no values. +func kept[T any](v []T) []T { + if len(v) == 0 { + return nil + } + return append(make([]T, 0, len(v)), v...) +} diff --git a/numbering_test.go b/numbering_test.go index 603fe5f..4f6925f 100644 --- a/numbering_test.go +++ b/numbering_test.go @@ -2,13 +2,16 @@ package rls import ( "fmt" + "math" + "reflect" "slices" "strings" "testing" + "time" ) -// numbering is what HasSeason, HasEpisode, Seasons and EpisodeRange give for -// a release. +// numbering is what a Numbering gives for a release: whether it has a season +// and an episode, its seasons, and the range of its episodes. type numbering struct { season, episode bool seasons []int @@ -17,17 +20,55 @@ type numbering struct { } func numberingOf(r Release) numbering { - first, last, ok := r.EpisodeRange() + n := r.Numbering + _, season := n.Season() + _, episode := n.Episode() + first, last, ok := episodeRange(n) return numbering{ - season: r.HasSeason(), - episode: r.HasEpisode(), - seasons: r.Seasons(), + season: season, + episode: episode, + seasons: n.Seasons, first: first, last: last, ok: ok, } } +// ep returns one episode, or one range of episodes, of a season. +func ep(season, first, last int) Ep { + return Ep{Season: season, First: first, Last: last} +} + +// episodeRange returns the first and the last episode when n gives more than +// one ('S01E05E06', 'S01E02-04', '01-12'). The episodes are those of the +// season the first episode is in, so 'S01E01.S02E01' is not a range, and +// neither is one episode under two numberings ('S23E19.Episode.1174'). +func episodeRange(n Numbering) (first, last int, ok bool) { + for i, e := range n.Episodes { + switch { + case i == 0: + first, last = e.First, e.Last + case e.Season == n.Episodes[0].Season: + first, last = min(first, e.First, e.Last), max(last, e.First, e.Last) + } + } + if first == last { + return 0, 0, false + } + return first, last, true +} + +// pairs returns each season and episode that n.All yields, once and in rising +// order, with NoSeason for an episode that has no season. +func pairs(n Numbering) [][]int { + var v [][]int + for season, episode := range n.All() { + v = append(v, []int{season, episode}) + } + slices.SortFunc(v, slices.Compare[[]int]) + return slices.CompactFunc(v, slices.Equal[[]int]) +} + func TestNumbering(t *testing.T) { tests := []struct { name string @@ -48,15 +89,16 @@ func TestNumbering(t *testing.T) { {"Show.S01E02-04.1080p.WEB.h264-GRP", numbering{season: true, episode: true, seasons: []int{1}, first: 2, last: 4, ok: true}}, {"Show.S01E02-E04.1080p.WEB.h264-GRP", numbering{season: true, episode: true, seasons: []int{1}, first: 2, last: 4, ok: true}}, {"Show.S00E02-E05.1080p.WEB.h264-GRP", numbering{season: true, episode: true, seasons: []int{0}, first: 2, last: 5, ok: true}}, - // the two ends of a range that is too wide for SeriesEpisodes to fill + // the two ends of a range that is too wide for All to fill {"Show.S01E1-E99999.1080p.WEB.h264-GRP", numbering{season: true, episode: true, seasons: []int{1}, first: 1, last: 99999, ok: true}}, // one episode under two numberings {"Show.S23E19.Episode.1174.1080p.WEB.h264-GRP", numbering{season: true, episode: true, seasons: []int{23}}}, // one episode in two seasons is not a range {"Show.S01E01.S02E01.1080p.WEB.h264-GRP", numbering{season: true, episode: true, seasons: []int{1, 2}}}, - // the episodes are those of the season written first, the one in Series - {"Show.S02E01.S01E05-E06.1080p.WEB.h264-GRP", numbering{season: true, episode: true, seasons: []int{1, 2}}}, - {"Show.S02E01E02.S01E05.1080p.WEB.h264-GRP", numbering{season: true, episode: true, seasons: []int{1, 2}, first: 1, last: 2, ok: true}}, + // the episodes are those of the season written first, the one Season + // gives, and the seasons are in the order written + {"Show.S02E01.S01E05-E06.1080p.WEB.h264-GRP", numbering{season: true, episode: true, seasons: []int{2, 1}}}, + {"Show.S02E01E02.S01E05.1080p.WEB.h264-GRP", numbering{season: true, episode: true, seasons: []int{2, 1}, first: 1, last: 2, ok: true}}, // the same episode twice in a path {"Show.S11E11-GRP/Show.S11E11-GRP.mkv", numbering{season: true, episode: true, seasons: []int{11}}}, // no season, one episode @@ -108,49 +150,164 @@ func TestNumbering(t *testing.T) { } } +// TestNumberingByHand checks that a Numbering made by hand gives what its +// maker put in it, and that the methods read the value alone: a release has +// the numbering it holds, whatever its tags say. func TestNumberingByHand(t *testing.T) { - // a caller clears the fields of a parsed release, and the tags still - // give the season and the episode - cleared := ParseString("Show.S01E02.1080p.WEB.h264-GRP") - cleared.Series, cleared.Episode = 0, 0 + type answers struct { + season, episode, absolute int + seasoned, numbered, abs bool + shape Shape + pairs [][]int + } + parsed := ParseString("Show.S01E02.1080p.WEB.h264-GRP") + // a caller clears the numbering of a parsed release, or replaces it to + // make a pack read as one of its episodes + cleared, replaced := parsed, ParseString("Show.S01.1080p.WEB.h264-GRP") + cleared.Numbering = Numbering{} + replaced.Numbering.Episodes = []Ep{ep(1, 4, 4)} tests := []struct { name string - r Release - exp numbering + n Numbering + exp answers }{ - {"zero", Release{}, numbering{}}, - {"series", Release{Series: 3}, numbering{season: true, seasons: []int{3}}}, - {"episode", Release{Episode: 4}, numbering{episode: true}}, - {"series and episode", Release{Series: 1, Episode: 2}, numbering{season: true, episode: true, seasons: []int{1}}}, - {"cleared", cleared, numbering{season: true, episode: true, seasons: []int{1}}}, + {"zero", Numbering{}, answers{}}, + {"season", Numbering{Scheme: SchemeSeasoned, Seasons: []int{3}}, answers{season: 3, seasoned: true, shape: ShapeSeason}}, + {"seasons", Numbering{Scheme: SchemeSeasoned, Seasons: []int{3, 1}}, answers{season: 3, seasoned: true, shape: ShapeSeasons}}, + {"season 0", Numbering{Seasons: []int{0}}, answers{seasoned: true, shape: ShapeSeason}}, + { + "episode", Numbering{Scheme: SchemeAbsolute, Episodes: []Ep{ep(NoSeason, 4, 4)}}, + answers{episode: 4, numbered: true, absolute: 4, abs: true, shape: ShapeEpisode, pairs: [][]int{{NoSeason, 4}}}, + }, + { + "episode 0", Numbering{Episodes: []Ep{ep(NoSeason, 0, 0)}}, + answers{numbered: true, abs: true, shape: ShapeEpisode, pairs: [][]int{{NoSeason, 0}}}, + }, + { + "season and episode", Numbering{Scheme: SchemeSeasoned, Seasons: []int{1}, Episodes: []Ep{ep(1, 2, 2)}}, + answers{season: 1, seasoned: true, episode: 2, numbered: true, shape: ShapeEpisode, pairs: [][]int{{1, 2}}}, + }, + // the season of an episode is a season, with nothing in Seasons + { + "episode in a season", Numbering{Episodes: []Ep{ep(2, 5, 5)}}, + answers{season: 2, seasoned: true, episode: 5, numbered: true, shape: ShapeEpisode, pairs: [][]int{{2, 5}}}, + }, + // the zero Ep is in season 0, which qualifies its episode as the + // specials do + { + "zero ep", Numbering{Episodes: []Ep{{First: 5, Last: 5}}}, + answers{seasoned: true, episode: 5, numbered: true, shape: ShapeEpisode, pairs: [][]int{{0, 5}}}, + }, + { + "range", Numbering{Episodes: []Ep{ep(NoSeason, 1, 12)}}, + answers{episode: 1, numbered: true, shape: ShapeEpisodes, pairs: [][]int{{NoSeason, 1}, {NoSeason, 2}, {NoSeason, 3}, {NoSeason, 4}, {NoSeason, 5}, {NoSeason, 6}, {NoSeason, 7}, {NoSeason, 8}, {NoSeason, 9}, {NoSeason, 10}, {NoSeason, 11}, {NoSeason, 12}}}, + }, + { + "half an episode", Numbering{Episodes: []Ep{{Season: NoSeason, First: 21, Last: 21, Frac: 5}}}, + answers{episode: 21, numbered: true, shape: ShapeEpisode, pairs: [][]int{{NoSeason, 21}}}, + }, + { + "second numbering", Numbering{Seasons: []int{23}, Episodes: []Ep{ep(23, 19, 19)}, Alt: []Ep{ep(NoSeason, 1174, 1174)}}, + answers{season: 23, seasoned: true, episode: 19, numbered: true, absolute: 1174, abs: true, shape: ShapeEpisode, pairs: [][]int{{23, 19}}}, + }, + { + "the episode again", Numbering{Seasons: []int{2}, Episodes: []Ep{ep(2, 6, 6)}, Alt: []Ep{ep(NoSeason, 6, 6)}}, + answers{season: 2, seasoned: true, episode: 6, numbered: true, shape: ShapeEpisode, pairs: [][]int{{2, 6}}}, + }, + // an extra is no regular episode: it is in Episodes with its Kind, + // and Episode, Absolute, Shape and All pass over it + {"an extra", Numbering{Episodes: []Ep{{Season: NoSeason, First: 2, Last: 2, Kind: EpOVA}}}, answers{}}, + {"extras", Numbering{Episodes: []Ep{{Season: NoSeason, First: 3, Last: 3, Kind: EpSpecial}, {Season: NoSeason, First: 1, Last: 2, Kind: EpOP}}}, answers{}}, + { + "an extra of a season", Numbering{Seasons: []int{2}, Episodes: []Ep{{Season: 2, First: 1, Last: 1, Kind: EpOVA}}}, + answers{season: 2, seasoned: true, shape: ShapeSeason}, + }, + { + "an extra and an episode", Numbering{Episodes: []Ep{{Season: NoSeason, First: 2, Last: 2, Kind: EpSpecial}, ep(NoSeason, 7, 7)}}, + answers{episode: 7, numbered: true, absolute: 7, abs: true, shape: ShapeEpisode, pairs: [][]int{{NoSeason, 7}}}, + }, + { + "an episode and extras", Numbering{Episodes: []Ep{ep(NoSeason, 7, 7), {Season: NoSeason, First: 1, Last: 1, Kind: EpPV}, {Season: NoSeason, First: 1, Last: 1, Kind: EpED}}}, + answers{episode: 7, numbered: true, absolute: 7, abs: true, shape: ShapeEpisode, pairs: [][]int{{NoSeason, 7}}}, + }, + { + "an extra and a range", Numbering{Episodes: []Ep{{Season: NoSeason, First: 1, Last: 1, Kind: EpOVA}, ep(NoSeason, 1, 3)}}, + answers{episode: 1, numbered: true, shape: ShapeEpisodes, pairs: [][]int{{NoSeason, 1}, {NoSeason, 2}, {NoSeason, 3}}}, + }, + // more than one episode has no absolute number + { + "two episodes", Numbering{Episodes: []Ep{ep(NoSeason, 0, 0), ep(NoSeason, 5, 5)}}, + answers{numbered: true, shape: ShapeEpisodes, pairs: [][]int{{NoSeason, 0}, {NoSeason, 5}}}, + }, + { + "an episode and a range", Numbering{Episodes: []Ep{ep(NoSeason, 13, 13), ep(NoSeason, 1, 2)}}, + answers{episode: 13, numbered: true, shape: ShapeEpisodes, pairs: [][]int{{NoSeason, 1}, {NoSeason, 2}, {NoSeason, 13}}}, + }, + // an Ep that ends below its start is one episode + { + "last below first", Numbering{Episodes: []Ep{ep(NoSeason, 5, 3)}}, + answers{episode: 5, numbered: true, absolute: 5, abs: true, shape: ShapeEpisode, pairs: [][]int{{NoSeason, 5}}}, + }, + {"daily", Numbering{Scheme: SchemeDaily}, answers{shape: ShapeDaily}}, + {"daily with a season", Numbering{Scheme: SchemeDaily, Seasons: []int{1}}, answers{season: 1, seasoned: true, shape: ShapeDaily}}, + {"cleared", cleared.Numbering, answers{}}, + { + "replaced", replaced.Numbering, + answers{season: 1, seasoned: true, episode: 4, numbered: true, shape: ShapeEpisode, pairs: [][]int{{1, 4}}}, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - if got := numberingOf(test.r); !equalNumbering(got, test.exp) { + var got answers + got.season, got.seasoned = test.n.Season() + got.episode, got.numbered = test.n.Episode() + got.absolute, got.abs = test.n.Absolute() + got.shape, got.pairs = test.n.Shape(), pairs(test.n) + if !reflect.DeepEqual(got, test.exp) { t.Errorf("got %+v, expected %+v", got, test.exp) } }) } + // the tags of the two releases are those of the parse + if s := fmt.Sprintf("%o", cleared); s != "Show.S01E02.1080p.WEB.h264-GRP" { + t.Errorf("expected the name back, got: %q", s) + } + // what Compare and Event read is the numbering the release holds + if Compare(parsed, cleared) <= 0 { + t.Errorf("expected the release with no numbering to sort before the one with an episode") + } + event := Release{Type: Episode, Title: "Formula1", Numbering: Numbering{Seasons: []int{2024}, Episodes: []Ep{ep(2024, 5, 5)}}} + if ev, ok := event.Event(); !ok || ev.Round != 5 { + t.Errorf("expected round 5 of an event, got: %+v %t", ev, ok) + } } +// TestNumberingAllocs checks that the methods of a Numbering allocate nothing, +// since they are asked of every release a caller holds. func TestNumberingAllocs(t *testing.T) { for _, name := range []string{ "Show.S01E02-E04.1080p.WEB.h264-GRP", "Show.S01-S03.1080p.BluRay.x264-GRP", "[Grp] Show - 01-12 [1080p]", + "Show.S23E19.Episode.1174.1080p.WEB.h264-GRP", } { - r := ParseString(name) + n := ParseString(name).Numbering for _, test := range []struct { name string - max float64 f func() }{ - {"HasSeason", 0, func() { _ = r.HasSeason() }}, - {"HasEpisode", 0, func() { _ = r.HasEpisode() }}, - {"EpisodeRange", 0, func() { _, _, _ = r.EpisodeRange() }}, + {"Season", func() { _, _ = n.Season() }}, + {"Episode", func() { _, _ = n.Episode() }}, + {"Absolute", func() { _, _ = n.Absolute() }}, + {"Shape", func() { _ = n.Shape() }}, + {"All", func() { + for season, episode := range n.All() { + _, _ = season, episode + } + }}, } { - if n := testing.AllocsPerRun(100, test.f); n > test.max { - t.Errorf("%s: %s allocates %v times, expected at most %v", name, test.name, n, test.max) + if n := testing.AllocsPerRun(100, test.f); n != 0 { + t.Errorf("%s: %s allocates %v times, expected none", name, test.name, n) } } } @@ -161,18 +318,18 @@ func equalNumbering(a, b numbering) bool { a.first == b.first && a.last == b.last && a.ok == b.ok } -// TestEpisodeZero checks that a written episode 0 is an episode: SeriesEpisodes -// lists it, a range starts at it, and with no season it is absolute. +// TestEpisodeZero checks that a written episode 0 is an episode: All yields +// it, a range starts at it, and with no season it is absolute. func TestEpisodeZero(t *testing.T) { tests := []struct { name string exp [][]int absolute bool }{ - {"[Group] Show - 00 [720p]", [][]int{{0, 0}}, true}, - {"[Group] Show - 00v2 [720p]", [][]int{{0, 0}}, true}, - {"[Group] Show - Episode 0 [720p]", [][]int{{0, 0}}, true}, - {"Show.E00.1080p.WEB.h264-GRP", [][]int{{0, 0}}, true}, + {"[Group] Show - 00 [720p]", [][]int{{NoSeason, 0}}, true}, + {"[Group] Show - 00v2 [720p]", [][]int{{NoSeason, 0}}, true}, + {"[Group] Show - Episode 0 [720p]", [][]int{{NoSeason, 0}}, true}, + {"Show.E00.1080p.WEB.h264-GRP", [][]int{{NoSeason, 0}}, true}, // a season qualifies it {"Show.S01E00.1080p.WEB.h264-GRP", [][]int{{1, 0}}, false}, {"Show.1x00.HDTV.x264-GRP", [][]int{{1, 0}}, false}, @@ -181,29 +338,30 @@ func TestEpisodeZero(t *testing.T) { // ranges that start at 0 {"Show.S01E00E01.1080p.WEB.h264-GRP", [][]int{{1, 0}, {1, 1}}, false}, {"Show.S01E00-E02.1080p.WEB.h264-GRP", [][]int{{1, 0}, {1, 1}, {1, 2}}, false}, - {"[Group] Show - 00-03 [720p]", [][]int{{0, 0}, {0, 1}, {0, 2}, {0, 3}}, false}, - {"[Group] Show - 00 ~ 02 [720p]", [][]int{{0, 0}, {0, 1}, {0, 2}}, false}, + {"[Group] Show - 00-03 [720p]", [][]int{{NoSeason, 0}, {NoSeason, 1}, {NoSeason, 2}, {NoSeason, 3}}, false}, + {"[Group] Show - 00 ~ 02 [720p]", [][]int{{NoSeason, 0}, {NoSeason, 1}, {NoSeason, 2}}, false}, // a range that ends at 0 is its two ends {"Show.S01E03-E00.1080p.WEB.h264-GRP", [][]int{{1, 0}, {1, 3}}, false}, - // half an episode and a range after the 0 are not its number - {"[Group] Show - 00 (Ep 5.5) [720p]", [][]int{{0, 0}, {0, 5}}, true}, - {"[Group] Show - 00 - E05-07 [720p]", [][]int{{0, 0}, {0, 5}, {0, 6}, {0, 7}}, true}, + // with half an episode or a range after the 0 the name gives more + // than one episode, and has no absolute number + {"[Group] Show - 00 (Ep 5.5) [720p]", [][]int{{NoSeason, 0}, {NoSeason, 5}}, false}, + {"[Group] Show - 00 - E05-07 [720p]", [][]int{{NoSeason, 0}, {NoSeason, 5}, {NoSeason, 6}, {NoSeason, 7}}, false}, // half an episode has no absolute number - {"[Group] Show - 00.5 [720p]", [][]int{{0, 0}}, false}, + {"[Group] Show - 00.5 [720p]", [][]int{{NoSeason, 0}}, false}, // no episode written {"Show.S01.1080p.WEB.h264-GRP", nil, false}, {"Show.2024.1080p.WEB.h264-GRP", nil, false}, } for _, test := range tests { - r := ParseString(test.name) - if v := r.SeriesEpisodes(); !slices.EqualFunc(v, test.exp, slices.Equal[[]int]) { + n := ParseString(test.name).Numbering + if v := pairs(n); !slices.EqualFunc(v, test.exp, slices.Equal[[]int]) { t.Errorf("%q: expected series episodes %v, got: %v", test.name, test.exp, v) } - if episode, ok := r.Absolute(); episode != 0 || ok != test.absolute { + if episode, ok := n.Absolute(); episode != 0 || ok != test.absolute { t.Errorf("%q: expected absolute 0 %t, got: %d %t", test.name, test.absolute, episode, ok) } - if ok := r.HasEpisode(); ok != (test.exp != nil) { - t.Errorf("%q: expected has episode %t, got: %t", test.name, test.exp != nil, ok) + if _, ok := n.Episode(); ok != (test.exp != nil) { + t.Errorf("%q: expected an episode %t, got: %t", test.name, test.exp != nil, ok) } } for _, tag := range ParseString("Show.S01E00.1080p.WEB.h264-GRP").Tags() { @@ -211,9 +369,14 @@ func TestEpisodeZero(t *testing.T) { t.Errorf("expected episodes [0], got: %v", v) } } - // the first episode that is not 0 is the absolute one, as it is Episode - if episode, ok := ParseString("[Group] Show - 00 - 05 [720p]").Absolute(); episode != 5 || !ok { - t.Errorf("expected absolute 5 true, got: %d %t", episode, ok) + // two episodes have no absolute number, and Episode gives the first, + // which is 0 and an episode + n := ParseString("[Group] Show - 00 - 05 [720p]").Numbering + if episode, ok := n.Absolute(); episode != 0 || ok { + t.Errorf("expected no absolute episode, got: %d %t", episode, ok) + } + if episode, ok := n.Episode(); episode != 0 || !ok { + t.Errorf("expected episode 0 true, got: %d %t", episode, ok) } } @@ -227,16 +390,16 @@ func TestEpisodeRangeTilde(t *testing.T) { {"[Grp] Show S04E29~E31 1080p WEB H.264", [][]int{{4, 29}, {4, 30}, {4, 31}}}, {"Show.S01E02~S01E04.1080p.WEB.h264-GRP", [][]int{{1, 2}, {1, 3}, {1, 4}}}, {"Show.S01E01~03.1080p.WEB.x264-GRP", [][]int{{1, 1}, {1, 2}, {1, 3}}}, - {"[Grp] Show E05~E07 [1080p]", [][]int{{0, 5}, {0, 6}, {0, 7}}}, + {"[Grp] Show E05~E07 [1080p]", [][]int{{NoSeason, 5}, {NoSeason, 6}, {NoSeason, 7}}}, // two seasons are not a range {"Show.S01E02~S02E04.1080p.WEB.h264-GRP", [][]int{{1, 2}, {2, 4}}}, } for _, test := range tests { - r := ParseString(test.name) - if v := r.SeriesEpisodes(); !slices.EqualFunc(v, test.exp, slices.Equal[[]int]) { + n := ParseString(test.name).Numbering + if v := pairs(n); !slices.EqualFunc(v, test.exp, slices.Equal[[]int]) { t.Errorf("%q: expected series episodes %v, got: %v", test.name, test.exp, v) } - first, last, ok := r.EpisodeRange() + first, last, ok := episodeRange(n) if exp := test.exp[0][0] == test.exp[len(test.exp)-1][0]; ok != exp || ok && (first != test.exp[0][1] || last != test.exp[len(test.exp)-1][1]) { t.Errorf("%q: expected the range of %v, got: %d to %d, %t", test.name, test.exp, first, last, ok) } @@ -261,7 +424,7 @@ func TestSeriesEpisodesSeasonZero(t *testing.T) { {"Show.S01E02-S02E04.1080p.WEB.h264-GRP", [][]int{{1, 2}, {2, 4}}}, } for _, test := range tests { - if v := ParseString(test.name).SeriesEpisodes(); !slices.EqualFunc(v, test.exp, slices.Equal[[]int]) { + if v := pairs(ParseString(test.name).Numbering); !slices.EqualFunc(v, test.exp, slices.Equal[[]int]) { t.Errorf("%q: expected series episodes %v, got: %v", test.name, test.exp, v) } } @@ -302,31 +465,35 @@ func TestSeriesEpisodesSecondNumbering(t *testing.T) { {"[Grp] Show S2 - 04 [1080p].mkv", [][]int{{2, 4}}, 4}, {"Show.S01E01.S02.Episode.2.1080p.WEB.h264-GRP", [][]int{{1, 1}, {2, 2}}, 1}, // no season written - {"Show.Episode.1.1080p.WEB.h264-GRP", [][]int{{0, 1}}, 1}, + {"Show.Episode.1.1080p.WEB.h264-GRP", [][]int{{NoSeason, 1}}, 1}, // a part is not an episode {"Show.S01E01.Part.1.1080p.WEB.h264-GRP", [][]int{{1, 1}}, 1}, {"Show.S01E02.Part.2.1080p.WEB.h264-GRP", [][]int{{1, 2}}, 2}, } for _, test := range tests { - r := ParseString(test.name) - if v := r.SeriesEpisodes(); !slices.EqualFunc(v, test.exp, slices.Equal[[]int]) { + n := ParseString(test.name).Numbering + if v := pairs(n); !slices.EqualFunc(v, test.exp, slices.Equal[[]int]) { t.Errorf("%q: expected series episodes %v, got: %v", test.name, test.exp, v) } - if r.Episode != test.episode { - t.Errorf("%q: expected episode %d, got: %d", test.name, test.episode, r.Episode) + if episode, _ := n.Episode(); episode != test.episode { + t.Errorf("%q: expected episode %d, got: %d", test.name, test.episode, episode) } } // season 2 writes its episode in '(S02E01)', so the 13 after 'S2' is a // second numbering name := "[Grp] Show S2 - 13 (S02E01) [1080p].mkv" - if v, exp := ParseString(name).SeriesEpisodes(), [][]int{{2, 1}}; !slices.EqualFunc(v, exp, slices.Equal[[]int]) { + n := ParseString(name).Numbering + if v, exp := pairs(n), [][]int{{2, 1}}; !slices.EqualFunc(v, exp, slices.Equal[[]int]) { t.Errorf("%q: expected series episodes %v, got: %v", name, exp, v) } + if exp := []Ep{ep(NoSeason, 13, 13)}; !slices.Equal(n.Alt, exp) { + t.Errorf("%q: expected the second numbering %v, got: %v", name, exp, n.Alt) + } } // TestAbsoluteSecondNumbering checks that an episode written without a season // beside one written with a season and an episode is the absolute episode, -// and that Episode is the season's episode wherever the two are written. +// and that Episode gives the season's episode wherever the two are written. func TestAbsoluteSecondNumbering(t *testing.T) { tests := []struct { name string @@ -350,6 +517,16 @@ func TestAbsoluteSecondNumbering(t *testing.T) { {"Show.S01E05.E06.1080p.WEB.h264-GRP", 5, 0, false}, {"Show.S01E01.Episode.5-7.1080p.WEB.h264-GRP", 1, 0, false}, {"Show.S01E01.Episode.5.5.1080p.WEB.h264-GRP", 1, 0, false}, + // the end of a range that a version follows + {"[Judas] Shingeki no Kyojin (Attack on Titan) - S04E29-31v2 [1080p][HEVC x265 10bit][Multi-Subs] (Weekly)", 29, 0, false}, + {"Show.S04E29-31v2.1080p.WEB.H264-GRP", 29, 0, false}, + {"Show.S04E29~31v2.1080p.WEB.H264-GRP", 29, 0, false}, + {"Show.S01E998-1002v2.1080p.WEB.H264-GRP", 998, 0, false}, + // four digits after a lower episode are another number, as they are + // with no version after them, and so is an episode written with a word + {"Show.S23E19-1174v2.1080p.WEB.H264-GRP", 19, 1174, true}, + {"Show.S01E05-2020v2.1080p.WEB.H264-GRP", 5, 2020, true}, + {"Show.S01E05-Episode.10.1080p.WEB.H264-GRP", 5, 10, true}, // a season with no episode leaves the episode after it in the season {"[Grp] Show S2 - 04 [1080p].mkv", 4, 0, false}, {"Show.S01E01.S02.Episode.2.1080p.WEB.h264-GRP", 1, 0, false}, @@ -357,25 +534,25 @@ func TestAbsoluteSecondNumbering(t *testing.T) { {"[Group] One Piece - 1169 [1080p].mkv", 1169, 1169, true}, } for _, test := range tests { - r := ParseString(test.name) - if r.Episode != test.episode { - t.Errorf("%q: expected episode %d, got: %d", test.name, test.episode, r.Episode) + n := ParseString(test.name).Numbering + if episode, _ := n.Episode(); episode != test.episode { + t.Errorf("%q: expected episode %d, got: %d", test.name, test.episode, episode) } - if absolute, ok := r.Absolute(); absolute != test.absolute || ok != test.ok { + if absolute, ok := n.Absolute(); absolute != test.absolute || ok != test.ok { t.Errorf("%q: expected absolute %d %t, got: %d %t", test.name, test.absolute, test.ok, absolute, ok) } } } // TestSeasonRange checks a range of seasons written with one season word: -// Series is the first season, Seasons gives every season of the range, the +// Season gives the first season, Seasons every season of the range, the // release is a pack, and the last season is neither the subtitle nor a // leftover word. An episode written beside the range is in no season. func TestSeasonRange(t *testing.T) { tests := []struct { name string seasons []int - spans []EpisodeSpan + spans []Ep }{ // a bare hyphen or a tilde {"Show.S01-03.1080p.BluRay.x264-GRP", []int{1, 2, 3}, nil}, @@ -399,31 +576,34 @@ func TestSeasonRange(t *testing.T) { {"[Grp] Show (Season 01 - 04+OVAs) [BD] [1080p]", []int{1, 2, 3, 4}, nil}, // episodes beside the range are in no season, whichever way the range // is written - {"[Grp] Show Season 1-4 (1-76) [1080p]", []int{1, 2, 3, 4}, []EpisodeSpan{{"", "1", "76"}}}, - {"[Grp] Show 001-367 (Seasons 1-10) [BD 1080p]", []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, []EpisodeSpan{{"", "001", "367"}}}, - {"[Grp] Show S01-04 (1-76) [1080p]", []int{1, 2, 3, 4}, []EpisodeSpan{{"", "1", "76"}}}, - {"[Grp] Show S01-S04 (1-76) [1080p]", []int{1, 2, 3, 4}, []EpisodeSpan{{"", "1", "76"}}}, + {"[Grp] Show Season 1-4 (1-76) [1080p]", []int{1, 2, 3, 4}, []Ep{ep(NoSeason, 1, 76)}}, + {"[Grp] Show 001-367 (Seasons 1-10) [BD 1080p]", []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, []Ep{ep(NoSeason, 1, 367)}}, + {"[Grp] Show S01-04 (1-76) [1080p]", []int{1, 2, 3, 4}, []Ep{ep(NoSeason, 1, 76)}}, + {"[Grp] Show S01-S04 (1-76) [1080p]", []int{1, 2, 3, 4}, []Ep{ep(NoSeason, 1, 76)}}, } for _, test := range tests { r := ParseString(test.name) - if v := r.Seasons(); !slices.Equal(v, test.seasons) { - t.Errorf("%q: expected seasons %v, got: %v", test.name, test.seasons, v) + n := r.Numbering + if !slices.Equal(n.Seasons, test.seasons) { + t.Errorf("%q: expected seasons %v, got: %v", test.name, test.seasons, n.Seasons) } if r.Type != Series { t.Errorf("%q: expected type series, got: %s", test.name, r.Type) } - if r.Series != test.seasons[0] { - t.Errorf("%q: expected series %d, got: %d", test.name, test.seasons[0], r.Series) + if season, ok := n.Season(); season != test.seasons[0] || !ok { + t.Errorf("%q: expected season %d, got: %d %t", test.name, test.seasons[0], season, ok) } - if v := r.EpisodeSpans(); !slices.Equal(v, test.spans) { - t.Errorf("%q: expected spans %q, got: %q", test.name, test.spans, v) + if !slices.Equal(n.Episodes, test.spans) { + t.Errorf("%q: expected episodes %v, got: %v", test.name, test.spans, n.Episodes) } - if exp := len(test.spans) != 0; r.HasEpisode() != exp { - t.Errorf("%q: expected HasEpisode %t", test.name, exp) + // a range of seasons alone is several seasons, and with a range of + // episodes beside it the release is its episodes + if exp := map[bool]Shape{false: ShapeSeasons, true: ShapeEpisodes}[len(test.spans) != 0]; n.Shape() != exp { + t.Errorf("%q: expected shape %s, got: %s", test.name, exp, n.Shape()) } - for _, pair := range r.SeriesEpisodes() { - if pair[0] != 0 { - t.Errorf("%q: expected the episodes in no season, got: %v", test.name, pair) + for season := range n.All() { + if season != NoSeason { + t.Errorf("%q: expected the episodes in no season, got one in season %d", test.name, season) break } } @@ -444,26 +624,26 @@ func TestSeasonRange(t *testing.T) { notRanges := []struct { name string season int - spans []EpisodeSpan + spans []Ep }{ // a season and its episode - {"[Grp] Show Season 3 - 03 [1080p]", 3, []EpisodeSpan{{"3", "03", ""}}}, - {"[Grp] Show Season 1 - 12 [1080p]", 1, []EpisodeSpan{{"1", "12", ""}}}, - {"[Grp] Show Season 2 - 8 [1080p]", 2, []EpisodeSpan{{"2", "8", ""}}}, - {"[Grp] Show S2 - 04 [1080p]", 2, []EpisodeSpan{{"2", "04", ""}}}, - {"[Grp] Show S01 - 04 [1080p]", 1, []EpisodeSpan{{"01", "04", ""}}}, - {"[Grp] Show S01 - 04 (1080p)", 1, []EpisodeSpan{{"01", "04", ""}}}, - {"[Grp] Show S01 - 12 + OVA [1080p]", 1, []EpisodeSpan{{"01", "12", ""}}}, - {"[Grp] Show Season 1 - 12 + OVA [1080p]", 1, []EpisodeSpan{{"1", "12", ""}}}, - {"[Grp] Show (S01 - 12) [1080p]", 1, []EpisodeSpan{{"01", "12", ""}}}, + {"[Grp] Show Season 3 - 03 [1080p]", 3, []Ep{ep(3, 3, 3)}}, + {"[Grp] Show Season 1 - 12 [1080p]", 1, []Ep{ep(1, 12, 12)}}, + {"[Grp] Show Season 2 - 8 [1080p]", 2, []Ep{ep(2, 8, 8)}}, + {"[Grp] Show S2 - 04 [1080p]", 2, []Ep{ep(2, 4, 4)}}, + {"[Grp] Show S01 - 04 [1080p]", 1, []Ep{ep(1, 4, 4)}}, + {"[Grp] Show S01 - 04 (1080p)", 1, []Ep{ep(1, 4, 4)}}, + {"[Grp] Show S01 - 12 + OVA [1080p]", 1, []Ep{ep(1, 12, 12)}}, + {"[Grp] Show Season 1 - 12 + OVA [1080p]", 1, []Ep{ep(1, 12, 12)}}, + {"[Grp] Show (S01 - 12) [1080p]", 1, []Ep{ep(1, 12, 12)}}, } for _, test := range notRanges { - r := ParseString(test.name) - if v := r.Seasons(); !slices.Equal(v, []int{test.season}) { - t.Errorf("%q: expected season %d alone, got: %v", test.name, test.season, v) + n := ParseString(test.name).Numbering + if !slices.Equal(n.Seasons, []int{test.season}) { + t.Errorf("%q: expected season %d alone, got: %v", test.name, test.season, n.Seasons) } - if v := r.EpisodeSpans(); !slices.Equal(v, test.spans) { - t.Errorf("%q: expected spans %q, got: %q", test.name, test.spans, v) + if !slices.Equal(n.Episodes, test.spans) { + t.Errorf("%q: expected episodes %v, got: %v", test.name, test.spans, n.Episodes) } } // the second number is not a season: it is not the higher one, it is @@ -481,7 +661,7 @@ func TestSeasonRange(t *testing.T) { {"Show.S01-720p.WEB.x264-GRP", []int{1}}, {"The.Four.Seasons.1-2.1080p.BluRay.x264-GRP", nil}, } { - if v := ParseString(test.name).Seasons(); !slices.Equal(v, test.seasons) { + if v := ParseString(test.name).Numbering.Seasons; !slices.Equal(v, test.seasons) { t.Errorf("%q: expected seasons %v, got: %v", test.name, test.seasons, v) } } @@ -534,14 +714,15 @@ func TestSeasonList(t *testing.T) { } for _, test := range tests { r := ParseString(test.name) - if v := r.Seasons(); !slices.Equal(v, test.seasons) { - t.Errorf("%q: expected seasons %v, got: %v", test.name, test.seasons, v) + n := r.Numbering + if !slices.Equal(n.Seasons, test.seasons) { + t.Errorf("%q: expected seasons %v, got: %v", test.name, test.seasons, n.Seasons) } - if r.Type != Series || r.Series != test.seasons[0] || !strings.HasPrefix(r.Title, "Show") { - t.Errorf("%q: expected series %d of Show, got: %s %d of %q", test.name, test.seasons[0], r.Type, r.Series, r.Title) + if season, _ := n.Season(); r.Type != Series || season != test.seasons[0] || !strings.HasPrefix(r.Title, "Show") { + t.Errorf("%q: expected series %d of Show, got: %s %d of %q", test.name, test.seasons[0], r.Type, season, r.Title) } - if r.HasEpisode() { - t.Errorf("%q: expected no episode, got: %q", test.name, r.EpisodeSpans()) + if n.Episodes != nil || n.Alt != nil || n.Shape() != ShapeSeasons { + t.Errorf("%q: expected seasons and no episode, got: %v %v, %s", test.name, n.Episodes, n.Alt, n.Shape()) } for _, tag := range r.Unused() { if s := tag.Text(); s == "&" || strings.Trim(s, "0123456789") == "" { @@ -611,7 +792,7 @@ func TestSeasonList(t *testing.T) { {"Artist-Seasons_1_&_2-WEB-FLAC-2020-GRP", nil}, } { r := ParseString(test.name) - if v := r.Seasons(); !slices.Equal(v, test.seasons) { + if v := r.Numbering.Seasons; !slices.Equal(v, test.seasons) { t.Errorf("%q: expected seasons %v, got: %v", test.name, test.seasons, v) } if s := fmt.Sprintf("%o", r); s != test.name { @@ -624,8 +805,8 @@ func TestSeasonList(t *testing.T) { "Show.S01,24.12.2020.1080p.WEB.H264-GRP", "Show S01 & 24.12.2020", } { - if r := ParseString(name); r.Year != 2020 || r.Month != 12 || r.Day != 24 || !slices.Equal(r.Seasons(), []int{1}) { - t.Errorf("%q: expected season 1 and 2020-12-24, got: %v and %d-%d-%d", name, r.Seasons(), r.Year, r.Month, r.Day) + if r := ParseString(name); r.Year != 2020 || r.Month != 12 || r.Day != 24 || !slices.Equal(r.Numbering.Seasons, []int{1}) { + t.Errorf("%q: expected season 1 and 2020-12-24, got: %v and %d-%d-%d", name, r.Numbering.Seasons, r.Year, r.Month, r.Day) } } } @@ -636,40 +817,40 @@ func TestSeasonListEpisodes(t *testing.T) { for _, test := range []struct { name string seasons []int - spans []EpisodeSpan + spans []Ep }{ - {"[Grp] Show Season 1+2 (01-25) [1080p]", []int{1, 2}, []EpisodeSpan{{"", "01", "25"}}}, - {"[Grp] Show S1+S2 (01-25) [1080p]", []int{1, 2}, []EpisodeSpan{{"", "01", "25"}}}, - {"[Grp] Show S1, S2 (01-25) [1080p]", []int{1, 2}, []EpisodeSpan{{"", "01", "25"}}}, - {"[Grp] Show (Season 01 + Season 02) (01-25) [1080p]", []int{1, 2}, []EpisodeSpan{{"", "01", "25"}}}, - {"[Grp] Show Season 1 & Season 2 (01-25) [1080p]", []int{1, 2}, []EpisodeSpan{{"", "01", "25"}}}, - {"[Grp] Show S1 + S2 - 05 [1080p]", []int{1, 2}, []EpisodeSpan{{"", "05", ""}}}, + {"[Grp] Show Season 1+2 (01-25) [1080p]", []int{1, 2}, []Ep{ep(NoSeason, 1, 25)}}, + {"[Grp] Show S1+S2 (01-25) [1080p]", []int{1, 2}, []Ep{ep(NoSeason, 1, 25)}}, + {"[Grp] Show S1, S2 (01-25) [1080p]", []int{1, 2}, []Ep{ep(NoSeason, 1, 25)}}, + {"[Grp] Show (Season 01 + Season 02) (01-25) [1080p]", []int{1, 2}, []Ep{ep(NoSeason, 1, 25)}}, + {"[Grp] Show Season 1 & Season 2 (01-25) [1080p]", []int{1, 2}, []Ep{ep(NoSeason, 1, 25)}}, + {"[Grp] Show S1 + S2 - 05 [1080p]", []int{1, 2}, []Ep{ep(NoSeason, 5, 5)}}, // one season, written twice or once - {"[Grp] Show Season 1 (S01) (01-25) [1080p]", []int{1}, []EpisodeSpan{{"01", "01", "25"}}}, - {"[Grp] Show S2 (01-25) [1080p]", []int{2}, []EpisodeSpan{{"2", "01", "25"}}}, + {"[Grp] Show Season 1 (S01) (01-25) [1080p]", []int{1}, []Ep{ep(1, 1, 25)}}, + {"[Grp] Show S2 (01-25) [1080p]", []int{2}, []Ep{ep(2, 1, 25)}}, } { - r := ParseString(test.name) - if v := r.Seasons(); !slices.Equal(v, test.seasons) { - t.Errorf("%q: expected seasons %v, got: %v", test.name, test.seasons, v) + n := ParseString(test.name).Numbering + if !slices.Equal(n.Seasons, test.seasons) { + t.Errorf("%q: expected seasons %v, got: %v", test.name, test.seasons, n.Seasons) } - if v := r.EpisodeSpans(); !slices.Equal(v, test.spans) { - t.Errorf("%q: expected spans %q, got: %q", test.name, test.spans, v) + if !slices.Equal(n.Episodes, test.spans) { + t.Errorf("%q: expected episodes %v, got: %v", test.name, test.spans, n.Episodes) } - season := atoi(test.spans[0].Season) - for _, pair := range r.SeriesEpisodes() { - if pair[0] != season { - t.Errorf("%q: expected the episodes in season %d, got: %v", test.name, season, pair) + for season := range n.All() { + if season != test.spans[0].Season { + t.Errorf("%q: expected the episodes in season %d, got one in season %d", test.name, test.spans[0].Season, season) break } } - if first, last, ok := r.EpisodeRange(); ok != (test.spans[0].Last != "") || ok && (first != 1 || last != 25) { + if first, last, ok := episodeRange(n); ok != (test.spans[0].First != test.spans[0].Last) || ok && (first != 1 || last != 25) { t.Errorf("%q: expected the range 1 to 25 where one is written, got: %d, %d, %t", test.name, first, last, ok) } } } -// TestSeasonZeroFirst checks that Series is the first season the name writes -// when that season is 0, and not the season of a second numbering after it. +// TestSeasonZeroFirst checks that Season gives the first season the name +// writes when that season is 0, and not the season of a second numbering +// after it. func TestSeasonZeroFirst(t *testing.T) { tests := []struct { name string @@ -690,21 +871,22 @@ func TestSeasonZeroFirst(t *testing.T) { } for _, test := range tests { r := ParseString(test.name) - if r.Series != test.series || r.Episode != test.episode { - t.Errorf("%q: expected series %d episode %d, got: %d and %d", test.name, test.series, test.episode, r.Series, r.Episode) + season, ok := r.Numbering.Season() + if episode, _ := r.Numbering.Episode(); season != test.series || episode != test.episode { + t.Errorf("%q: expected series %d episode %d, got: %d and %d", test.name, test.series, test.episode, season, episode) } if r.Type != test.typ { t.Errorf("%q: expected type %s, got: %s", test.name, test.typ, r.Type) } - if !r.HasSeason() { + if !ok { t.Errorf("%q: expected a season", test.name) } } } -// TestHalfEpisode checks that half an episode keeps its fraction in the tag: -// Episode is the whole number, the fraction is not a word of the name, and the -// number is not an absolute one. +// TestHalfEpisode checks that half an episode keeps its fraction in the tag +// and in Frac: Episode gives the whole number, the fraction is not a word of +// the name, and the number is not an absolute one. func TestHalfEpisode(t *testing.T) { tests := []struct { name string @@ -743,26 +925,33 @@ func TestHalfEpisode(t *testing.T) { } for _, test := range tests { r := ParseString(test.name) + n := r.Numbering var fraction string for _, tag := range r.Tags() { fraction += tag.fraction() } - _, absolute := r.Absolute() - if r.Episode != test.episode || fraction != test.fraction || r.Subtitle != test.subtitle { - t.Errorf("%q: expected episode %d, fraction %q, subtitle %q, got: %d, %q, %q", test.name, test.episode, test.fraction, test.subtitle, r.Episode, fraction, r.Subtitle) + episode, _ := n.Episode() + _, absolute := n.Absolute() + if episode != test.episode || fraction != test.fraction || r.Subtitle != test.subtitle { + t.Errorf("%q: expected episode %d, fraction %q, subtitle %q, got: %d, %q, %q", test.name, test.episode, test.fraction, test.subtitle, episode, fraction, r.Subtitle) } if absolute && test.fraction != "" { t.Errorf("%q: expected no absolute episode", test.name) } - if pairs := r.SeriesEpisodes(); len(pairs) != 1 { - t.Errorf("%q: expected one episode, got: %v", test.name, pairs) + if n.Shape() != ShapeEpisode { + t.Errorf("%q: expected one episode, got: %v", test.name, n.Episodes) + } + // Frac is the digits of the fraction as a number, without the zeros + // that end them: '.10' is the tenth that '.1' is + if frac := strings.TrimRight(strings.TrimPrefix(test.fraction, "."), "0"); len(n.Episodes) != 1 || int(n.Episodes[0].Frac) != atoi(frac) { + t.Errorf("%q: expected the fraction %q in Frac, got: %v", test.name, frac, n.Episodes) } if s := fmt.Sprintf("%o", r); s != test.name { t.Errorf("%q: expected the name back, got: %q", test.name, s) } } // the dot of 'Ep.' is not a decimal point - if episode, ok := ParseString("[Group] Show Ep. 07 [720p]").Absolute(); episode != 7 || !ok { + if episode, ok := ParseString("[Group] Show Ep. 07 [720p]").Numbering.Absolute(); episode != 7 || !ok { t.Errorf("expected absolute 7 true, got: %d %t", episode, ok) } } @@ -773,21 +962,21 @@ func TestHalfEpisode(t *testing.T) { func TestBracketedRange(t *testing.T) { tests := []struct { name string - spans []EpisodeSpan + spans []Ep }{ - {"[Grp] Show Title [1-13]", []EpisodeSpan{{"", "1", "13"}}}, - {"[Grp] Show Title (01-13)", []EpisodeSpan{{"", "01", "13"}}}, - {"Show Title (01-12).mkv", []EpisodeSpan{{"", "01", "12"}}}, - {"Show_Title [1-13] [.srt]", []EpisodeSpan{{"", "1", "13"}}}, + {"[Grp] Show Title [1-13]", []Ep{ep(NoSeason, 1, 13)}}, + {"[Grp] Show Title (01-13)", []Ep{ep(NoSeason, 1, 13)}}, + {"Show Title (01-12).mkv", []Ep{ep(NoSeason, 1, 12)}}, + {"Show_Title [1-13] [.srt]", []Ep{ep(NoSeason, 1, 13)}}, // in the middle of the name, as before - {"[Grp] Show Title [01-13] [1080p]", []EpisodeSpan{{"", "01", "13"}}}, + {"[Grp] Show Title [01-13] [1080p]", []Ep{ep(NoSeason, 1, 13)}}, // a range of years is not one of episodes {"[Grp] Show Title (2019-2020)", nil}, } for _, test := range tests { r := ParseString(test.name) - if v := r.EpisodeSpans(); !slices.Equal(v, test.spans) { - t.Errorf("%q: expected spans %q, got: %q", test.name, test.spans, v) + if v := r.Numbering.Episodes; !slices.Equal(v, test.spans) { + t.Errorf("%q: expected episodes %v, got: %v", test.name, test.spans, v) } if s := fmt.Sprintf("%o", r); s != test.name { t.Errorf("%q: expected the name back, got: %q", test.name, s) @@ -803,7 +992,7 @@ func TestAudioRange(t *testing.T) { name string typ Type artist, title string - spans []EpisodeSpan + spans []Ep }{ {"Mira Calder - Beneath Quiet Skies (2002) HDTracks 2011 [FLAC 24-96]", Music, "Mira Calder", "Beneath Quiet Skies", nil}, {"Mira Calder - Beneath Quiet Skies (2002) [FLAC 24-48]", Music, "Mira Calder", "Beneath Quiet Skies", nil}, @@ -818,23 +1007,23 @@ func TestAudioRange(t *testing.T) { {"Mira Calder - Live in Oslo (2011) [1080p FLAC (24-96)]", Movie, "", "Mira Calder - Live in Oslo", nil}, {"Mira Calder - Live in Oslo (2011) [1080p FLAC(24-96)]", Movie, "", "Mira Calder - Live in Oslo", nil}, // the episodes of a batch, in a name with a resolution - {"[Grp] Show Title - 24-48 [1080p]", Series, "", "Show Title", []EpisodeSpan{{"", "24", "48"}}}, - {"[Grp] Show Title 24-48 [BD 1080p FLAC]", Series, "", "Show Title", []EpisodeSpan{{"", "24", "48"}}}, - {"[Grp] Show Title (16-44) [720p]", Series, "", "Show Title", []EpisodeSpan{{"", "16", "44"}}}, + {"[Grp] Show Title - 24-48 [1080p]", Series, "", "Show Title", []Ep{ep(NoSeason, 24, 48)}}, + {"[Grp] Show Title 24-48 [BD 1080p FLAC]", Series, "", "Show Title", []Ep{ep(NoSeason, 24, 48)}}, + {"[Grp] Show Title (16-44) [720p]", Series, "", "Show Title", []Ep{ep(NoSeason, 16, 44)}}, // after the audio, in a bracket that follows the one the audio is in - {"[Grp] Show Title [BD 1080p FLAC] (24-48)", Series, "", "Show Title", []EpisodeSpan{{"", "24", "48"}}}, - {"[Grp] Show Title [1080p FLAC] [24-48]", Series, "", "Show Title", []EpisodeSpan{{"", "24", "48"}}}, + {"[Grp] Show Title [BD 1080p FLAC] (24-48)", Series, "", "Show Title", []Ep{ep(NoSeason, 24, 48)}}, + {"[Grp] Show Title [1080p FLAC] [24-48]", Series, "", "Show Title", []Ep{ep(NoSeason, 24, 48)}}, // a range that is no bit depth and sample rate - {"[Grp] Show Title - 24-50 [FLAC]", Series, "", "Show Title", []EpisodeSpan{{"", "24", "50"}}}, - {"[Grp] Show Title - 01-48 [FLAC]", Series, "", "Show Title", []EpisodeSpan{{"", "01", "48"}}}, + {"[Grp] Show Title - 24-50 [FLAC]", Series, "", "Show Title", []Ep{ep(NoSeason, 24, 50)}}, + {"[Grp] Show Title - 01-48 [FLAC]", Series, "", "Show Title", []Ep{ep(NoSeason, 1, 48)}}, } for _, test := range tests { r := ParseString(test.name) if r.Type != test.typ || r.Artist != test.artist || r.Title != test.title { t.Errorf("%q: expected type %s, artist %q and title %q, got: %s, %q and %q", test.name, test.typ, test.artist, test.title, r.Type, r.Artist, r.Title) } - if v := r.EpisodeSpans(); !slices.Equal(v, test.spans) { - t.Errorf("%q: expected spans %q, got: %q", test.name, test.spans, v) + if v := r.Numbering.Episodes; !slices.Equal(v, test.spans) { + t.Errorf("%q: expected episodes %v, got: %v", test.name, test.spans, v) } if s := fmt.Sprintf("%o", r); s != test.name { t.Errorf("%q: expected the name back, got: %q", test.name, s) @@ -887,8 +1076,9 @@ func TestGermanSeason(t *testing.T) { } for _, test := range tests { r := ParseString(test.name) - if r.Series != test.series || r.Episode != test.episode || r.Type != test.typ { - t.Errorf("%q: expected series %d, episode %d, type %s, got: %d, %d, %s", test.name, test.series, test.episode, test.typ, r.Series, r.Episode, r.Type) + season, _ := r.Numbering.Season() + if episode, _ := r.Numbering.Episode(); season != test.series || episode != test.episode || r.Type != test.typ { + t.Errorf("%q: expected series %d, episode %d, type %s, got: %d, %d, %s", test.name, test.series, test.episode, test.typ, season, episode, r.Type) } if s := fmt.Sprintf("%o", r); s != test.name { t.Errorf("%q: expected the name back, got: %q", test.name, s) @@ -938,7 +1128,7 @@ func TestSeasonInEpisodeTitle(t *testing.T) { if r.Subtitle != test.subtitle { t.Errorf("%q: expected subtitle %q, got: %q", test.name, test.subtitle, r.Subtitle) } - if v := r.Seasons(); !slices.Equal(v, test.seasons) { + if v := r.Numbering.Seasons; !slices.Equal(v, test.seasons) { t.Errorf("%q: expected seasons %v, got: %v", test.name, test.seasons, v) } if s := fmt.Sprintf("%o", r); s != test.name { @@ -952,7 +1142,7 @@ func TestSeasonInEpisodeTitle(t *testing.T) { "Show.S01E01.Title+Season.2.1080p.WEB.h264-GRP", } { r := ParseString(name) - if v := r.Seasons(); !slices.Equal(v, []int{1, 2}) { + if v := r.Numbering.Seasons; !slices.Equal(v, []int{1, 2}) { t.Errorf("%q: expected seasons [1 2], got: %v", name, v) } if s := fmt.Sprintf("%o", r); s != name { @@ -961,101 +1151,696 @@ func TestSeasonInEpisodeTitle(t *testing.T) { } } -func TestEpisodeSpans(t *testing.T) { +// TestEpisodes checks the episodes a name gives, in the order it writes them +// and with a range as one Ep, and the second numberings beside them. +func TestEpisodes(t *testing.T) { tests := []struct { name string - exp []EpisodeSpan + exp []Ep + alt []Ep }{ - // one episode, with its leading zero - {"Show.S01E02.1080p.WEB.h264-GRP", []EpisodeSpan{{"01", "02", ""}}}, - {"[Group] Show - 04 [720p]", []EpisodeSpan{{"", "04", ""}}}, - {"[Group] Show - 1169 [720p]", []EpisodeSpan{{"", "1169", ""}}}, + // one episode + {"Show.S01E02.1080p.WEB.h264-GRP", []Ep{ep(1, 2, 2)}, nil}, + {"[Group] Show - 04 [720p]", []Ep{ep(NoSeason, 4, 4)}, nil}, + {"[Group] Show - 1169 [720p]", []Ep{ep(NoSeason, 1169, 1169)}, nil}, // half an episode - {"[Group] Show - 21.5 [720p]", []EpisodeSpan{{"", "21.5", ""}}}, - {"[Group] Show - 12.10 [720p]", []EpisodeSpan{{"", "12.10", ""}}}, - {"[Group] Show - 13.5v2 [720p]", []EpisodeSpan{{"", "13.5", ""}}}, - {"Show.S01E06.5.720p.WEB.x264-GRP", []EpisodeSpan{{"01", "06.5", ""}}}, - {"[Group] Show Ep 5.5 [720p]", []EpisodeSpan{{"", "5.5", ""}}}, + {"[Group] Show - 21.5 [720p]", []Ep{{Season: NoSeason, First: 21, Last: 21, Frac: 5}}, nil}, + {"[Group] Show - 12.10 [720p]", []Ep{{Season: NoSeason, First: 12, Last: 12, Frac: 1}}, nil}, + {"[Group] Show - 12.50 [720p]", []Ep{{Season: NoSeason, First: 12, Last: 12, Frac: 5}}, nil}, + {"[Group] Show - 12.5 [720p]", []Ep{{Season: NoSeason, First: 12, Last: 12, Frac: 5}}, nil}, + // a zero in front of the fraction is not kept + {"[Group] Show - 12.05 [720p]", []Ep{{Season: NoSeason, First: 12, Last: 12, Frac: 5}}, nil}, + {"[Group] Show - 13.5v2 [720p]", []Ep{{Season: NoSeason, First: 13, Last: 13, Frac: 5}}, nil}, + {"Show.S01E06.5.720p.WEB.x264-GRP", []Ep{{Season: 1, First: 6, Last: 6, Frac: 5}}, nil}, + {"[Group] Show Ep 5.5 [720p]", []Ep{{Season: NoSeason, First: 5, Last: 5, Frac: 5}}, nil}, // an episode 0 - {"[Group] Show - 00 [720p]", []EpisodeSpan{{"", "00", ""}}}, - {"Show.S01E00.1080p.WEB.h264-GRP", []EpisodeSpan{{"01", "00", ""}}}, - {"Show.S00E05.1080p.WEB.h264-GRP", []EpisodeSpan{{"00", "05", ""}}}, + {"[Group] Show - 00 [720p]", []Ep{ep(NoSeason, 0, 0)}, nil}, + {"Show.S01E00.1080p.WEB.h264-GRP", []Ep{ep(1, 0, 0)}, nil}, + {"Show.S00E05.1080p.WEB.h264-GRP", []Ep{ep(0, 5, 5)}, nil}, // ranges, inside a tag and between two tags - {"Show.S01E02-04.1080p.WEB.h264-GRP", []EpisodeSpan{{"01", "02", "04"}}}, - {"Show.S01E02-E04.1080p.WEB.h264-GRP", []EpisodeSpan{{"01", "02", "04"}}}, - {"Show.S00E02-S00E04.1080p.WEB.h264-GRP", []EpisodeSpan{{"00", "02", "04"}}}, - {"[Group] Show - 00 ~ 12 [720p]", []EpisodeSpan{{"", "00", "12"}}}, - {"[Group] Show (01-12) [720p]", []EpisodeSpan{{"", "01", "12"}}}, + {"Show.S01E02-04.1080p.WEB.h264-GRP", []Ep{ep(1, 2, 4)}, nil}, + {"Show.S01E02-E04.1080p.WEB.h264-GRP", []Ep{ep(1, 2, 4)}, nil}, + {"Show.S00E02-S00E04.1080p.WEB.h264-GRP", []Ep{ep(0, 2, 4)}, nil}, + {"[Group] Show - 00 ~ 12 [720p]", []Ep{ep(NoSeason, 0, 12)}, nil}, + {"[Group] Show (01-12) [720p]", []Ep{ep(NoSeason, 1, 12)}, nil}, // a range that ends the title, in front of the episodes - {"[Group] Show 17-26 - 01 ~ 08 [720p]", []EpisodeSpan{{"", "01", "08"}}}, + {"[Group] Show 17-26 - 01 ~ 08 [720p]", []Ep{ep(NoSeason, 1, 8)}, nil}, // a range that starts at 1 is the episodes of a batch, not the title - {"[Group] Show 01-12 - 13 [720p]", []EpisodeSpan{{"", "01", "12"}, {"", "13", ""}}}, - {"Show.S01E1-E99999.1080p.WEB.h264-GRP", []EpisodeSpan{{"01", "1", "99999"}}}, + {"[Group] Show 01-12 - 13 [720p]", []Ep{ep(NoSeason, 1, 12), ep(NoSeason, 13, 13)}, nil}, + {"Show.S01E1-E99999.1080p.WEB.h264-GRP", []Ep{ep(1, 1, 99999)}, nil}, // episodes that are not a range - {"Show.S01E05E06.1080p.WEB.h264-GRP", []EpisodeSpan{{"01", "05", ""}, {"01", "06", ""}}}, - {"Show.S01E01.S02E01.1080p.WEB.h264-GRP", []EpisodeSpan{{"01", "01", ""}, {"02", "01", ""}}}, - {"Show.S01E02-S02E04.1080p.WEB.h264-GRP", []EpisodeSpan{{"01", "02", ""}, {"02", "04", ""}}}, + {"Show.S01E05E06.1080p.WEB.h264-GRP", []Ep{ep(1, 5, 5), ep(1, 6, 6)}, nil}, + {"Show.S01E01.S02E01.1080p.WEB.h264-GRP", []Ep{ep(1, 1, 1), ep(2, 1, 1)}, nil}, + {"Show.S01E02-S02E04.1080p.WEB.h264-GRP", []Ep{ep(1, 2, 2), ep(2, 4, 4)}, nil}, // the season written before the episode, and a season 0 after another - {"[Group] Show S2 - 04 [720p]", []EpisodeSpan{{"2", "04", ""}}}, - {"[Group] Show 2nd Season - 08 [720p]", []EpisodeSpan{{"2", "08", ""}}}, - {"[Group] Show - S04E29 (WEB 1080p) | Other Name - E88 - S00E36", []EpisodeSpan{{"04", "29", ""}, {"04", "88", ""}, {"00", "36", ""}}}, + {"[Group] Show S2 - 04 [720p]", []Ep{ep(2, 4, 4)}, nil}, + {"[Group] Show 2nd Season - 08 [720p]", []Ep{ep(2, 8, 8)}, nil}, + {"[Group] Show - S04E29 (WEB 1080p) | Other Name - E88 - S00E36", []Ep{ep(4, 29, 29), ep(4, 88, 88), ep(0, 36, 36)}, nil}, // a range goes on over a second hyphen - {"Show.S01E02-E03-E04.1080p.WEB.h264-GRP", []EpisodeSpan{{"01", "02", "04"}}}, - {"Show.S01E02-E04-06.1080p.WEB.h264-GRP", []EpisodeSpan{{"01", "02", "06"}}}, - {"Show.S01E01-E02.E04-E05.1080p.WEB.h264-GRP", []EpisodeSpan{{"01", "01", "02"}, {"01", "04", "05"}}}, - {"Show.Ep.05-07.1080p.WEB.h264-GRP", []EpisodeSpan{{"", "05", "07"}}}, - {"[Group] Show S2 - 04 ~ 06 [720p]", []EpisodeSpan{{"2", "04", "06"}}}, - {"Show.S01E05-E06.5.1080p.WEB.h264-GRP", []EpisodeSpan{{"01", "05", "06.5"}}}, - // an end that is not higher, a hyphen with spaces and a tilde between - // two tags make no range - {"Show.S01E02-E01.1080p.WEB.h264-GRP", []EpisodeSpan{{"01", "02", ""}, {"01", "01", ""}}}, - {"Show.S01E05-E05.1080p.WEB.h264-GRP", []EpisodeSpan{{"01", "05", ""}, {"01", "05", ""}}}, - {"Show S01E02 - E04 1080p WEB h264-GRP", []EpisodeSpan{{"01", "02", ""}, {"01", "04", ""}}}, + {"Show.S01E02-E03-E04.1080p.WEB.h264-GRP", []Ep{ep(1, 2, 4)}, nil}, + {"Show.S01E02-E04-06.1080p.WEB.h264-GRP", []Ep{ep(1, 2, 6)}, nil}, + {"Show.S01E01-E02.E04-E05.1080p.WEB.h264-GRP", []Ep{ep(1, 1, 2), ep(1, 4, 5)}, nil}, + {"Show.Ep.05-07.1080p.WEB.h264-GRP", []Ep{ep(NoSeason, 5, 7)}, nil}, + {"[Group] Show S2 - 04 ~ 06 [720p]", []Ep{ep(2, 4, 6)}, nil}, + {"Show.S01E05-E06.5.1080p.WEB.h264-GRP", []Ep{{Season: 1, First: 5, Last: 6, Frac: 5}}, nil}, + // an end that is not higher and a hyphen with spaces between two tags + // make no range, and the same episode twice is listed once + {"Show.S01E02-E01.1080p.WEB.h264-GRP", []Ep{ep(1, 2, 2), ep(1, 1, 1)}, nil}, + {"Show.S01E05-E05.1080p.WEB.h264-GRP", []Ep{ep(1, 5, 5)}, nil}, + {"Show S01E02 - E04 1080p WEB h264-GRP", []Ep{ep(1, 2, 2), ep(1, 4, 4)}, nil}, // the season carried over a tag with no episode, and none carried back - {"Show.S01.1080p.E05.WEB.h264-GRP", []EpisodeSpan{{"01", "05", ""}}}, - {"Show.E05.S01.1080p.WEB.h264-GRP", []EpisodeSpan{{"", "05", ""}}}, + {"Show.S01.1080p.E05.WEB.h264-GRP", []Ep{ep(1, 5, 5)}, nil}, + {"Show.E05.S01.1080p.WEB.h264-GRP", []Ep{ep(NoSeason, 5, 5)}, nil}, // the channels are not a fraction - {"Show.S01E06.5.1.AAC.720p.WEB-GRP", []EpisodeSpan{{"01", "06", ""}}}, + {"Show.S01E06.5.1.AAC.720p.WEB-GRP", []Ep{ep(1, 6, 6)}, nil}, // a tilde makes a range as a hyphen does, inside a tag and between two - {"[Grp] Show S04E29~E31 1080p WEB H.264", []EpisodeSpan{{"04", "29", "31"}}}, - {"Show.S01E01~03.1080p.WEB.x264-GRP", []EpisodeSpan{{"01", "01", "03"}}}, + {"[Grp] Show S04E29~E31 1080p WEB H.264", []Ep{ep(4, 29, 31)}, nil}, + // the end of a range that a version follows, and a second numbering + // after a hyphen, which is no range + {"Show.S04E29-31v2.1080p.WEB.H264-GRP", []Ep{ep(4, 29, 31)}, nil}, + {"Show.S23E19-1174v2.1080p.WEB.H264-GRP", []Ep{ep(23, 19, 19)}, []Ep{ep(NoSeason, 1174, 1174)}}, + {"Show.S01E05-Episode.10.1080p.WEB.H264-GRP", []Ep{ep(1, 5, 5)}, []Ep{ep(NoSeason, 10, 10)}}, + {"Show.S01E01~03.1080p.WEB.x264-GRP", []Ep{ep(1, 1, 3)}, nil}, // a range end of four digits after an episode of three or more - {"[Grp] Show EP1156-1170 [1080p]", []EpisodeSpan{{"", "1156", "1170"}}}, - {"Show.S01E1001-1004.1080p.WEB.x264-GRP", []EpisodeSpan{{"01", "1001", "1004"}}}, - {"[Grp] Show E998-1002 [1080p]", []EpisodeSpan{{"", "998", "1002"}}}, + {"[Grp] Show EP1156-1170 [1080p]", []Ep{ep(NoSeason, 1156, 1170)}, nil}, + {"Show.S01E1001-1004.1080p.WEB.x264-GRP", []Ep{ep(1, 1001, 1004)}, nil}, + {"[Grp] Show E998-1002 [1080p]", []Ep{ep(NoSeason, 998, 1002)}, nil}, // four digits after a lower episode are a year or another number, as // are those a thousand episodes on - {"Show.S01E05-2020.1080p.WEB.x264-GRP", []EpisodeSpan{{"01", "05", ""}}}, - {"[Grp] Show E05-2020 [1080p]", []EpisodeSpan{{"", "05", ""}}}, - {"Show.S01E05-1080.WEB.x264-GRP", []EpisodeSpan{{"01", "05", ""}}}, - {"Show.S01E100-9999.WEB.x264-GRP", []EpisodeSpan{{"01", "100", ""}}}, + {"Show.S01E05-2020.1080p.WEB.x264-GRP", []Ep{ep(1, 5, 5)}, nil}, + {"[Grp] Show E05-2020 [1080p]", []Ep{ep(NoSeason, 5, 5)}, nil}, + {"Show.S01E05-1080.WEB.x264-GRP", []Ep{ep(1, 5, 5)}, nil}, + {"Show.S01E100-9999.WEB.x264-GRP", []Ep{ep(1, 100, 100)}, nil}, // half an episode with a tag or a version right after it - {"Show.S01E06.5.WEB.x264-GRP", []EpisodeSpan{{"01", "06.5", ""}}}, - {"Show.S01E02.5v2.720p.WEB.x264-GRP", []EpisodeSpan{{"01", "02.5", ""}}}, - // one episode under two numberings, in the order written - {"Show.S23E19.Episode.1174.1080p.WEB.h264-GRP", []EpisodeSpan{{"23", "19", ""}, {"23", "1174", ""}}}, + {"Show.S01E06.5.WEB.x264-GRP", []Ep{{Season: 1, First: 6, Last: 6, Frac: 5}}, nil}, + {"Show.S01E02.5v2.720p.WEB.x264-GRP", []Ep{{Season: 1, First: 2, Last: 2, Frac: 5}}, nil}, + // one episode under two numberings: the second one has no season + {"Show.S23E19.Episode.1174.1080p.WEB.h264-GRP", []Ep{ep(23, 19, 19)}, []Ep{ep(NoSeason, 1174, 1174)}}, + {"[Grp] Show - 1174 (S23E19) [1080p]", []Ep{ep(23, 19, 19)}, []Ep{ep(NoSeason, 1174, 1174)}}, + {"Noragami - S02E06 - What Must Be Done [Episode 6]", []Ep{ep(2, 6, 6)}, []Ep{ep(NoSeason, 6, 6)}}, + // a second numbering starts no range, ends none, and is a range of + // its own when it writes one + {"Show.S01E01.Episode.5-E07.1080p.WEB.h264-GRP", []Ep{ep(1, 1, 1), ep(1, 7, 7)}, []Ep{ep(NoSeason, 5, 5)}}, + {"Show.S01E01.Episode.5-7.1080p.WEB.h264-GRP", []Ep{ep(1, 1, 1)}, []Ep{ep(NoSeason, 5, 7)}}, + {"Show.S01E01.Episode.5.5.1080p.WEB.h264-GRP", []Ep{ep(1, 1, 1)}, []Ep{{Season: NoSeason, First: 5, Last: 5, Frac: 5}}}, + // the same episode written twice, in a path + {"Show.S11E11-GRP/Show.S11E11-GRP.mkv", []Ep{ep(11, 11, 11)}, nil}, // no episode - {"Show.S01.1080p.WEB.h264-GRP", nil}, - {"Show.S01-S03.1080p.WEB.h264-GRP", nil}, - {"Show.2024.10.13.1080p.WEB.h264-GRP", nil}, - {"Movie.2020.1080p.BluRay.x264-GRP", nil}, + {"Show.S01.1080p.WEB.h264-GRP", nil, nil}, + {"Show.S01-S03.1080p.WEB.h264-GRP", nil, nil}, + {"Show.2024.10.13.1080p.WEB.h264-GRP", nil, nil}, + {"Movie.2020.1080p.BluRay.x264-GRP", nil, nil}, } for _, test := range tests { - if v := ParseString(test.name).EpisodeSpans(); !slices.Equal(v, test.exp) { - t.Errorf("%q: expected spans %q, got: %q", test.name, test.exp, v) + n := ParseString(test.name).Numbering + if !slices.Equal(n.Episodes, test.exp) || !slices.Equal(n.Alt, test.alt) { + t.Errorf("%q: expected episodes %v and second numbering %v, got: %v and %v", test.name, test.exp, test.alt, n.Episodes, n.Alt) } } - // by hand - if v := (Release{Series: 2, Episode: 5}).EpisodeSpans(); !slices.Equal(v, []EpisodeSpan{{"2", "5", ""}}) { - t.Errorf("expected the episode set by hand, got: %q", v) +} + +// TestNumberingValue checks the whole Numbering of names that between them +// have every scheme and shape, and what its methods give for it. +func TestNumberingValue(t *testing.T) { + type answers struct { + season, episode, absolute int + seasoned, numbered, abs bool + shape Shape } - if v := (Release{Series: 2}).EpisodeSpans(); v != nil { - t.Errorf("expected no span, got: %q", v) + tests := []struct { + name string + exp Numbering + ans answers + }{ + // a season and an episode + { + "Show.S01E05.1080p.WEB.h264-GRP", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{1}, Episodes: []Ep{ep(1, 5, 5)}}, + answers{season: 1, seasoned: true, episode: 5, numbered: true, shape: ShapeEpisode}, + }, + { + "Show.1x05.1080p.WEB.h264-GRP", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{1}, Episodes: []Ep{ep(1, 5, 5)}}, + answers{season: 1, seasoned: true, episode: 5, numbered: true, shape: ShapeEpisode}, + }, + // a season in front of the episode + { + "[Grp] Show S2 - 04 [1080p].mkv", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{2}, Episodes: []Ep{ep(2, 4, 4)}}, + answers{season: 2, seasoned: true, episode: 4, numbered: true, shape: ShapeEpisode}, + }, + { + "[Grp] Show 2nd Season - 08 [1080p].mkv", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{2}, Episodes: []Ep{ep(2, 8, 8)}}, + answers{season: 2, seasoned: true, episode: 8, numbered: true, shape: ShapeEpisode}, + }, + // season 0 and episode 0 are a season and an episode + { + "Show.S00E05.1080p.WEB.h264-GRP", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{0}, Episodes: []Ep{ep(0, 5, 5)}}, + answers{seasoned: true, episode: 5, numbered: true, shape: ShapeEpisode}, + }, + { + "Show.S01E00.1080p.WEB.h264-GRP", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{1}, Episodes: []Ep{ep(1, 0, 0)}}, + answers{season: 1, seasoned: true, numbered: true, shape: ShapeEpisode}, + }, + { + "[Grp] Show - 00 [1080p].mkv", + Numbering{Scheme: SchemeAbsolute, Episodes: []Ep{ep(NoSeason, 0, 0)}}, + answers{numbered: true, abs: true, shape: ShapeEpisode}, + }, + // packs + { + "Show.S01.1080p.WEB.h264-GRP", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{1}}, + answers{season: 1, seasoned: true, shape: ShapeSeason}, + }, + { + "Show.S00.1080p.WEB.h264-GRP", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{0}}, + answers{seasoned: true, shape: ShapeSeason}, + }, + { + "Show.S01-S03.1080p.BluRay.x264-GRP", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{1, 2, 3}}, + answers{season: 1, seasoned: true, shape: ShapeSeasons}, + }, + // the seasons are in the order written, and Season gives the first + { + "[Grp] Show [Season 2 + Season 1 OVA] [BD 1080p]", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{2, 1}}, + answers{season: 2, seasoned: true, shape: ShapeSeasons}, + }, + // the first season written is not the season of the episode + { + "Show.S01-S03E05.1080p.BluRay.x264-GRP", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{1, 3}, Episodes: []Ep{ep(3, 5, 5)}}, + answers{season: 1, seasoned: true, episode: 5, numbered: true, shape: ShapeEpisode}, + }, + // several episodes + { + "Show.S01E05E06.1080p.WEB.h264-GRP", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{1}, Episodes: []Ep{ep(1, 5, 5), ep(1, 6, 6)}}, + answers{season: 1, seasoned: true, episode: 5, numbered: true, shape: ShapeEpisodes}, + }, + { + "Show.S01E01-E03.1080p.WEB.h264-GRP", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{1}, Episodes: []Ep{ep(1, 1, 3)}}, + answers{season: 1, seasoned: true, episode: 1, numbered: true, shape: ShapeEpisodes}, + }, + // the first episode of a batch is its episode, as that of any range + { + "[Grp] Show - 01-12 [1080p]", + Numbering{Scheme: SchemeAbsolute, Episodes: []Ep{ep(NoSeason, 1, 12)}}, + answers{episode: 1, numbered: true, shape: ShapeEpisodes}, + }, + { + "[Grp] Show S2 - 01-12 [1080p]", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{2}, Episodes: []Ep{ep(2, 1, 12)}}, + answers{season: 2, seasoned: true, episode: 1, numbered: true, shape: ShapeEpisodes}, + }, + // episodes with no season anywhere are absolute + { + "[Grp] Show - 1169 [1080p].mkv", + Numbering{Scheme: SchemeAbsolute, Episodes: []Ep{ep(NoSeason, 1169, 1169)}}, + answers{episode: 1169, numbered: true, absolute: 1169, abs: true, shape: ShapeEpisode}, + }, + { + "Show.E1100.1080p.WEB.h264-GRP", + Numbering{Scheme: SchemeAbsolute, Episodes: []Ep{ep(NoSeason, 1100, 1100)}}, + answers{episode: 1100, numbered: true, absolute: 1100, abs: true, shape: ShapeEpisode}, + }, + // half an episode + { + "[Grp] Show - 21.5 [1080p].mkv", + Numbering{Scheme: SchemeAbsolute, Episodes: []Ep{{Season: NoSeason, First: 21, Last: 21, Frac: 5}}}, + answers{episode: 21, numbered: true, shape: ShapeEpisode}, + }, + { + "Show.S01E05-E06.5.1080p.WEB.h264-GRP", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{1}, Episodes: []Ep{{Season: 1, First: 5, Last: 6, Frac: 5}}}, + answers{season: 1, seasoned: true, episode: 5, numbered: true, shape: ShapeEpisodes}, + }, + // a second numbering + { + "Show.S23E19.Episode.1174.1080p.WEB.h264-GRP", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{23}, Episodes: []Ep{ep(23, 19, 19)}, Alt: []Ep{ep(NoSeason, 1174, 1174)}}, + answers{season: 23, seasoned: true, episode: 19, numbered: true, absolute: 1174, abs: true, shape: ShapeEpisode}, + }, + { + "Noragami - S02E06 - What Must Be Done [Episode 6]", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{2}, Episodes: []Ep{ep(2, 6, 6)}, Alt: []Ep{ep(NoSeason, 6, 6)}}, + answers{season: 2, seasoned: true, episode: 6, numbered: true, shape: ShapeEpisode}, + }, + { + "Show.S00E05.Episode.12.1080p.WEB.h264-GRP", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{0}, Episodes: []Ep{ep(0, 5, 5)}, Alt: []Ep{ep(NoSeason, 12, 12)}}, + answers{seasoned: true, episode: 5, numbered: true, shape: ShapeEpisode}, + }, + // the same episode twice + { + "Show.S11E11-GRP/Show.S11E11-GRP.mkv", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{11}, Episodes: []Ep{ep(11, 11, 11)}}, + answers{season: 11, seasoned: true, episode: 11, numbered: true, shape: ShapeEpisode}, + }, + // a date where an episode would stand + { + "Show.2024.03.11.1080p.WEB.h264-GRP", + Numbering{Scheme: SchemeDaily}, + answers{shape: ShapeDaily}, + }, + { + "Show.2024.05.06.Title.Season.1.1080p.WEB.h264-GRP", + Numbering{Scheme: SchemeDaily, Seasons: []int{1}}, + answers{season: 1, seasoned: true, shape: ShapeDaily}, + }, + // a date beside an episode + { + "Show.S01E05.2024.03.11.1080p.WEB.h264-GRP", + Numbering{Scheme: SchemeSeasoned, Seasons: []int{1}, Episodes: []Ep{ep(1, 5, 5)}}, + answers{season: 1, seasoned: true, episode: 5, numbered: true, shape: ShapeEpisode}, + }, + // no numbering + {"Movie.2020.1080p.BluRay.x264-GRP", Numbering{}, answers{}}, + {"Artist_Name-Album_Title-2CD-FLAC-2020-GRP", Numbering{}, answers{}}, + } + for _, test := range tests { + r := ParseString(test.name) + n := r.Numbering + if !reflect.DeepEqual(n, test.exp) { + t.Errorf("%q: expected %+v, got: %+v", test.name, test.exp, n) + } + var got answers + got.season, got.seasoned = n.Season() + got.episode, got.numbered = n.Episode() + got.absolute, got.abs = n.Absolute() + if got.shape = n.Shape(); got != test.ans { + t.Errorf("%q: expected %+v, got: %+v", test.name, test.ans, got) + } + checkNumbering(t, test.name, r) + } + // a dated name is a daily episode by its type: the type a caller gives + // says whether the date stands for an episode + const dated = "Show.2024.03.11.1080p.WEB.h264-GRP" + for typ, exp := range map[Type]Scheme{Unknown: SchemeDaily, Episode: SchemeDaily, Movie: SchemeNone, Series: SchemeNone} { + if n := ParseStringHint(dated, Hint{Type: typ}).Numbering; n.Scheme != exp { + t.Errorf("%q as %q: expected scheme %q, got: %q", dated, typ, exp, n.Scheme) + } + } +} + +// TestNumberingNames checks the names of the schemes, the shapes and the +// kinds, which a caller prints and logs. +func TestNumberingNames(t *testing.T) { + for _, test := range []struct { + v fmt.Stringer + exp string + }{ + {SchemeNone, ""}, {SchemeSeasoned, "seasoned"}, {SchemeAbsolute, "absolute"}, {SchemeDaily, "daily"}, {Scheme(99), ""}, + {ShapeNone, ""}, {ShapeEpisode, "episode"}, {ShapeEpisodes, "episodes"}, {ShapeSeason, "season"}, {ShapeSeasons, "seasons"}, {ShapeDaily, "daily"}, {Shape(99), ""}, + {EpRegular, ""}, {EpSpecial, "special"}, {EpOVA, "ova"}, {EpOP, "op"}, {EpED, "ed"}, {EpPV, "pv"}, {EpKind(99), ""}, + } { + if s := test.v.String(); s != test.exp { + t.Errorf("%T(%d): expected %q, got: %q", test.v, test.v, test.exp, s) + } + } +} + +// TestNumberingAll checks the order All yields in, that it stops when asked +// to, and that it yields the two ends of a range it has no room to fill. +func TestNumberingAll(t *testing.T) { + n := ParseString("[Grp] Show - S04E29-E31 (WEB 1080p) | Other Name - E88 - S00E36").Numbering + var got [][]int + for season, episode := range n.All() { + got = append(got, []int{season, episode}) + } + if exp := [][]int{{4, 29}, {4, 30}, {4, 31}, {4, 88}, {0, 36}}; !slices.EqualFunc(got, exp, slices.Equal[[]int]) { + t.Errorf("expected %v in the order of the name, got: %v", exp, got) + } + got = nil + for season, episode := range n.All() { + if got = append(got, []int{season, episode}); len(got) == 2 { + break + } + } + if len(got) != 2 { + t.Errorf("expected All to stop after two, got: %v", got) + } + // the room is shared by the ranges of a numbering, in their order + wide := Numbering{Episodes: []Ep{ep(1, 1, 9000), ep(1, 9001, 12000), ep(2, 1, 3), ep(NoSeason, 7, 7)}} + count := map[int]int{} + for season := range wide.All() { + count[season]++ + } + if exp := map[int]int{1: 9000 + 2, 2: 3, NoSeason: 1}; !reflect.DeepEqual(count, exp) { + t.Errorf("expected the episodes per season %v, got: %v", exp, count) + } + // an extra yields nothing + got = nil + for season, episode := range (Numbering{Episodes: []Ep{{Season: 1, First: 1, Last: 9, Kind: EpOVA}, ep(1, 5, 6), {Season: 1, First: 2, Last: 2, Kind: EpSpecial}}}).All() { + got = append(got, []int{season, episode}) + } + if exp := [][]int{{1, 5}, {1, 6}}; !slices.EqualFunc(got, exp, slices.Equal[[]int]) { + t.Errorf("expected %v, got: %v", exp, got) + } +} + +// TestNumberingAllAnyValue checks that All ends on a value no parse made, as +// one decoded from a stored release may be: it yields no more than the two +// ends of each Ep and maxRangeFill episodes beside them, whatever the numbers. +// An Ep whose Last is not above its First yields its First, and a number +// below 0 is yielded as it is. +func TestNumberingAllAnyValue(t *testing.T) { + const lo, hi = math.MinInt, math.MaxInt + for _, test := range []struct { + name string + eps []Ep + // the pairs when they are few, and else how many there are + exp [][]int + count int + }{ + {"last below first", []Ep{ep(1, 5, 3)}, [][]int{{1, 5}}, 0}, + {"below zero", []Ep{ep(-7, -3, -1)}, [][]int{{-7, -3}, {-7, -2}, {-7, -1}}, 0}, + {"from below zero to the highest", []Ep{ep(1, -2, hi)}, [][]int{{1, -2}, {1, hi}}, 0}, + {"from the lowest to the highest", []Ep{ep(1, lo, hi)}, [][]int{{1, lo}, {1, hi}}, 0}, + {"the two highest", []Ep{ep(1, hi-1, hi)}, [][]int{{1, hi - 1}, {1, hi}}, 0}, + {"the highest three", []Ep{ep(1, hi-2, hi)}, [][]int{{1, hi - 2}, {1, hi - 1}, {1, hi}}, 0}, + {"the lowest three", []Ep{ep(1, lo, lo+2)}, [][]int{{1, lo}, {1, lo + 1}, {1, lo + 2}}, 0}, + {"the highest alone", []Ep{ep(NoSeason, hi, hi)}, [][]int{{NoSeason, hi}}, 0}, + {"the highest down to the lowest", []Ep{ep(1, hi, lo)}, [][]int{{1, hi}}, 0}, + // a range that fits is filled, and the one after it has what is left + {"as wide as the room", []Ep{ep(1, 0, maxRangeFill+1)}, nil, maxRangeFill + 2}, + {"one wider than the room", []Ep{ep(1, 0, maxRangeFill+2)}, [][]int{{1, 0}, {1, maxRangeFill + 2}}, 0}, + {"the room used up", []Ep{ep(1, -5000, 5001), ep(2, lo, hi), ep(3, 1, 3), ep(3, 7, 8)}, nil, maxRangeFill + 2 + 2 + 2 + 2}, + // the first range of 9,000 is filled, and the others are their ends + {"many wide ranges", slices.Repeat([]Ep{ep(1, -2, hi), ep(2, lo, 0), ep(3, 1, 9000)}, 100), nil, 100*6 + 8998}, + } { + n := Numbering{Episodes: test.eps} + var got [][]int + var count int + for season, episode := range n.All() { + if count++; count > 4*maxRangeFill { + break + } + if test.exp != nil { + got = append(got, []int{season, episode}) + } + } + switch { + case test.exp != nil && !slices.EqualFunc(got, test.exp, slices.Equal[[]int]): + t.Errorf("%s: expected %v, got: %v", test.name, test.exp, got) + case test.exp == nil && count != test.count: + t.Errorf("%s: expected %d pairs, got: %d", test.name, test.count, count) + } + // the other methods read such a value too + _, _ = n.Season() + _, _ = n.Episode() + _, _ = n.Absolute() + _ = n.Shape() + } +} + +// checkNumbering checks what holds for the Numbering of every parsed release, +// whatever the name: the fields agree with each other and with the series +// tags, and each method gives what the fields say. +func checkNumbering(tb testing.TB, name string, r Release) { + tb.Helper() + n := r.Numbering + fail := func(format string, args ...any) { + tb.Helper() + tb.Errorf("%.200q: %s\n %+v", name, fmt.Sprintf(format, args...), n) + } + // the fields + for _, list := range [][]Ep{n.Episodes, n.Alt} { + for i, e := range list { + switch { + case e.First < 0 || e.First > e.Last: + fail("expected an episode from First up to Last, got: %+v", e) + case e.Season != NoSeason && e.Season < 0: + fail("expected a season or NoSeason, got: %+v", e) + case e.Kind != EpRegular || e.Frac > 99 || e.Frac != 0 && e.Frac%10 == 0: + fail("expected a regular episode with a fraction of two digits at most and no zero at its end, got: %+v", e) + case e.Season != NoSeason && !slices.Contains(n.Seasons, e.Season): + fail("expected the season of %+v in Seasons", e) + case slices.Contains(list[:i], e): + fail("expected %+v once", e) + } + } + if list != nil && (len(list) == 0 || cap(list) != len(list)) { + fail("expected nil for no episodes and no room to spare, got: %d of %d", len(list), cap(list)) + } + } + for i, season := range n.Seasons { + if season < 0 || slices.Contains(n.Seasons[:i], season) { + fail("expected each season once, got: %v", n.Seasons) + } + } + if n.Seasons != nil && (len(n.Seasons) == 0 || cap(n.Seasons) != len(n.Seasons)) { + fail("expected nil for no seasons and no room to spare, got: %d of %d", len(n.Seasons), cap(n.Seasons)) + } + if slices.ContainsFunc(n.Alt, func(e Ep) bool { return e.Season != NoSeason }) || n.Alt != nil && (n.Episodes == nil || n.Seasons == nil) { + fail("expected a second numbering with no season, beside a season and an episode") + } + if n.Volume != 0 || n.Contents != nil || n.Batch { + fail("expected no volume, contents or batch") + } + daily := n.Episodes == nil && r.Type == Episode && r.Year != 0 && r.Month != 0 && r.Day != 0 + scheme := SchemeNone + switch { + case daily: + scheme = SchemeDaily + case n.Seasons != nil: + scheme = SchemeSeasoned + case n.Episodes != nil: + scheme = SchemeAbsolute + } + if n.Scheme != scheme { + fail("expected scheme %q, got: %q", scheme, n.Scheme) + } + // the tags + var seasons, episodes bool + for _, tag := range r.tags { + if !tag.Is(TagTypeSeries) { + continue + } + if tag.val(1) != "" { + if seasons = true; !slices.Contains(n.Seasons, atoi(tag.val(1))) { + fail("expected the season of the tag %q in Seasons", tag.val(0)) + } + } + episodes = episodes || tag.wroteEpisode() + } + if seasons != (n.Seasons != nil) || episodes != (n.Episodes != nil) { + fail("expected seasons %t and episodes %t by the tags", seasons, episodes) + } + if again, _ := r.numbering(); !reflect.DeepEqual(again, Numbering{Scheme: again.Scheme, Seasons: n.Seasons, Episodes: n.Episodes, Alt: n.Alt}) { + fail("expected the tags to give the same numbering again, got: %+v", again) + } + // the methods + season, seasoned := n.Season() + if seasoned != (n.Seasons != nil) || seasoned && season != n.Seasons[0] || !seasoned && season != 0 { + fail("expected Season to give the first of Seasons, got: %d %t", season, seasoned) + } + episode, numbered := n.Episode() + if numbered != (n.Episodes != nil) || numbered && episode != n.Episodes[0].First || !numbered && episode != 0 { + fail("expected Episode to give the First of the first episode, got: %d %t", episode, numbered) + } + shape := ShapeNone + switch { + case len(n.Episodes) == 1 && n.Episodes[0].First == n.Episodes[0].Last: + shape = ShapeEpisode + case n.Episodes != nil: + shape = ShapeEpisodes + case daily: + shape = ShapeDaily + case len(n.Seasons) == 1: + shape = ShapeSeason + case n.Seasons != nil: + shape = ShapeSeasons + } + if n.Shape() != shape { + fail("expected shape %q, got: %q", shape, n.Shape()) + } + // All yields the episodes of each Ep in turn: its First, then all the + // episodes inside a range or none of them, and the Last of a range + var all [][2]int + for season, episode := range n.All() { + all = append(all, [2]int{season, episode}) + } + var k, filled int + for _, e := range n.Episodes { + if k == len(all) || all[k] != [2]int{e.Season, e.First} { + fail("expected All to yield the First of %+v as pair %d, got: %v", e, k, all[min(k, len(all)):min(k+1, len(all))]) + break + } + if k++; e.First == e.Last { + continue + } + if inside := e.Last - e.First - 1; inside > 0 && k < len(all) && all[k] == [2]int{e.Season, e.First + 1} { + for episode := e.First + 1; episode < e.Last && k < len(all) && all[k] == [2]int{e.Season, episode}; episode++ { + k, filled = k+1, filled+1 + } + } + if k == len(all) || all[k] != [2]int{e.Season, e.Last} { + fail("expected All to yield the Last of %+v as pair %d, got: %v", e, k, all[min(k, len(all)):min(k+1, len(all))]) + break + } + k++ + } + if k != len(all) || filled > maxRangeFill { + fail("expected All to yield the episodes and no more, and to fill at most %d, got: %d pairs, %d read and %d filled", maxRangeFill, len(all), k, filled) + } + // an absolute episode is one whole episode: the one episode of a name + // with no season anywhere, which Episode gives too, and else a second + // numbering that is not the season's episode again + absolute, ok := n.Absolute() + one := func(e Ep) bool { return e.First == absolute && e.Last == absolute && e.Frac == 0 } + switch { + case !ok && absolute != 0: + fail("expected no number with no absolute episode, got: %d", absolute) + case !ok: + case !seasoned && (len(n.Episodes) != 1 || !one(n.Episodes[0]) || absolute != episode): + fail("expected the absolute episode %d to be the one episode", absolute) + case seasoned && (season == 0 || absolute == episode || !slices.ContainsFunc(n.Alt, one)): + fail("expected the absolute episode %d to be a second numbering, and not of the specials or the episode again", absolute) + } +} + +// TestNumberingInvariants checks checkNumbering on every name there is: those +// of tests.yaml, of the labelled fixtures and of the corpora that are present. +func TestNumberingInvariants(t *testing.T) { + names := slices.Concat(benchCorpus(t), scratchNames()) + for _, file := range []string{"anitomy.json", "anitogo.json", "nyaa-400.json", "nyaa-blind-140.json", "probes-title.json", "probes-title-end.json"} { + for _, c := range loadLabelled(t, file) { + names = append(names, c.FileName) + } + } + if !testing.Short() { + for _, file := range []string{"nyaa.txt", "sports.txt"} { + v, _ := readCorpus(file) + names = append(names, v...) + } + } + shapes := map[Shape]int{} + for _, name := range names { + r := ParseString(name) + checkNumbering(t, name, r) + shapes[r.Numbering.Shape()]++ + } + t.Logf("%d names: %v", len(names), shapes) +} + +// TestNumberingLinear checks that the time to parse a name grows with its +// length and not with the square of it, for names that are all numbering. A +// name is untrusted input, and the numbering is read on every parse. Each +// shape is parsed at two lengths, one eight times the other, and the longer +// may take 24 times as long: a walk over the name for every series tag takes +// 64. +func TestNumberingLinear(t *testing.T) { + clock := func(s string) time.Duration { + best := time.Duration(1<<63 - 1) + for range 5 { + start := time.Now() + ParseString(s) + best = min(best, time.Since(start)) + } + return best + } + for _, unit := range []string{ + // a range that is a word of the title, and the episodes + "Title 17-26 - 01 ~ 08 ", + // seasons with their episodes, the same and different ones + "S01E01.", + "S01E01.S02E02.", + // ranges between two tags and inside one + "E01-E02.", + "01 ~ 12 ", + // a list of seasons + "Season 1+2+", + // episodes with no season, and second numberings + "[Grp] Show - 05 ", + "- 05 ", + "- 05v2 ", + "Episode 5 ", + "S23E19.Episode.1174.", + "S01E01.S02E02.Episode.3.", + // a season in front of the episode, and seasons with a range beside + "S2 - 04 ", + "2nd Season - 08 ", + "Season 1-4 (1-76) ", + } { + short := clock(strings.Repeat(unit, 1000)) + long := clock(strings.Repeat(unit, 8000)) + if long > 24*short { + t.Errorf("8000 of %q took %s and 1000 took %s, more than 24 times as long", unit, long, short) + } + } +} + +// TestNumberingParseAllocs keeps what the numbering adds to a parse to what a +// release holds on to: nothing for a name with no numbering, and one +// allocation for its seasons, its episodes and its second numbering each. +func TestNumberingParseAllocs(t *testing.T) { + for _, test := range []struct { + name string + max float64 + }{ + {"Movie.Title.2019.1080p.WEB-DL.DDP5.1.H.264-GRP", 0}, + {"Show.Title.2024.03.11.1080p.WEB-DL.H.264-GRP", 0}, + {"Show.Title.S01.1080p.WEB-DL.H.264-GRP", 1}, + {"[SubsPlease] Show Title - 05 (1080p) [ABCD1234].mkv", 1}, + {"[SubsPlease] Show Title (01-12) (1080p) [Batch]", 1}, + {"Show.Title.S01E02.The.Episode.1080p.WEB-DL.DDP5.1.H.264-GRP", 2}, + {"Show.Title.S01E02-E04.1080p.WEB-DL.H.264-GRP", 2}, + {"Show.Title.S23E19.Episode.1174.1080p.WEB-DL.H.264-GRP", 3}, + } { + r := ParseString(test.name) + if n := testing.AllocsPerRun(100, func() { _, _ = r.numbering() }); n > test.max { + t.Errorf("%q: expected at most %v allocations for the numbering, got: %v", test.name, test.max, n) + } + } +} + +// TestEventNumbering checks what Event reads of the numbering of a name that +// starts with a competition: an episode with no season makes it a show about +// the sport, and the range of a batch does not. +func TestEventNumbering(t *testing.T) { + for _, test := range []struct { + name string + exp bool + }{ + {"UFC.300.Prelims.1080p.WEB.h264-GRP", true}, + {"WWE.Unreal.E02.1080p.WEB.h264-GRP", false}, + {"UFC.Countdown.E05.720p.HDTV.x264-GRP", false}, + {"UFC.2024.E01-E03.Qualifying.1080p.WEB.h264-GRP", false}, + {"UFC.2024.(01-05).Qualifying.1080p.WEB.h264-GRP", true}, + } { + if ev, ok := ParseString(test.name).Event(); ok != test.exp { + t.Errorf("%q: expected an event %t, got: %+v %t", test.name, test.exp, ev, ok) + } + } + // a release made by hand has the episode it was given + r := Release{Type: Episode, Title: "UFC 300", Subtitle: "Prelims"} + if _, ok := r.Event(); !ok { + t.Errorf("expected an event with no numbering") + } + r.Numbering = Numbering{Scheme: SchemeAbsolute, Episodes: []Ep{ep(NoSeason, 5, 5)}} + if ev, ok := r.Event(); ok { + t.Errorf("expected no event with an episode and no season, got: %+v", ev) + } + // the range of a batch is no episode, and neither is an extra + for _, n := range []Numbering{ + {Scheme: SchemeAbsolute, Episodes: []Ep{ep(NoSeason, 1, 3)}}, + {Episodes: []Ep{{Season: NoSeason, First: 2, Last: 2, Kind: EpOVA}}}, + {Episodes: []Ep{ep(NoSeason, 0, 0)}}, + } { + if r.Numbering = n; !func() bool { _, ok := r.Event(); return ok }() { + t.Errorf("expected an event with %+v", n) + } } - // by hand over a parsed season pack, which HasEpisode counts too - r := ParseString("Show.S01.1080p.WEB.h264-GRP") - r.Episode = 4 - if v := r.EpisodeSpans(); !slices.Equal(v, []EpisodeSpan{{"1", "4", ""}}) || !r.HasEpisode() { - t.Errorf("expected the episode set by hand, got: %q", v) + r.Numbering = Numbering{Scheme: SchemeSeasoned, Seasons: []int{1}, Episodes: []Ep{ep(1, 5, 5)}} + if ev, ok := r.Event(); ok { + t.Errorf("expected no event with a season and an episode, got: %+v", ev) } } diff --git a/parse.go b/parse.go index 4483a27..9df5eb5 100644 --- a/parse.go +++ b/parse.go @@ -642,6 +642,10 @@ func (b *TagBuilder) build(tags []Tag, end int, h Hint) Release { if Unknown < h.Type && h.Type <= Series { r.Type = h.Type } + // an episode with no episode written is one by its date + if r.Type == Episode && r.Numbering.Episodes == nil && r.Year != 0 && r.Month != 0 && r.Day != 0 { + r.Numbering.Scheme = SchemeDaily + } // special b.specialDate(r) // unset tags @@ -915,25 +919,9 @@ func appendOnce(v []string, s string) []string { // collect collects tags into the release. func (b *TagBuilder) collect(r *Release) { - // bareEp is whether an episode was written with no season, ie the '04' in - // 'Show - 04 (1080p)', 'Show E04' or 'Show Episode 04', and bare the first - // such episode. season is whether a season was written anywhere in the - // name, as a number ('S02E04', '2nd Season') or as the specials ('S00E04') - // seasoned is whether a tag before the one at hand wrote a season - // secondEp is whether one episode was written as a second numbering, ie - // the '1174' of 'S23E19.Episode.1174' or of '1174 (S23E19)', and second - // the first such episode - var bareEp, season, seasoned, secondEp bool - var bare, second int + // the series tags, which are read together + r.Numbering, r.numbered = r.numbering() for i := 0; i < len(r.tags); i++ { - // the first one that is not 0, as Episode is - if (!bareEp || bare == 0) && bareEpisode(r.tags, i) { - bareEp, bare = true, atoi(r.tags[i].v[2]) - } - if !secondEp && bareEpisode(r.tags, i) && r.secondNumbering(i) { - secondEp, second = true, atoi(r.tags[i].v[2]) - } - season = season || r.tags[i].Is(TagTypeSeries) && r.tags[i].v[1] != "" switch r.tags[i].typ { case TagTypeText: case TagTypePlatform: @@ -959,17 +947,6 @@ func (b *TagBuilder) collect(r *Release) { case TagTypeDate: r.Year, r.Month, r.Day = r.tags[i].Date() r.YearEnd = r.tags[i].yearEnd() - case TagTypeSeries: - // the first season the name writes, which season 0 is - series, episode := r.tags[i].Series() - if !seasoned { - r.Series, seasoned = series, r.tags[i].v[1] != "" - } - // the episode is the season's, wherever a second numbering is - // written ('1174 (S23E19)' is episode 19) - if r.Episode == 0 && !r.secondNumbering(i) { - r.Episode = episode - } case TagTypeVersion: if r.Version == "" { r.Version = r.tags[i].Version() @@ -1041,18 +1018,6 @@ func (b *TagBuilder) collect(r *Release) { r.Ext = r.tags[i].Ext() } } - // a bare number is an absolute episode when nothing qualified it: a season - // marker anywhere makes it season relative by fansub convention ('Hell - // Mode S2 - 04' is episode 4 of season 2, not absolute 4). Beside a season - // and an episode it is a second numbering, and absolute unless it writes - // the season's episode again ('S02E06 [Episode 6]') or the season is the - // specials ('S00E05.Episode.12'). - switch { - case bareEp && !season: - r.absolute, r.isAbsolute = bare, true - case secondEp && r.Series != 0 && second != r.Episode: - r.absolute, r.isAbsolute = second, true - } // collect year, month, day from unset date tags for i := len(r.dates); i > 0; i-- { year, month, day := r.tags[r.dates[i-1]].Date() @@ -1075,15 +1040,20 @@ func (b *TagBuilder) inspect(r *Release, initial bool) Type { } n := len(r.tags) // inspect types - // episode is whether an episode was written, which r.Episode cannot say - // for episode 0 ('Show - 00', 'S01E00') - // season is whether a season other than 0 was written, which r.Series - // cannot say when season 0 is written first ('S00E02 (S02E00)') + // series is whether the name has a series tag + // season is whether a season other than 0 was written + // episode is whether a tag writes an episode in its first place, which + // the range of a batch does not ('01-12'): 'S01E01-E03' is an episode + // and '[Grp] Show - 01-12' a series. r.numbered is whether such an + // episode is not 0, a second numbering aside ('S00E00.Episode.12' has + // none) var app, series, season, episode, movie, video bool for _, tag := range r.tags { - series = series || tag.Is(TagTypeSeries) - season = season || tag.Is(TagTypeSeries) && len(tag.v) > 1 && atoi(tag.v[1]) != 0 - episode = episode || tag.Is(TagTypeSeries) && len(tag.v) > 2 && tag.v[2] != "" + if tag.Is(TagTypeSeries) { + series = true + season = season || atoi(tag.val(1)) != 0 + episode = episode || tag.val(2) != "" + } video = video || (!tag.Is(TagTypeGroup) && tag.InfoType() == Movie) } for i := n; i > 0; i-- { @@ -1103,12 +1073,12 @@ func (b *TagBuilder) inspect(r *Release, initial bool) Type { } return typ case Series, Episode: - if r.Episode != 0 || episode || (r.Series == 0 && r.Episode == 0 && !series) && !slices.Contains(r.Other, "BOXSET") { + if episode || !series && !slices.Contains(r.Other, "BOXSET") { return Episode } return Series case Education: - if !season && r.Episode == 0 { + if !season && !r.numbered { return Education } case Music: @@ -1147,7 +1117,7 @@ func (b *TagBuilder) inspect(r *Release, initial bool) Type { // exclusive tag not superseded by version/episode/date if r.tags[i-1].InfoExcl() && r.Version == "" && - !season && r.Episode == 0 && + !season && !r.numbered && r.Day == 0 && r.Month == 0 { return typ } @@ -1175,9 +1145,9 @@ func (b *TagBuilder) inspect(r *Release, initial bool) Type { } // defaults switch { - case r.Episode != 0 || episode || (r.Year != 0 && r.Month != 0 && r.Day != 0): + case episode || (r.Year != 0 && r.Month != 0 && r.Day != 0): return Episode - case r.Series != 0 || series: + case series: return Series case app || (r.Version != "" && r.Resolution == "" && !movie): return App diff --git a/rls.go b/rls.go index c19f126..05f431f 100644 --- a/rls.go +++ b/rls.go @@ -53,10 +53,10 @@ type Release struct { // ('2014-2015', '2024-25', '1999-2003'), and Year is the first. YearEnd int - Series int - Episode int - Version string - Disc string + // Numbering is the seasons and the episodes the name gives. + Numbering Numbering + Version string + Disc string Codec []string HDR []string @@ -87,17 +87,18 @@ type Release struct { // path is whether the name is a file path, which isPath reports. path bool + // numbered is whether a tag that is no second numbering writes an episode + // other than 0 in its first place, which the range of a batch does not + // ('01-12'). The type is read by it, and Event tells a show from an event + // by it. + numbered bool + // groupFrom is where Group was read. + groupFrom groupOrigin tags []Tag dates []int unused []int end int - // absolute is the episode Absolute returns, and isAbsolute whether there - // is one. - absolute int - isAbsolute bool - // groupFrom is where Group was read. - groupFrom groupOrigin } // Parse creates a release from src. @@ -190,166 +191,41 @@ func (r Release) Tags() []Tag { // 'E1-E99999.E1-E99999...' from growing into millions of episodes. const maxRangeFill = 10000 -// SeriesEpisodes returns all series and episodes. The episodes inside a range -// are included, up to maxRangeFill of them. A written episode 0 is an episode -// ('S01E00', '[Grp] Show - 00-12'), and a season with no episode gives no -// pair ('S01'). As in EpisodeRange, an episode that is a second numbering -// gives no pair of its own, so 'S02E01.Episode.1' and 'S23E19.Episode.1174' -// each give one pair. An episode written twice gives one pair -// ('S11E11-GRP/S11E11-GRP.mkv'). -func (r Release) SeriesEpisodes() [][]int { - var v [][]int - last, fill, none := -1, maxRangeFill, 0 - for i, tag := range r.tags { - if !tag.Is(TagTypeSeries) || r.secondNumbering(i) { - continue - } - series, _ := tag.Series() - // a tag that writes no season is in the season written before it, - // which a written season 0 is not ('S04E29 ... S00E36') - bare := tag.val(1) == "" - for k, episode := range tag.episodes(&fill) { - s := series - if bare && last != -1 { - s, _ = r.tags[last].Series() - } - // a hyphen or a tilde between two episode tags of one season - // makes a range ('E02-E04', 'S00E02-S00E04', 'E29~E31'), which - // runs from the last episode of the tag before it, unless that - // tag is a second numbering ('S01E01.Episode.5-E07') - if k == 0 && i >= 2 && r.tags[i-2].Is(TagTypeSeries) && !r.secondNumbering(i-2) && (bare || tag.val(1) == r.tags[i-2].val(1)) && r.tags[i-1].rangeDelim() { - if prev := r.tags[i-2].episodes(&none); len(prev) != 0 { - if first := prev[len(prev)-1] + 1; episode-first <= fill { - for j := first; j < episode; j++ { - v = append(v, []int{s, j}) - } - fill -= max(episode-first, 0) - } - } - } - v = append(v, []int{s, episode}) - } - if !bare { - // an episode after a range or a list of seasons is in none of - // them - if last = i; r.seasonRange(i) != -1 || r.seasonList(i) != -1 { - last = -1 - } - } - } - slices.SortFunc(v, func(a, b []int) int { - return cmp.Or(cmp.Compare(a[0], b[0]), cmp.Compare(a[1], b[1])) - }) - - return slices.CompactFunc(v, slices.Equal[[]int]) -} - -// secondNumbering reports whether the series tag at i writes an episode -// without a season that numbers an episode of the name a second way, ie the -// 'Episode.1174' of 'S23E19.Episode.1174' and the '1174' of '1174 (S23E19)'. -// The episode is in the season written nearest before it, and is a second -// numbering when the name writes that season's episode too: the '13' of 'S2 - -// 13 (S02E01)' is, and the 'Episode.2' of 'S01E01.S02.Episode.2' is episode 2 -// of season 2. With no season before it, any season written with an episode -// makes it one. An 'E06' continuation is another episode, and not one. -func (r Release) secondNumbering(i int) bool { - tag := r.tags[i] - if tag.typ != TagTypeSeries || tag.val(1) != "" || tag.continuation() { - return false - } - season := "" - for j := i - 1; j >= 0 && season == ""; j-- { - if r.tags[j].typ == TagTypeSeries { - season = r.tags[j].val(1) - } - } - for _, t := range r.tags { - if t.typ == TagTypeSeries && t.val(1) != "" && t.wroteEpisode() && (season == "" || atoi(t.val(1)) == atoi(season)) { - return true - } - } - return false -} - -// Absolute returns the episode when the name numbers its episodes absolutely -// and not within a season, ie '[Group] One Piece - 1169'. Episode carries the -// same number. What Absolute adds is that no season qualifies it, so it is not -// comparable against a season's episode without an external mapping (AniDB, -// anime-relations, TheTVDB). ok is false for a season relative number ('Hell -// Mode S2 - 04') and for a special ('Show.S00E05'), both of which are already -// qualified. A written episode 0 is absolute like any other: '[Group] Show - -// 00' gives 0 and true, and a name with no episode 0 and false. +// rangeEnd reports whether the series tag at i writes the end of a range that +// the series tag before it starts, ie the '31' of 'S04E29-31v2'. The series +// lexer reads 'S04E29-31' as one tag, and leaves the '31' to the next tag when +// a version follows it. The tag at i is a bare number, a bare hyphen or tilde +// stands between the two, the tag before writes a season and an episode, and +// the number at i is higher than the last episode it writes. // -// A name may write the absolute episode beside the season and episode, as a -// second numbering ('S23E19.Episode.1174', '[Group] One Piece - 1174 -// (S23E19)'). Absolute then gives it, 1174 and true, and Episode is the -// season's episode, 19. The season's episode written again is no absolute -// number ('S02E06 [Episode 6]'). -func (r Release) Absolute() (episode int, ok bool) { - return r.absolute, r.isAbsolute -} - -// HasSeason reports whether the name gives a season, which season 0 is -// ('S00E05'). The Series field cannot tell a season 0 from none, and -// HasSeason answers from the tags. A Release built by hand with a Series has -// a season too. -func (r Release) HasSeason() bool { - if r.Series != 0 { - return true - } - for _, tag := range r.tags { - if tag.typ == TagTypeSeries && tag.val(1) != "" { - return true - } +// As in the lexer, four digits after a lower episode are a year or another +// number and not the end of a range ('S23E19-1174v2', 'S01E05-2020v2'), unless +// the episodes are numbered that high ('S01E998-1002v2'). An episode written +// with a word numbers the episode a second way, as it does after a dot +// ('S01E05-Episode.10'). +func (r Release) rangeEnd(i int) bool { + if i < 2 || !r.tags[i-1].rangeDelim() { + return false } - return false -} - -// HasEpisode reports whether the name gives an episode, which episode 0 and -// the episodes of a range are. So 'S01E00', '[Grp] Show - 00' and the batch -// '[Grp] Show - 01-12' have an episode though Episode is 0, and the season -// pack 'Show.S01' has none. -func (r Release) HasEpisode() bool { - if r.Episode != 0 { - return true + tag, prev := r.tags[i], r.tags[i-2] + if prev.typ != TagTypeSeries || prev.val(1) == "" { + return false } - for _, tag := range r.tags { - if tag.typ == TagTypeSeries && tag.wroteEpisode() { - return true - } + if s := tag.val(0); s == "" || s[0] < '0' || s[0] > '9' { + return false } - return false -} - -// Seasons returns the seasons the name gives, each once and in order. Two -// seasons written with no episode and a hyphen or a tilde between them are a -// range ('S01-S03', 'S01-03', 'Seasons 1~7', '(Season 1 - 3)'), and the -// seasons in between are included, up to maxRangeFill of them. The seasons of -// a list are those it writes ('S01+S02', 'Season 1+2+3', 'Seasons 1 & 2'). A -// Release built by hand with a Series and no tags gives that season. -func (r Release) Seasons() []int { - var v []int - fill := maxRangeFill - for i, tag := range r.tags { - if tag.typ != TagTypeSeries || tag.val(1) == "" { - continue - } - season := atoi(tag.val(1)) - if start := r.seasonRange(i); start != -1 { - if prev := atoi(r.tags[start].val(1)); season-prev-1 <= fill { - for j := prev + 1; j < season; j++ { - v = append(v, j) - } - fill -= season - prev - 1 - } + var start string + for _, b := range prev.rest(2) { + if b != "" && b != "-" { + start = b } - v = append(v, season) } - if v == nil && r.Series != 0 { - return []int{r.Series} + end := tag.val(2) + first, last := atoi(start), atoi(end) + if start == "" || len(end) >= 4 && (len(start) < 3 || last-first >= 1000) { + return false } - slices.Sort(v) - return slices.Compact(v) + return first < last } // seasonRange returns the index of the series tag that starts a range of @@ -359,8 +235,7 @@ func (r Release) Seasons() []int { // ('S01-S03', 'S01-03', 'Seasons 1~7', '(Season 1 - 3)', 'S01 ~ S03'). // // An episode written after the range with no season of its own is in none of -// them, as SeriesEpisodes, EpisodeSpans and EpisodeRange have it ('Season 1-4 -// (1-76)'). +// them ('Season 1-4 (1-76)'). func (r Release) seasonRange(i int) int { tag, start := r.tags[i], -1 if tag.typ != TagTypeSeries || tag.val(1) == "" || tag.wroteEpisode() { @@ -415,130 +290,6 @@ func (r Release) seasonList(i int) int { return -1 } -// EpisodeRange returns the first and last episode when the name gives more -// than one ('S01E05E06', 'S01E02-04', '01-12'). The episodes are those of the -// first season the name gives, the one in Series: 'S01E01.S02E01' is not a -// range. An episode that is a second numbering is not counted, so -// 'S23E19.Episode.1174' is one episode under two numberings. The same episode -// written twice is one episode. The ends of a range come back however wide it -// is. -func (r Release) EpisodeRange() (first, last int, ok bool) { - // cur is the season the nearest earlier tag wrote, which an episode - // written without one is in - cur, season, found := 0, 0, false - for i, tag := range r.tags { - if tag.typ != TagTypeSeries { - continue - } - s := cur - switch { - case tag.val(1) != "": - s = atoi(tag.val(1)) - if cur = s; r.seasonRange(i) != -1 || r.seasonList(i) != -1 { - cur = 0 - } - case r.secondNumbering(i): - continue - } - for _, b := range tag.rest(2) { - if b == "" || b == "-" { - continue - } - episode := atoi(b) - switch { - case !found: - season, first, last, found = s, episode, episode, true - case s == season: - first, last = min(first, episode), max(last, episode) - } - } - } - if !found || first == last { - return 0, 0, false - } - return first, last, true -} - -// EpisodeSpan is one episode, or one range of episodes, as a name writes it. -// Season is the season the name gives for it, and empty when it gives none. -// First is the episode. Last is the end of a range, and empty for one episode. -// The numbers are the digits of the name, so a leading zero and half an -// episode are kept: '21.5', '06.5', '00'. -type EpisodeSpan struct { - Season string - First string - Last string -} - -// EpisodeSpans returns the episodes the name gives, in the order it gives -// them, with a range as its two ends. It tells half an episode from the whole -// one ('21.5' and '21' are both Episode 21) and an episode 0 from none. A -// season pack gives no span. -// -// An episode written with no season is in the season written before it, as in -// SeriesEpisodes: the '04' of 'S2 - 04'. Unlike SeriesEpisodes, a second -// numbering of the same episode is listed too ('S23E19.Episode.1174' gives -// 1174 in season 23), and an episode written twice is listed twice. A hyphen -// or a tilde inside a tag makes a range ('S01E02-04', '01 ~ 12'), and so does -// a bare hyphen or tilde between two tags of one season when the end is the -// higher number ('E02-E04', 'E29~E31'). A Release built by hand with an -// Episode and no episode in its tags gives that episode. -func (r Release) EpisodeSpans() []EpisodeSpan { - var v []EpisodeSpan - var season string - // open is whether the tag before wrote the last span, which a hyphen may - // then extend - var open bool - for i, tag := range r.tags { - if tag.typ != TagTypeSeries { - continue - } - bare := tag.val(1) == "" - if !bare { - if season = tag.val(1); r.seasonRange(i) != -1 || r.seasonList(i) != -1 { - season = "" - } - } - eps := tag.rest(2) - ranged := open && i >= 2 && r.tags[i-2].typ == TagTypeSeries && r.tags[i-1].rangeDelim() && - (bare || tag.val(1) == r.tags[i-2].val(1)) - open = false - for k, b := range eps { - switch b { - case "": - continue - case "-": - ranged = open - continue - } - // the fraction follows the last number of the tag - if k == len(eps)-1 { - b += tag.fraction() - } - if last := len(v) - 1; ranged && wholeEpisode(b) > wholeEpisode(cmp.Or(v[last].Last, v[last].First)) { - v[last].Last = b - } else { - v = append(v, EpisodeSpan{Season: season, First: b}) - } - ranged, open = false, true - } - } - if len(v) == 0 && r.Episode != 0 { - v = append(v, EpisodeSpan{First: strconv.Itoa(r.Episode)}) - if r.Series != 0 { - v[0].Season = strconv.Itoa(r.Series) - } - } - return v -} - -// wholeEpisode returns the whole number of an episode as EpisodeSpans gives -// it, ie 21 for '21.5'. -func wholeEpisode(s string) int { - s, _, _ = strings.Cut(s, ".") - return atoi(s) -} - // rangeDelim reports whether the tag is the bare hyphen or tilde that makes a // range of the episode tags on its two sides ('E02-E04', 'E29~E31'). func (tag Tag) rangeDelim() bool { @@ -1543,8 +1294,13 @@ var CompareMap = map[Type]int{ // Compare compares a to b, normalizing titles with Normalize, comparing the // resulting lower cased strings. Release types are grouped together based on -// the precedence defined in CompareMap. +// the precedence defined in CompareMap. The season and the episode compared +// are those Numbering.Season and Numbering.Episode give, with 0 for none. func Compare(a, b Release) int { + aseason, _ := a.Numbering.Season() + bseason, _ := b.Numbering.Season() + aepisode, _ := a.Numbering.Episode() + bepisode, _ := b.Numbering.Episode() var c int for _, f := range []func() int{ compareInt(CompareMap[a.Type], CompareMap[b.Type]), @@ -1553,8 +1309,8 @@ func Compare(a, b Release) int { compareInt(a.Year, b.Year), compareInt(a.Month, b.Month), compareInt(a.Day, b.Day), - compareInt(a.Series, b.Series), - compareInt(a.Episode, b.Episode), + compareInt(aseason, bseason), + compareInt(aepisode, bepisode), compareTitle(a.Subtitle, b.Subtitle), compareTitles(a.Alt, b.Alt), compareIntString(a.Resolution, b.Resolution), diff --git a/rls_test.go b/rls_test.go index 939b133..e7b8cba 100644 --- a/rls_test.go +++ b/rls_test.go @@ -63,9 +63,16 @@ func TestParseRelease(t *testing.T) { } } -// TestSeriesEpisodesRangeFill checks that the episodes inside a range are -// filled in, and that ranges too wide to fill are given by their ends. +// TestSeriesEpisodesRangeFill checks that All fills in the episodes inside a +// range, and that ranges too wide to fill are given by their ends. func TestSeriesEpisodesRangeFill(t *testing.T) { + count := func(s string) int { + var n int + for range ParseString(s).Numbering.All() { + n++ + } + return n + } for _, test := range []struct { s string exp int @@ -75,18 +82,26 @@ func TestSeriesEpisodesRangeFill(t *testing.T) { {"Show.E1-E99999.1080p.WEB-GRP", 2}, {"Show.S01.E1-E99999.1080p.WEB-GRP", 2}, } { - if n := len(ParseString(test.s).SeriesEpisodes()); n != test.exp { + if n := count(test.s); n != test.exp { t.Errorf("%q expected %d episodes, got: %d", test.s, test.exp, n) } } // every range adds its two ends, and together they fill no more than // maxRangeFill episodes - for _, s := range []string{"E1-999.", "E1-E9999.", "S01E1-999."} { - const count = 500 - if n := len(ParseString(strings.Repeat(s, count)).SeriesEpisodes()); n > maxRangeFill+2*count { - t.Errorf("%q repeated expected at most %d episodes, got: %d", s, maxRangeFill+2*count, n) + for _, s := range []string{"E1-999.", "E1-E9999.", "S01E1-999.", "E1-999.E2-999.", "S01E1-E9999.S02E1-E9999."} { + const times = 500 + if n := count(strings.Repeat(s, times)); n > maxRangeFill+2*times { + t.Errorf("%q repeated expected at most %d episodes, got: %d", s, maxRangeFill+2*times, n) } } + // ranges that differ are each an Ep, and are filled until the room is used + var s strings.Builder + for i := range 500 { + fmt.Fprintf(&s, "E%d-%d.", i+1, i+900) + } + if n := count(s.String()); n <= maxRangeFill || n > maxRangeFill+2*500 { + t.Errorf("expected ranges that differ to fill %d episodes and no more than their ends beside, got: %d", maxRangeFill, n) + } } // TestDateColon checks that a colon before two digits does not make a month. @@ -1151,13 +1166,22 @@ type rls struct { } func buildRls(r Release) rls { - absolute, _ := r.Absolute() + series, _ := r.Numbering.Season() + episode, _ := r.Numbering.Episode() + absolute, _ := r.Numbering.Absolute() req := 0 if r.Req { req = 1 } + // each season and episode once and in rising order, when there is more + // than one. An episode the name gives no season for is written S00 + var eps [][]int + for season, episode := range r.Numbering.All() { + eps = append(eps, []int{max(season, 0), episode}) + } + slices.SortFunc(eps, slices.Compare[[]int]) var seriesEpisodes []string - if eps := r.SeriesEpisodes(); len(eps) > 1 { + if eps = slices.CompactFunc(eps, slices.Equal[[]int]); len(eps) > 1 { for _, ep := range eps { seriesEpisodes = append(seriesEpisodes, fmt.Sprintf("S%02dE%02d", ep[0], ep[1])) } @@ -1184,8 +1208,8 @@ func buildRls(r Release) rls { Day: r.Day, Yearend: r.YearEnd, - Series: r.Series, - Episode: r.Episode, + Series: series, + Episode: episode, Absolute: absolute, SeriesEpisodes: strings.Join(seriesEpisodes, " "), Version: r.Version, diff --git a/tests.yaml b/tests.yaml index 02d8f6c..e880a88 100644 --- a/tests.yaml +++ b/tests.yaml @@ -4630,6 +4630,7 @@ source: "BluRay" resolution: "1080p" series: 2 + episode: 5 seriesEpisodes: "S02E05 S02E06" audio: "FLAC" group: "Coalgirls" @@ -4808,6 +4809,7 @@ title: "Re Zero Kara Hajimeru Isekai Seikatsu" resolution: "720p" series: 2 + episode: 1 seriesEpisodes: "S02E01 S02E02 S02E03 S02E04 S02E05 S02E06 S02E07 S02E08 S02E09 S02E10 S02E11 S02E12 S02E13" group: "HorribleSubs" site: "HorribleSubs" @@ -4938,6 +4940,20 @@ channels: "5.1" other: "Audio.Description" group: "NTb" +"[Judas] Shingeki no Kyojin (Attack on Titan) - S04E29-31v2 [1080p][HEVC x265 10bit][Multi-Subs] (Weekly)": + type: "episode" + title: "Shingeki no Kyojin" + resolution: "1080p" + series: 4 + episode: 29 + seriesEpisodes: "S04E29 S04E30 S04E31" + version: "v2" + codec: "HEVC x265" + bitdepth: "10BIT" + language: "MULTiSUB" + group: "Judas" + site: "Judas" + unused: "Attack on Titan Weekly" "Show - 01 (1080p@59.94fps)": type: "episode" title: "Show" @@ -5906,6 +5922,7 @@ type: "series" title: "Show Name" resolution: "1080p" + episode: 1 seriesEpisodes: "S00E01 S00E02 S00E03 S00E04 S00E05 S00E06 S00E07 S00E08 S00E09 S00E10 S00E11 S00E12" group: "Group" site: "Group" @@ -5914,6 +5931,7 @@ type: "series" title: "Show Name" resolution: "1080p" + episode: 1 seriesEpisodes: "S00E01 S00E02 S00E03 S00E04 S00E05 S00E06 S00E07 S00E08 S00E09 S00E10 S00E11 S00E12" group: "Group" site: "Group" @@ -5923,29 +5941,13 @@ title: "Show Name" resolution: "1080p" collection: "AT-X" + episode: 1 seriesEpisodes: "S00E01 S00E02 S00E03 S00E04 S00E05 S00E06 S00E07 S00E08 S00E09 S00E10 S00E11 S00E12" codec: "MPEG-2" audio: "AAC" group: "Group" site: "Group" ext: "ts" -"[Group] Show Name - 24-48 [BD 1080p FLAC]": - type: "series" - title: "Show Name" - source: "BluRay" - resolution: "1080p" - seriesEpisodes: "S00E24 S00E25 S00E26 S00E27 S00E28 S00E29 S00E30 S00E31 S00E32 S00E33 S00E34 S00E35 S00E36 S00E37 S00E38 S00E39 S00E40 S00E41 S00E42 S00E43 S00E44 S00E45 S00E46 S00E47 S00E48" - audio: "FLAC" - group: "Group" - site: "Group" -"[Group] Show Name 10-12 [BD 1080p]": - type: "series" - title: "Show Name" - source: "BluRay" - resolution: "1080p" - seriesEpisodes: "S00E10 S00E11 S00E12" - group: "Group" - site: "Group" "[Group] Show Name - 05 (JA) [720p]": type: "episode" title: "Show Name" @@ -5976,6 +5978,15 @@ group: "Mori+Leopard-Raws" site: "Mori+Leopard-Raws" ext: "mkv" +"[Group] Show Name 10-12 [BD 1080p]": + type: "series" + title: "Show Name" + source: "BluRay" + resolution: "1080p" + episode: 10 + seriesEpisodes: "S00E10 S00E11 S00E12" + group: "Group" + site: "Group" "[Group] Show Name - 24 (JA) [720p WEB-DL AVC AAC]": type: "episode" title: "Show Name" @@ -5988,6 +5999,16 @@ group: "Group" site: "Group" unused: "JA" +"[Group] Show Name - 24-48 [BD 1080p FLAC]": + type: "series" + title: "Show Name" + source: "BluRay" + resolution: "1080p" + episode: 24 + seriesEpisodes: "S00E24 S00E25 S00E26 S00E27 S00E28 S00E29 S00E30 S00E31 S00E32 S00E33 S00E34 S00E35 S00E36 S00E37 S00E38 S00E39 S00E40 S00E41 S00E42 S00E43 S00E44 S00E45 S00E46 S00E47 S00E48" + audio: "FLAC" + group: "Group" + site: "Group" "[Group] Show Name - S00E28 (WEB 1080p) (Show Name 2nd Season OVA)": type: "episode" title: "Show Name" @@ -6050,21 +6071,22 @@ group: "Group" site: "Group" unused: "EP : 402" -"[Group] Show Name S2 - 13~24 [BDRip 1080p]": - type: "series" +"[Group] Show Name 2nd Season - 08 [1080p]": + type: "episode" title: "Show Name" - source: "BDRiP" resolution: "1080p" series: 2 - seriesEpisodes: "S02E13 S02E14 S02E15 S02E16 S02E17 S02E18 S02E19 S02E20 S02E21 S02E22 S02E23 S02E24" + episode: 8 group: "Group" site: "Group" -"[Group] Show Name 2nd Season - 08 [1080p]": - type: "episode" +"[Group] Show Name S2 - 13~24 [BDRip 1080p]": + type: "series" title: "Show Name" + source: "BDRiP" resolution: "1080p" series: 2 - episode: 8 + episode: 13 + seriesEpisodes: "S02E13 S02E14 S02E15 S02E16 S02E17 S02E18 S02E19 S02E20 S02E21 S02E22 S02E23 S02E24" group: "Group" site: "Group" "Show Name 3rd Season (BD 1080p HEVC Opus)": @@ -6411,6 +6433,7 @@ source: "WEB-DL" resolution: "1080p" collection: "AMZN" + episode: 1 seriesEpisodes: "S00E01 S00E02 S00E03 S00E04 S00E05 S00E06 S00E07 S00E08" codec: "AVC" audio: "DDP"