Skip to content

feat(series)!: replace Series and Episode with Numbering - #77

Open
zze0s wants to merge 1 commit into
fix/dub-groupfrom
feat/numbering
Open

zze0s wants to merge 1 commit into
fix/dub-groupfrom
feat/numbering

Conversation

@zze0s

@zze0s zze0s commented Nov 18, 2026

Copy link
Copy Markdown

Description

Stacked on #76. First of two PRs for step 3: the type. The anime stage that fills the new fields follows.

A name's numbering was spread over two ints that cannot tell zero from none, Series and Episode, and seven accessors that each walk the tags their own way. qui has four different definitions of a season pack built on them, and both apps read season or episode 0 as "none". This PR replaces all of it with one value, Release.Numbering, built once per parse.

type Numbering struct {
    Scheme   Scheme   // SchemeNone, SchemeSeasoned, SchemeAbsolute, SchemeDaily
    Seasons  []int    // each season once, in the order written, a range filled in
    Episodes []Ep     // in the order of the name, a range is one Ep
    Alt      []Ep     // a second numbering: the 1174 of S23E19.Episode.1174
    Volume   int      // set by the anime stage PR
    Contents []string // set by the anime stage PR
    Batch    bool     // set by the anime stage PR
}
type Ep struct {
    Season      int    // NoSeason (-1) when the name writes none
    First, Last int    // Last == First for one episode
    Frac        uint8  // 21.5 is First 21, Frac 5
    Kind        EpKind // EpRegular here; the anime stage PR sets the others
}
func (n Numbering) Season() (int, bool)       // the first season the name writes
func (n Numbering) Episode() (int, bool)      // First of the first regular episode
func (n Numbering) Absolute() (int, bool)
func (n Numbering) Shape() Shape              // None, Episode, Episodes, Season, Seasons, Daily
func (n Numbering) All() iter.Seq2[int, int]  // season and episode, ranges filled

String() on Scheme, Shape and EpKind is the only addition beyond the shape you approved. The CLI and logs have to print them.

What a caller writes instead

removed replacement, with n := r.Numbering
r.Series season, _ := n.Season()
r.Episode episode, _ := n.Episode()
r.HasSeason() _, ok := n.Season()
r.HasEpisode() _, ok := n.Episode()
r.Seasons() n.Seasons, in the order written
r.SeriesEpisodes() for season, episode := range n.All(), with NoSeason where it gave 0
r.EpisodeRange() n.Episodes[0].First and .Last when n.Shape() == ShapeEpisodes and it is one Ep
r.EpisodeSpans(), EpisodeSpan n.Episodes and n.Alt
r.Absolute() n.Absolute()

Readings

This PR changes no reading on purpose, except where it has to. Before the old code was deleted its answers were recorded, and the new value was compared with them on every name of nine sets: tests.yaml, nyaa.txt, sports.txt, the probe sets, the labelled fixtures, 54,766 real scene names and 7,719 real German names. Type, Event(), the season, "has a season", "has an episode", the seasons and the season and episode pairs are identical on every name. What differs:

what names example
Episode() is the first episode of a range 727 [shincaps] Nige Jouzu no Wakagimi - 01-12: 0 to 1 intended, see below
S04E29-31v2 is a range 1 the name of #72 the rule of #72, carried in
Absolute() is none for a name that writes two episodes 48 Hellsing.E06.E07.UNCUT.GERMAN.2002.DVDRiP.SVCD-MB: 6 to none one rule in place of "the first bare episode that is not 0"
Absolute() for an episode with digits after a dot 3 Angela.Merkel...E01.1954.bis.1990: none to 1 follows the documented contract
Episode() when the first episode is 0 0 [Grp] Show - 00 - 05: 5 to 0 the field skipped a 0, no real name writes it
Frac drops zeros at the end 0 12.50 is the half that 12.5 is

Episode() and a batch. The removed field was 0 for [Grp] Show - 01-12 and 1 for Show.S01E01-E03. That was an artefact of how two lexers lay out their tags, and nothing in the name says it. Episode() gives the first episode in both. A caller that means "this release is one episode" asks Shape() == ShapeEpisode.

Absolute(). It is true when the name gives exactly one regular episode and no season, or a second numbering beside a seasoned episode (S23E19.Episode.1174). 21 of the 48 names that lose it are names where a title number was read as an episode (Fairy Tail - 100 Years Quest - 07 gave 100). They were wrong before, and the anime stage reads them right.

Kinds. Episode(), Shape() and All() describe regular episodes only. No parsed name has another kind yet. When the anime stage reads - OVA 02, it is an Ep with kind EpOVA in Episodes, with no Episode() and ShapeNone. That follows decision 3.

Nine episode: expectations change in tests.yaml, all the first case of the table. A script checks that each new value is the first pair of that entry's own seriesEpisodes.

Time and size

On master a long name that is all numbering is quadratic, because collect and the accessors walk the tags for every series tag. The numbering is now built in two passes.

unit, repeated to 128 KB base head
- 05 3.8 s 81 ms
S2 - 04 2.5 s 78 ms
Title 17-26 - 01 ~ 08 596 ms 38 ms
S01E01. 38.5 ms 44.6 ms

TestNumberingLinear covers 15 shapes.

unsafe.Sizeof(Release{}) goes from 752 to 840 bytes, and a kept release is 2.7 to 3.4% larger. A name with no numbering allocates nothing more. A name with it allocates one slice each for its seasons, episodes and second numbering. Benchmarks are 1.9% faster in the geometric mean.

Downstream impact on autobrr and qui

This is the largest port of the stack. I did it in local worktrees of both apps, against this branch. Nothing is pushed there.

app port tests against this branch with the port
qui develop (bc56dcac) 49 files, +803 -632 builds, vet clean, the 11 packages that depend on rls pass
autobrr develop (9edcbede) 2 files, +67 -2 builds, vet clean, the same two tests fail as against master (TestRelease_Parse/parse_7, TestRelease_Hash/23, the 1080i change since v0.10.0)
  • qui keeps season and episode as integers where 0 means none. The port puts the reads and writes behind helpers in a new pkg/releases/numbering.go: 107 production reads of Series, 70 of Episode, 18 places that set them on a copy, 108 literals in tests. hasSingleSeason and IsEpisodeRange no longer walk tags. They read len(Seasons) == 1 and Shape() == ShapeEpisodes.
  • autobrr has one production site, in internal/domain/release.go. A small helper returns what the old Episode field held, so no stored season, episode or NormalizedHash changes over 71,632 names.

Three behaviour questions come out of the port:

  1. qui, a batch with a season label. 64 names go from "season pack" to "episode range": [SubsPlease] Dr. Stone S4 (01-24) [Batch]. The old tag walk dropped the (01-24). Numbering cannot tell that name from S01E02-E04 yet. The anime stage sets Batch for it, which gives qui a way to keep it a pack.
  2. qui, "exactly one season". 493 names go from false to true, because the old code counted a season written twice as two (S02E17 ... (The Blue Orchestra Season 2)). Counting seasons and not tags looks right to me.
  3. autobrr, the episode of a batch. [Grp] Show - 01-12 stores episode 0 today, and the port keeps that. With plain Episode() it would store 1 on 727 names, their hash would change, and a filter on episode 1 would match a batch.

Other things a caller meets:

  • Seasons is in the order written, where Seasons() sorted. 13 names write their seasons out of rising order.
  • The zero Ep is episode 0 of season 0. A caller that builds one by hand for a name with no season sets Season: rls.NoSeason.
  • Event() reads an unexported flag that a parse sets, so a release decoded from JSON can answer differently for one shape: UFC 300 - E01-E03 [1080p] is a show when parsed and an event after a round trip. The doc comment says so and TestEventRoundTrip pins it.
  • Compare ranks a batch equal on episode with its first episode, where it ranked with releases that have none.
  • The CLI's episode key goes from 0 to the first episode on the 727 batch names, and it gains a numbering object. The other keys are identical on 71,636 names.

Review

An independent review compared old and new answers with its own programs over 80,013 real names and 816 generated shapes with every hint. It confirmed the table above and found, all fixed in this commit:

  • All() could run without end on a Numbering decoded from JSON with a huge range.
  • Absolute() and Episode() contradicted each other on - 00 - 05.
  • TestAccuracyLabelled counted a batch as right without checking its end. It scores both ends now, and halves. The episode floors move to anitomy 65, habari 65, anitogo 64. No row moved because a reading changed: five batches and three half episodes count as right that the old scorer could not read, and four batches of which the parser reads only the first episode no longer count.

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How has this been tested?

  • The comparison of every old accessor with the new value, described above.
  • TestNumbering* keeps every case of the old 1,000 lines of tables, and adds invariants over tests.yaml and the corpora: every pair All yields lies inside an Ep, Shape is ShapeEpisode exactly for one Ep that is no range, Absolute is never inside a range. They also run in the fuzz target.
  • sampleFloors and probeFailures do not move.
  • go vet ./..., gofmt -l . with Go 1.26 and 1.27, go test ./... with the corpus present, go test -race ./..., the cmd/rls checks and 60 s of FuzzParseString pass. TestAbsoluteInvariants passes here, since the rule of fix(series): read the end of a range before a version as an episode #72 is carried in.

Checklist

  • I ran go fmt and the test suite passes locally
  • I added cases to tests.yaml for any parsing change
  • If this adds or renames a normalized value (source, codec, HDR, etc.), I noted the downstream impact on autobrr/qui
  • I have linked any related issue (none)

AI disclosure

Yes, all of it. Claude Code (Claude Fable 5.2) wrote the type, the tests and the comparison. A second model reviewed it, and a third ported both apps in local worktrees.

