Source tier stops deciding grabs. Per resolution the policy carries a floor, a target and a penalty per gigabyte over, so a 20 GB WEB-DL beats a 60 GB remux while the remux keeps a score and stays eligible. Below the floor is a hard filter rather than a low score: unbounded "smaller is better" selects a 3 GB 4K encode that looks like mud. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
322 lines
7.7 KiB
Rust
322 lines
7.7 KiB
Rust
//! Pure domain types shared by the arr crates.
|
|
//!
|
|
//! This crate must never depend on `axum`, `sqlx` or `reqwest`.
|
|
|
|
use std::{collections::BTreeMap, path::PathBuf, time::SystemTime};
|
|
|
|
pub mod lang;
|
|
pub mod policy;
|
|
pub mod score;
|
|
|
|
pub use arr_parse::NameClaims as ParsedRelease;
|
|
pub use score::{Score, ScoreWeights};
|
|
|
|
macro_rules! id_type {
|
|
($name:ident) => {
|
|
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
|
pub struct $name(pub i64);
|
|
};
|
|
}
|
|
|
|
id_type!(RootId);
|
|
id_type!(PolicyId);
|
|
id_type!(MovieId);
|
|
id_type!(MediaFileId);
|
|
id_type!(ReleaseId);
|
|
id_type!(GrabId);
|
|
id_type!(OwnerId);
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub enum Audience {
|
|
Main,
|
|
Kids,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct Root {
|
|
pub id: RootId,
|
|
pub audience: Audience,
|
|
pub path: PathBuf,
|
|
pub policy_id: PolicyId,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
|
pub enum Language {
|
|
PortuguesePortugal,
|
|
PortugueseBrazil,
|
|
PortugueseUnverified,
|
|
Other(String),
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
|
pub enum Resolution {
|
|
R2160p,
|
|
R1080p,
|
|
R720p,
|
|
Other(u16),
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
|
pub enum Source {
|
|
Remux,
|
|
BluRay,
|
|
WebDl,
|
|
WebRip,
|
|
Hdtv,
|
|
Dvd,
|
|
Telecine,
|
|
Telesync,
|
|
Cam,
|
|
Screener,
|
|
Other,
|
|
}
|
|
|
|
impl From<arr_parse::Resolution> for Resolution {
|
|
fn from(value: arr_parse::Resolution) -> Self {
|
|
match value {
|
|
arr_parse::Resolution::P480 => Self::Other(480),
|
|
arr_parse::Resolution::P576 => Self::Other(576),
|
|
arr_parse::Resolution::P720 => Self::R720p,
|
|
arr_parse::Resolution::P1080 => Self::R1080p,
|
|
arr_parse::Resolution::P2160 => Self::R2160p,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<arr_parse::Source> for Source {
|
|
fn from(value: arr_parse::Source) -> Self {
|
|
match value {
|
|
arr_parse::Source::Cam => Self::Cam,
|
|
arr_parse::Source::Telesync => Self::Telesync,
|
|
arr_parse::Source::Telecine => Self::Telecine,
|
|
arr_parse::Source::Screener => Self::Screener,
|
|
arr_parse::Source::Dvd => Self::Dvd,
|
|
arr_parse::Source::Hdtv => Self::Hdtv,
|
|
arr_parse::Source::WebRip => Self::WebRip,
|
|
arr_parse::Source::WebDl => Self::WebDl,
|
|
arr_parse::Source::BluRay => Self::BluRay,
|
|
arr_parse::Source::Remux => Self::Remux,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub struct DolbyVisionProfile {
|
|
pub profile: u8,
|
|
pub compatibility_id: Option<u8>,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub enum HdrFormat {
|
|
Sdr,
|
|
Hdr10,
|
|
Hdr10Plus,
|
|
Hlg,
|
|
DolbyVision(DolbyVisionProfile),
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub enum RequiredAudio {
|
|
OriginalLanguage,
|
|
AnyOf(Vec<Language>),
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct HdrRules {
|
|
pub rejected_dolby_vision_profiles: Vec<DolbyVisionProfile>,
|
|
}
|
|
|
|
/// One resolution's size band (`DESIGN.md` §5.5). Below the floor is a hard
|
|
/// filter; the target is where the score peaks; above it the penalty grows
|
|
/// with every gigabyte.
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub struct SizeBand {
|
|
pub floor_bytes: u64,
|
|
pub target_bytes: u64,
|
|
/// Points lost per gigabyte above `target_bytes`, against the scale set
|
|
/// by [`ScoreWeights::size_at_target`].
|
|
pub penalty_per_gb_over: i32,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct Policy {
|
|
pub id: PolicyId,
|
|
pub name: String,
|
|
pub required_audio: RequiredAudio,
|
|
pub dub_blacklist: Vec<Language>,
|
|
pub hdr_rules: HdrRules,
|
|
pub size_bands: BTreeMap<Resolution, SizeBand>,
|
|
pub resolution_preference: Vec<Resolution>,
|
|
pub source_weights: BTreeMap<Source, i32>,
|
|
pub score_weights: ScoreWeights,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
|
pub struct MovieOverrides {
|
|
pub only_4k: bool,
|
|
pub allow_english_audio: bool,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub enum MovieState {
|
|
Missing,
|
|
Downloading,
|
|
Available,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct Movie {
|
|
pub id: MovieId,
|
|
pub tmdb_id: u64,
|
|
pub title: String,
|
|
pub year: u16,
|
|
pub original_language: Language,
|
|
pub root_id: RootId,
|
|
pub wanted: bool,
|
|
pub overrides: MovieOverrides,
|
|
pub state: MovieState,
|
|
pub blocked: bool,
|
|
pub search_attempts: u32,
|
|
pub last_searched_at: Option<SystemTime>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct AudioTrack {
|
|
pub language: Language,
|
|
pub title: Option<String>,
|
|
pub handler_name: Option<String>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct SubtitleTrack {
|
|
pub language: Language,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct ProbedMedia {
|
|
pub resolution: Resolution,
|
|
pub source: Option<Source>,
|
|
pub hdr: HdrFormat,
|
|
pub audio_tracks: Vec<AudioTrack>,
|
|
pub subtitle_tracks: Vec<SubtitleTrack>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub enum Rule {
|
|
RequiredAudio,
|
|
DubBlacklist(Language),
|
|
/// A Portuguese track whose pt-PT / pt-BR flavour no signal resolved.
|
|
PortugueseUnverified,
|
|
DolbyVisionProfile(DolbyVisionProfile),
|
|
Resolution(Resolution),
|
|
Source(Source),
|
|
Size,
|
|
Other(String),
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub enum Verdict {
|
|
Eligible,
|
|
Waived(Rule),
|
|
Rejected(Rule),
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct MediaFile {
|
|
pub id: MediaFileId,
|
|
pub movie_id: MovieId,
|
|
pub path: PathBuf,
|
|
pub size: u64,
|
|
pub probed: ProbedMedia,
|
|
pub waiver: Option<Rule>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct Release {
|
|
pub id: ReleaseId,
|
|
pub indexer_id: i64,
|
|
pub guid: String,
|
|
pub name: String,
|
|
pub size: u64,
|
|
pub seeders: u32,
|
|
pub publish_date: SystemTime,
|
|
pub download_url: String,
|
|
pub parsed: ParsedRelease,
|
|
pub score: i64,
|
|
pub verdict: Verdict,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub enum GrabState {
|
|
Downloading,
|
|
Downloaded,
|
|
Imported,
|
|
Failed,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct Grab {
|
|
pub id: GrabId,
|
|
pub release_id: ReleaseId,
|
|
pub movie_id: MovieId,
|
|
pub infohash: String,
|
|
pub state: GrabState,
|
|
pub grabbed_at: SystemTime,
|
|
pub imported_at: Option<SystemTime>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct BlacklistEntry {
|
|
pub infohash: String,
|
|
pub normalised_name: String,
|
|
pub reason: String,
|
|
pub created_at: SystemTime,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct Owner {
|
|
pub id: OwnerId,
|
|
pub name: String,
|
|
pub ntfy_topic: String,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub struct MovieOwner {
|
|
pub movie_id: MovieId,
|
|
pub owner_id: OwnerId,
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::{DolbyVisionProfile, HdrFormat, Language, Rule, Verdict};
|
|
|
|
#[test]
|
|
fn portuguese_variants_are_distinct() {
|
|
assert_ne!(Language::PortuguesePortugal, Language::PortugueseBrazil);
|
|
assert_ne!(Language::PortugueseBrazil, Language::PortugueseUnverified);
|
|
}
|
|
|
|
#[test]
|
|
fn dolby_vision_profile_is_preserved() {
|
|
assert_ne!(
|
|
HdrFormat::DolbyVision(DolbyVisionProfile {
|
|
profile: 8,
|
|
compatibility_id: Some(1),
|
|
}),
|
|
HdrFormat::DolbyVision(DolbyVisionProfile {
|
|
profile: 8,
|
|
compatibility_id: Some(2),
|
|
})
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn non_eligible_verdicts_name_the_rule() {
|
|
let rule = Rule::DolbyVisionProfile(DolbyVisionProfile {
|
|
profile: 5,
|
|
compatibility_id: None,
|
|
});
|
|
assert_eq!(Verdict::Rejected(rule.clone()), Verdict::Rejected(rule));
|
|
}
|
|
}
|