epmarker

package
v0.8.0-dev.3 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package epmarker is the single authority for reading episode markers out of release names and archive member filenames. Every site that asks "which season and episode does this name claim?" reads the same scanner, so the scoring layer, the archive extractor and the AnimeTosho provider cannot disagree about what a marker is.

Notations, all case-insensitive:

  • S##E##, and S## E## with a short separator — the dominant forms, and the unseparated one was all this package read until a real SubSource pack turned up whose ten members were named the other way and were therefore all unreachable. The separated form was measured on two more packs, 54 members between them, in "Firefly [S01 E01] - Serenity.eng.srt" shape.
  • ##x## — Addic7ed's form, as in "Black Sails - 01x08 - VIII.". The episode half must carry at least two digits, which is what keeps an aspect ratio ("4x3", "16x9") from reading as a season and episode, and a match may not begin right after an alphanumeric, which is what keeps a resolution ("1920x1080", whose interior "20x108" is otherwise in range) out.
  • Multi-episode ranges — E01E02, E01-E02, E01-02, E01.E02 — expanded by Claims against every season the name names.

Views:

  • Find: every well-formed single marker, in order of appearance.
  • Claims: every episode the name claims, ranges expanded. This is the view a caller selecting an archive member wants.
  • Target and its Matches: what a lookup is looking for, where the zero value matches anything. Selecting with a Target means a caller has ONE loop rather than one for "find this episode" and another for "take the first".
  • FirstIndex / Present: where the first marker-SHAPED token starts, and whether one exists at all. Shape presence is deliberately independent of Find: a token whose digits overflow an int is still shaped like a marker, so it must keep suppressing a "this name carries no marker" fallback, but it yields no usable season/episode and Find therefore omits it.
  • Season: the season claimed by the leading S## token, whether or not an E## follows it — a season pack ("Show.S04.Complete") has no E##.

Deliberately NOT here, because it is per-site policy rather than marker syntax: the archive extractor's filepath.Base narrowing, and the AnimeTosho provider's standalone absolute-number probes (" - 26", "e26").

Digit runs in the S##E## form are unbounded on purpose: a bound either silently truncates a long episode number or silently misses a zero-padded season. "S001E01" read under a two-digit bound scanned as season 0 with no episode marker at all, which classified a single episode as a season pack, and "S01E1234" truncated to 123.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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, with no season anywhere in it: "6 - A Golden Crown..srt" states episode 6.

This is a reading, not a match. It is only SOUND alongside information the name does not carry, so it is reported separately from Find and Claims and never folded into them: a bare number says which episode of some season, and nothing about which season. Target.MatchesBareEpisode states the conditions a caller must meet before using it.

A name that carries a readable marker returns false, so the two readings can never both answer for one name.

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 claimed by the first explicit season statement in name, whether written compactly ("S01", with or without a trailing E##) or as a word ("Season 1"). ok is false when name carries no season token or the token's digits do not fit an int.

Falls back last to the cross form's season, because an authority that reported no season for "Black Sails - 01x08" while Find reported season 1 from the same token would be contradicting itself, and this package exists so its callers cannot disagree about what a marker says.

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, with multi-episode ranges expanded against each season the name names. Ordered, deduplicated, nil when the name claims nothing.

This is the view for selecting an archive member. A range only means something once a season is known, so "S01E01-E02" claims S01E01 and S01E02 while a bare "E01-E02" claims nothing: attaching a range to a season nobody stated would be guessing, and the cost of guessing wrong is 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.

Separate from Matches because it is only sound with information the NAME does not carry: the season. Two conditions must hold before a caller uses it, and neither is checkable from here.

The season must be known from outside the name, and known reliably rather than assumed. In subflux it is: the provider search sends seasonNumber to the API and the result's season is stamped from that same request, so a target's season came from Sonarr and not from any filename.

And no member of the same archive may claim a readable marker, which only the caller holding the whole member list can decide. That condition is what stops this reading from ever outvoting a notation that does parse.

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