feat(indexer): tvsearch with season and episode tags (#78)
ci / web (push) Successful in 50s
ci / rust (push) Successful in 1m18s
e2e / e2e (push) Successful in 1m46s

This commit was merged in pull request #78.
This commit is contained in:
2026-08-22 22:34:04 +01:00
parent fc2a8de58d
commit 8d44225b57
11 changed files with 876 additions and 50 deletions
+82
View File
@@ -8,6 +8,7 @@
//! Parsing never fails: a malformed name yields a partial [`NameClaims`],
//! worst case an empty one.
mod episodes;
mod markers;
use serde::{Deserialize, Serialize};
@@ -144,6 +145,82 @@ pub enum Edition {
Limited,
}
/// What a release name claims about which episodes it holds. A season pack
/// and one episode of that season carry the same series title and differ
/// only here.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
pub enum EpisodeClaim {
/// One or more episodes of a single season: `S01E02`, `S01E02E03`,
/// `S01E02-E04`, `1x02`.
Episodes {
season: u32,
/// Claimed episode numbers, in order of appearance. Ranges are
/// expanded.
episodes: Vec<u32>,
},
/// A whole season, no episode number: `S01`, `Season 1`.
Season { season: u32 },
/// Several whole seasons: `S01-S03`, `Seasons 1-3`.
Seasons { first: u32, last: u32 },
/// A daily show identified by its air date: `2024.05.13`.
Daily { year: u16, month: u8, day: u8 },
}
impl EpisodeClaim {
/// Whether the release claims a whole season or more, rather than
/// named episodes.
#[must_use]
pub fn is_season_pack(&self) -> bool {
matches!(self, Self::Season { .. } | Self::Seasons { .. })
}
/// Whether the release claims several episodes in one file.
#[must_use]
pub fn is_multi_episode(&self) -> bool {
matches!(self, Self::Episodes { episodes, .. } if episodes.len() > 1)
}
/// Whether the claim covers one numbered episode.
#[must_use]
pub fn covers(&self, season: u32, episode: u32) -> bool {
match self {
Self::Episodes {
season: claimed,
episodes,
} => *claimed == season && episodes.contains(&episode),
Self::Season { .. } | Self::Seasons { .. } => self.covers_season(season),
Self::Daily { .. } => false,
}
}
/// Whether the claim covers any part of one season.
#[must_use]
pub fn covers_season(&self, season: u32) -> bool {
match self {
Self::Episodes {
season: claimed, ..
}
| Self::Season { season: claimed } => *claimed == season,
Self::Seasons { first, last } => (*first..=*last).contains(&season),
Self::Daily { .. } => false,
}
}
/// Whether the claim is exactly this air date.
#[must_use]
pub fn covers_date(&self, year: u16, month: u8, day: u8) -> bool {
matches!(
self,
Self::Daily {
year: claimed_year,
month: claimed_month,
day: claimed_day,
} if *claimed_year == year && *claimed_month == month && *claimed_day == day
)
}
}
/// What a release name claims about itself. Every field is unverified
/// (`DESIGN.md` §5.6); absence of a marker means nothing.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
@@ -167,6 +244,9 @@ pub struct NameClaims {
pub editions: Vec<Edition>,
/// Claimed release group.
pub group: Option<String>,
/// Claimed season, episodes or air date. `None` for anything that does
/// not carry a TV tag.
pub episode: Option<EpisodeClaim>,
}
#[derive(Debug, Clone)]
@@ -205,11 +285,13 @@ pub fn parse(name: &str) -> NameClaims {
.copied();
let boundary = year_idx.map_or(limit, |y| y.min(limit));
let lows: Vec<&str> = toks.iter().map(|t| t.low.as_str()).collect();
let mut claims = NameClaims {
year: year_idx
.and_then(|i| toks.get(i))
.and_then(|t| markers::year_of(&t.low)),
group: dash_group.or(bracket_group),
episode: episodes::claim(&lows),
..NameClaims::default()
};