parser

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package parser extracts structured metadata (show name, season, episode numbers, quality, release group, etc.) from release filenames and titles.

This is a minimal implementation that covers the common S01E05 / S01E05E06 patterns required by the importer. A richer implementation (handling daily episodes, anime absolute numbering, scene naming conventions) can replace this file without changing the public API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeTitle

func NormalizeTitle(s string) string

NormalizeTitle lowercases a title and reduces it to letters and digits so two titles can be compared without being tripped up by dots, underscores, spaces, or punctuation. Unicode-aware: accented letters fold to their ASCII base ("Pokémon" → "pokemon", matching release titles that drop the accent), non-Latin letters are kept (not deleted — deleting them normalized CJK titles to "" and made every comparison fail), and "&" folds to "and" so "Rick & Morty" matches "Rick.and.Morty".

Example:

NormalizeTitle("Breaking.Bad") == NormalizeTitle("breaking bad") == "breakingbad"

func TitleMatches

func TitleMatches(seriesTitle, releaseShowTitle string) bool

TitleMatches reports whether a release's parsed show title refers to the same series as seriesTitle. Comparison is strict after normalization, with one concession: a trailing 4-digit year on the release side is allowed ("Breaking Bad 2008" matches "Breaking Bad") since indexer releases frequently embed the premiere year.

It does NOT do any fuzzy matching, substring matching, or word-set comparison — those let unrelated releases slip through and cause the exact wrong-torrent bug this is meant to prevent. Use TitleMatchesAny when the series carries explicit alternate titles (from TMDB).

func TitleMatchesAny

func TitleMatchesAny(candidates []string, releaseShowTitle string) bool

TitleMatchesAny reports whether a release's parsed show title matches any of the supplied candidate titles using the strict TitleMatches rules. Pass the canonical series title together with any alternate titles (from TMDB).

This is the right call for indexer-result filtering: an "Andor" series with alternate "Star Wars: Andor" will match release "Star Wars Andor S01..." because one of the candidates ("Star Wars: Andor") is itself a strict match. The strict semantics are preserved per-candidate — no fuzzy logic is added at the aggregate level.

Types

type EpisodeInfo

type EpisodeInfo struct {
	// Season is the parsed season number (1-indexed; 0 = specials / unknown).
	Season int

	// Episodes is the list of episode numbers found in the filename.
	// A multi-episode file like S02E03E04 will have [3, 4].
	Episodes []int

	// IsSeasonPack is true when the filename or directory name indicates an
	// entire season rather than individual episodes (e.g. "Show.S02.BluRay").
	IsSeasonPack bool

	// AbsoluteEpisode is the parsed absolute episode number from anime-
	// style titles ("[Group] Show - 48 [1080p]" → 48). Zero when the
	// title doesn't match the absolute-pattern OR when SxxExx took
	// precedence (the SxxExx form is preferred whenever both could
	// apply, since it's less ambiguous).
	AbsoluteEpisode int
}

EpisodeInfo holds the TV-episode-specific fields parsed from a filename.

type ParsedRelease

type ParsedRelease struct {
	// ShowTitle is the show name portion of the filename, with dots/underscores
	// replaced by spaces and trimmed.
	ShowTitle string

	// EpisodeInfo carries the season/episode position data.
	EpisodeInfo EpisodeInfo

	// Year is the 4-digit year if one was present in the title (0 = absent).
	Year int
}

ParsedRelease is the result of parsing a single filename or release title.

func Parse

func Parse(filename string) ParsedRelease

Parse extracts structured information from a filename or release title. It is intentionally lenient: fields that cannot be determined are left at their zero values rather than returning an error.

func (ParsedRelease) String

func (p ParsedRelease) String() string

String returns a human-readable representation of a ParsedRelease for logging and debugging.

Jump to

Keyboard shortcuts

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