epmarker

package
v0.10.0-dev.64 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package epmarker is the one authority for what a release or archive member name claims about its season and episode. A name is read once into tokens, runs of ASCII letters and digits, and every view classifies those tokens; every notation is case-insensitive.

  • Find: S##E## markers (S## E## too, across up to three of " ._-") and ##x## tokens. Claims: the episodes stated under a season, ranges expanded.
  • FirstIndex, Present: where a marker-shaped token starts, unreadable digits included, so such a name still reaches no fallback.
  • Season: the first S##E## or S## token, else "Season N", else ##x##.
  • StatesEpisode: a marker, E##, EP##, Episode N, " - NN" after the season or a range right after it or opening a bracket; a season pack states a Season and none.
  • Absolute: an episode number with no season attached (the caller supplies it); BareEpisode: a leading number in a name with no readable marker.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Absolute

func Absolute(name string) (episode int, ok bool)

Absolute returns the episode a name with no marker shape states by one number, as batch entries name their files ("[Group] Show - 26"): the last " - NN", since a title's number comes first, else the first E##, EP## or Episode N, else the last spaced NN that is no bit depth and that a space, the name's end or a file suffix follows ("Mob Psycho 100 05.mkv" states 5, "Show 02 10 bits" 2). A range's number or a bracketed bare one is none. ok is false when no form is present, the number overflows an int, or Present reports a marker shape.

func BareEpisode added in v0.4.35

func BareEpisode(name string) (episode int, ok bool)

BareEpisode returns the episode a name states as a bare leading number: "6 - A Golden Crown..srt" states episode 6. The number is the name's first token, one to three digits, followed by one of " ._-", so a resolution ("1080p") or a year ("2011 - ") is none. A name with a readable marker returns false.

A bare number names no season, so this reading is kept apart from Find and Claims; Target.MatchesBareEpisode states what a caller must know to use it.

func FirstIndex

func FirstIndex(name string) int

FirstIndex returns the byte offset at which the first marker-shaped token starts, or -1 when name carries none. Used to split a release name into its title portion and its marker portion.

func Present

func Present(name string) bool

Present reports whether name carries a marker-shaped token at all. This is the gate for "the name numbers its episodes some other way, fall back": a name containing an unparseable marker is still explicitly numbered, so it must not reach an absolute-number or season-pack fallback.

func Season

func Season(name string) (season int, ok bool)

Season returns the season of name's first S## token, a marker's S## included, else of "Season N", else of the cross form, so Season never contradicts Find ("Black Sails - 01x08" is season 1). ok is false when name carries no season token or its digits do not fit an int.

func StatesEpisode

func StatesEpisode(name string) bool

StatesEpisode reports whether name states an episode, as one number or a range: a marker-shaped token (Present), an E##, EP## or Episode N, or bare digits after a season statement, as " - 05" or as a range right after it or opening a bracket ("S2 01-12", "S2 [01 ~ 12]"). Other bare digits may be a title's, a volume's ("Vol.1-6"), a bit depth's ("10 bit"), a CRC's or a date's, so none of those states one. A season pack is a name with a Season that states none.

Types

type Marker

type Marker struct {
	Season  int
	Episode int
}

Marker is the season/episode pair one token claims. Both numbers are non-negative: they are read from digit runs, so "S00E00" is a legitimate Marker{0, 0} rather than a miss.

func Claims added in v0.4.35

func Claims(name string) []Marker

Claims returns every episode name claims, ordered, deduplicated, nil when it claims none: its markers, and each episode StatesEpisode reads under its marker's season, else the latest season statement before it; a range longer than maxRangeSpan claims its first. It selects archive members, so a number with no season before it ("E01-E02") claims nothing: guessing one risks the wrong episode's subtitle written under the right episode's name.

func Find

func Find(name string) []Marker

Find returns every well-formed single marker in name, in order of appearance, across both notations. Callers that care about precedence pick from the returned order themselves. A marker-shaped token whose season or episode does not fit an int is skipped here but still reported by Present.

func (Marker) String added in v0.4.35

func (m Marker) String() string

String renders a marker in the canonical S##E## form, which is what a diagnostic naming the episode a caller looked for should say.

type Target added in v0.4.35

type Target struct {
	// contains filtered or unexported fields
}

Target is what a lookup is looking for. The zero Target matches any name, which is what a movie download and a provider that reports no numbering both arrive with, so a caller selecting from candidates needs one loop rather than one per case.

func Any added in v0.4.35

func Any() Target

Any returns the Target that matches every name.

func For added in v0.4.35

func For(m Marker) Target

For returns the Target that matches only m, or Any when either half of m is absent. A zero season or episode is how the wire says "this download has no episode to disambiguate", so a caller can hand over a subtitle's fields without deciding what that means.

func (Target) Matches added in v0.4.35

func (t Target) Matches(name string) bool

Matches reports whether name claims the episode t is looking for. An Any target matches every name.

func (Target) MatchesBareEpisode added in v0.4.35

func (t Target) MatchesBareEpisode(name string) bool

MatchesBareEpisode reports whether name states t's episode as a bare leading number, with no season anywhere in the name. The name does not carry the season, so a caller uses it only when both conditions hold, neither checkable here: t's season is known reliably from outside the name (a provider result's season is stamped from the seasonNumber its search sent), and no member of the same archive claims a readable marker, so this reading never outvotes a notation that parses.

func (Target) String added in v0.4.35

func (t Target) String() string

String renders t for a diagnostic: the episode in canonical form, or "any" when nothing narrows the lookup.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL