//! The slice of TMDB's schema this project actually reads. //! //! TMDB returns a great deal more than this. Everything kept here is either //! shown to a person or fed to the policy engine; the rest is dropped at the //! edge so nothing downstream has to know TMDB's field names. use chrono::{Datelike, NaiveDate}; use serde::{Deserialize, Serialize}; /// TMDB's release-date type for a digital release. See §6.2 — this is the one /// that gates targeted search. const RELEASE_TYPE_DIGITAL: u8 = 4; /// One row of a TMDB search. /// /// `vote_average` is the one float, so this is `PartialEq` only. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct MovieSearchResult { /// TMDB's own id, the key everything else hangs off. pub tmdb_id: u32, /// Title in the requested language. pub title: String, /// Title in the original language. pub original_title: String, /// ISO 639-1, e.g. `en` or `pt`. See [`Movie::original_language`] for why /// this alone is not enough for Portuguese. pub original_language: String, /// Primary (theatrical) release date. Absent for announced-but-undated /// titles, where TMDB sends an empty string. pub release_date: Option, /// TMDB's synopsis, empty string normalised away. pub overview: Option, /// Path fragment, not a URL. TMDB's image base is a separate concern. pub poster_path: Option, /// TMDB's rating, out of 10, when TMDB has votes for it; zero normalised /// away like [`Movie::vote_average`]. pub vote_average: Option, /// How many votes the rating rests on. pub vote_count: u32, } impl MovieSearchResult { /// Release year, when TMDB has a release date at all. #[must_use] pub fn year(&self) -> Option { self.release_date.map(|date| date.year()) } } /// A movie as TMDB describes it, reduced to what this project uses. /// /// `vote_average` is the one float, so this is `PartialEq` only. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Movie { /// TMDB's own id. pub tmdb_id: u32, /// `IMDb` id, when TMDB knows one. Torznab `t=movie` searches take it. pub imdb_id: Option, /// Title in the requested language. pub title: String, /// Title in the original language. pub original_title: String, /// ISO 639-1, e.g. `en` or `pt`. /// /// The dub rule in §5.2 compares a track's language against this. ISO /// 639-1 has one code for both Portuguese variants, so `pt` on its own /// cannot tell a Brazilian film from a Portuguese one — pair it with /// [`Movie::origin_countries`] to resolve that. pub original_language: String, /// ISO 3166-1 alpha-2 country codes the title originates from. Needed to /// read `pt` as pt-BR or pt-PT. pub origin_countries: Vec, /// Primary (theatrical) release date. pub release_date: Option, /// Earliest digital release date TMDB records, across every country. /// /// §6.2: a movie with no digital release date gets zero targeted searches. /// Earliest-anywhere is the right reading of that — a release existing in /// one region is a release that exists on the indexers. pub digital_release: Option, /// Runtime in minutes, when known. pub runtime: Option, /// TMDB's own status string: `Released`, `Post Production`, and so on. pub status: String, /// TMDB's synopsis, empty string normalised away. pub overview: Option, /// Path fragment, not a URL. pub poster_path: Option, /// Path fragment, not a URL. §9.6 stores this on the row alongside /// [`Movie::poster_path`] and `vote_average`. pub backdrop_path: Option, /// TMDB's rating, out of 10, when TMDB has votes for it. Stored with the /// artwork (§9.6). TMDB sends `0` where "no rating yet" is meant, so a /// zero rating is normalised away here rather than stored as one. pub vote_average: Option, /// How many votes the rating rests on. pub vote_count: u32, } impl Movie { /// Release year, when TMDB has a release date at all. #[must_use] pub fn year(&self) -> Option { self.release_date.map(|date| date.year()) } /// Whether a digital release exists as of `on`. /// /// This is the §6.2 gate in one place: no digital date at all, or a date /// still in the future, means the release does not exist yet and searching /// for it is a wasted query. #[must_use] pub fn is_digitally_released(&self, on: NaiveDate) -> bool { self.digital_release.is_some_and(|date| date <= on) } } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct SeriesSearchResult { pub tmdb_id: u32, pub title: String, pub original_language: String, pub first_air_date: Option, pub overview: Option, pub poster_path: Option, /// Zero normalised away, like [`Movie::vote_average`]. pub vote_average: Option, /// How many votes the rating rests on. pub vote_count: u32, } impl SeriesSearchResult { #[must_use] pub fn year(&self) -> Option { self.first_air_date.map(|date| date.year()) } } /// TMDB's slice for series. `vote_average` is the one float, so this is /// `PartialEq` only. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Series { pub tmdb_id: u32, pub tvdb_id: Option, pub title: String, pub original_language: String, pub first_air_date: Option, pub status: String, pub overview: Option, pub poster_path: Option, /// §9.6 stores this on the row alongside `poster_path` and /// [`Series::vote_average`]. pub backdrop_path: Option, /// TMDB's rating, out of 10, when TMDB has votes for it. Stored with the /// artwork (§9.6); zero is normalised away like [`Movie::vote_average`]. pub vote_average: Option, /// How many votes the rating rests on. pub vote_count: u32, pub seasons: Vec, } impl Series { #[must_use] pub fn year(&self) -> Option { self.first_air_date.map(|date| date.year()) } } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct SeasonSummary { pub number: u32, pub episode_count: u32, } /// Placeholder for an episode TMDB has not named yet. #121's refresh replaces /// it once TMDB fills the title in. pub const UNTITLED_EPISODE: &str = "TBA"; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Season { pub number: u32, pub episodes: Vec, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Episode { pub number: u32, pub title: String, pub air_date: Option, } /// Cast is truncated to the top 10 billed, in the crate, so no caller has to /// remember to (§9.6). const CAST_LIMIT: usize = 10; /// A genre as a detail response carries it. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Genre { pub id: u32, pub name: String, } /// One of the top-billed cast members on a detail page. `profile_path` is a /// path fragment — §9.6 hotlinks images and the browser composes the URL. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct CastMember { /// The person's TMDB id, for the link out to tmdb.org (§9.6). pub tmdb_id: u32, pub name: String, pub character: String, pub profile_path: Option, pub order: u32, } /// One entry of a title's video list. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Video { pub key: String, /// `YouTube`, `Vimeo`, … Only `YouTube` ever becomes a trailer (§9.6). pub site: String, /// TMDB calls this field `type`: `Trailer`, `Teaser`, `Clip`, … pub kind: String, pub name: String, pub official: bool, } /// Rich movie detail for the §9.6 page. One upstream request via /// `append_to_response`, served through the same cache as everything else; /// nothing here is persisted. /// /// No float fields are involved in equality except `vote_average`, so this is /// `PartialEq` only. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct MovieDetail { pub tmdb_id: u32, pub overview: Option, pub tagline: Option, pub genres: Vec, pub backdrop_path: Option, pub poster_path: Option, /// Zero normalised away, like [`Movie::vote_average`]: TMDB sends `0` /// where "no votes yet" is meant, and a detail page must not show it as /// a rating. pub vote_average: Option, pub vote_count: u32, pub homepage: Option, pub status: String, pub runtime: Option, /// §9.6 links out to `IMDb` for movies. pub imdb_id: Option, /// Top [`CAST_LIMIT`] billed, ordered by TMDB's own cast order. pub cast: Vec, /// The one trailer worth showing, chosen by the §9.6 rule. pub trailer: Option