BREAKING CHANGE: the fields Release.Series and Release.Episode, the methods Release.HasSeason, HasEpisode, Seasons, SeriesEpisodes, EpisodeRange, EpisodeSpans and Absolute, and the type EpisodeSpan are removed. Release.Numbering replaces them. Numbering.Episode() gives the first episode of a batch where the field was 0.

The numbering of a name was two ints that could not tell zero from none, and
seven accessors that each walked the tags their own way. Release.Numbering
holds it as one value that a parse builds once: the scheme, the seasons, the
episodes with a range as one Ep, and a second numbering apart from them in
Alt. Season, Episode, Absolute, Shape and All read that value and nothing
else, so they answer the same for a Numbering made by hand or decoded from a
stored release.

Readings stay as they were, with these exceptions.

Episode gives the first episode of a batch: '[Grp] Show - 01-12' gives 1 and
true, where the field was 0 for a range the range lexer read and 1 for
'S01E01-E03'. Shape tells one episode from several. A first episode 0 is an
episode too: '[Grp] Show - 00 - 05' gives 0 and true, where the field skipped
the 0 and was 5. No name of the sets compared writes that.

The end of a range in front of a version is an episode and no second
numbering: 'S04E29-31v2' is the episodes 29 to 31 and has no absolute
episode. This is the rule of #72, and with it TestAbsoluteInvariants passes
when the corpus is present.

Absolute needs one regular episode and no more, so that it is the number
Episode gives. The field was the first bare episode that is not 0, whatever
stood beside it. Of the 71,636 names compared, 48 that write two episodes
and no season lose their absolute episode: two episodes in one release
('Hellsing.E06.E07' gave 6), a batch written as two numbers ('- 07 - 09'
gave 7), and a number of the title read as an episode ('Fairy Tail - 100
Years Quest - 07' gave 100). Three gain one, where the field took a year in
the title for half an episode ('E01.1954.bis.1990' gives 1).

Seasons are in the order the name writes them, and Season gives the first,
as Series did: 'Season 2 + Season 1 OVA' gives 2.

Frac is the digits after the point without the zeros that end them, so
'12.50' is the half that '12.5' is.

Episode, Absolute, Shape and All read the regular episodes. An Ep of another
Kind is in Episodes for a caller that wants it. All is safe on any value: it
counts the width of a range unsigned, and yields at most two pairs for each
Ep and maxRangeFill beside them.

The numbering is read in two passes over the tags. collect and the accessors
called secondNumbering for every series tag, and it walks the name, so a
name that is all numbering took quadratic time: '- 05 ' repeated to 128 KB
parsed in 3.8 s and takes 81 ms now. TestNumberingLinear holds that for 15
shapes.

The type of a release and Event depend on whether a tag writes an episode
other than 0 in its first place, which the range of a batch does not. No
rule over the Numbering gives that back for every name, so the parse keeps
it in Release.numbered and neither changes. A release with no tags, made by
hand or decoded, is read by its Numbering, where a range with no season is a
batch. Event is the same before and after a JSON round trip for every name
of tests.yaml and the corpora, which TestEventRoundTrip holds, and differs
for a range written with an 'E' after a competition ('UFC 300 - E01-E03').

Volume, Contents and Batch are not set yet, and every Kind is EpRegular.

tests.yaml gains the episode of nine names whose first episode stands in a
range, each the first pair of the entry's own seriesEpisodes, and the name
that the rule of #72 fixes.

TestAccuracyLabelled compares every label of a row with the episodes of the
release: one label with one episode, two with the ends of a batch. It read
the first label alone, so it counted a batch right whose end the parser
missed, and could not read a label with a fraction. The episode floors move
to what it measures: anitomy 65, habari 65, anitogo 64.

cmd/rls keeps its keys series, episode, has_season, has_episode, seasons and
episodes, computed from the numbering, and adds a numbering object with the
fields.

BREAKING CHANGE: the fields Release.Series and Release.Episode, the methods
Release.HasSeason, HasEpisode, Seasons, SeriesEpisodes, EpisodeRange,
EpisodeSpans and Absolute, and the type EpisodeSpan are removed. With
n := r.Numbering they become:

  r.Series            season, _ := n.Season()
  r.Episode           episode, _ := n.Episode(), which is the first
                      episode of a range too, and 0 when 0 is written first
  r.HasSeason()       _, ok := n.Season()
  r.HasEpisode()      _, ok := n.Episode()
  r.Seasons()         n.Seasons, in the order written and not sorted
  r.SeriesEpisodes()  for season, episode := range n.All(), in the order
                      written, with NoSeason where it gave season 0
  r.EpisodeRange()    First and Last of n.Episodes[0] when n.Shape() is
                      ShapeEpisodes and it is one Ep
  r.EpisodeSpans()    n.Episodes, and n.Alt for a second numbering
  EpisodeSpan         Ep, with numbers where it held the digits of the name
  r.Absolute()        n.Absolute(), which is false for more than one episode
@coderabbitai

coderabbitai Bot commented Nov 18, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 14658152-7ab6-4ce2-9f27-2d213aeec203

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant