From 9adbca3acd09a143d879eb415cbb177d69a69f52 Mon Sep 17 00:00:00 2001 From: "naps62-yolo (agent)" Date: Sun, 15 Nov 2026 13:22:29 +0000 Subject: [PATCH] fix(core): waive untagged audio on main roots (#282) --- DESIGN.md | 9 ++++++++ crates/arr-api/src/health.rs | 3 +-- crates/arr-api/src/search.rs | 1 + crates/arr-api/src/subtitles.rs | 5 +---- crates/arr-core/src/lib.rs | 4 ++++ crates/arr-core/src/policy.rs | 34 ++++++++++++++++++++++++++++++ crates/arr-daemon/src/qbit_fake.rs | 8 +++---- crates/arr-meta/src/model.rs | 33 +++++++++++++---------------- web/src/releases.ts | 1 + 9 files changed, 69 insertions(+), 29 deletions(-) diff --git a/DESIGN.md b/DESIGN.md index a35e8d1..f173df6 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -259,6 +259,15 @@ When none resolve it, tag the track `por-unverified` and surface it. Do not guess. Guessing toward `kids` gives a child a Brazilian dub; guessing toward `main` rejects a Brazilian film's own audio. +**Untagged audio.** A track tagged `und`, or carrying no language at all, says +nothing. On `main`, when no track matches the original language but one is +untagged, it is a soft fail (`audio_language_untagged`): import with a waiver +instead of rejecting. Sloppy tags are common in WEB-DL packs, often on a single +episode, and a hard fail there blacklists the whole pack (§5.7) over a file +that almost always carries the original soundtrack. `kids` is unchanged: its +missing-pt-PT case is already a soft fail, and an untagged track never counts +as pt-PT. + **Sourcing consequence for `kids`.** European Portuguese dubs live almost entirely in streaming WEB-DLs (Disney+, Netflix, Max) and essentially never in BluRay encodes or remuxes. That root biases hard toward WEB-DL sources, and diff --git a/crates/arr-api/src/health.rs b/crates/arr-api/src/health.rs index 5ae952c..d14a35f 100644 --- a/crates/arr-api/src/health.rs +++ b/crates/arr-api/src/health.rs @@ -243,8 +243,7 @@ async fn probe_subtitles(state: &AppState) -> SubtitleHealth { // quiet rather than failing on data the operator has not entered yet. let enabled = settings .as_ref() - .map(|settings| settings.providers_enabled.as_slice()) - .unwrap_or_default(); + .map_or_default(|settings| settings.providers_enabled.as_slice()); let engine = settings .as_ref() .and_then(|settings| settings.translation_engine.as_deref()); diff --git a/crates/arr-api/src/search.rs b/crates/arr-api/src/search.rs index 065dbad..9735f72 100644 --- a/crates/arr-api/src/search.rs +++ b/crates/arr-api/src/search.rs @@ -947,6 +947,7 @@ fn rule_name(rule: &Rule) -> String { Rule::RequiredAudio => "required_audio".into(), Rule::DubBlacklist(_) => "dub_blacklist".into(), Rule::PortugueseUnverified => "portuguese_unverified".into(), + Rule::AudioLanguageUntagged => "audio_language_untagged".into(), Rule::DolbyVisionProfile(_) => "dolby_vision_profile".into(), Rule::Resolution(_) => "resolution".into(), Rule::Source(_) => "source".into(), diff --git a/crates/arr-api/src/subtitles.rs b/crates/arr-api/src/subtitles.rs index 8412b0b..66e04ce 100644 --- a/crates/arr-api/src/subtitles.rs +++ b/crates/arr-api/src/subtitles.rs @@ -641,10 +641,7 @@ async fn embedded_tracks_of( .fetch_optional(pool(state)?) .await? .flatten(); - Ok(probed - .as_deref() - .map(extractable_tracks) - .unwrap_or_default()) + Ok(probed.as_deref().map_or_default(extractable_tracks)) } /// The `sub_tracks` array of a `probed` blob, filtered to what §15 allows an diff --git a/crates/arr-core/src/lib.rs b/crates/arr-core/src/lib.rs index f6b20b6..74b66c2 100644 --- a/crates/arr-core/src/lib.rs +++ b/crates/arr-core/src/lib.rs @@ -422,6 +422,9 @@ pub enum Rule { DubBlacklist(Language), /// A Portuguese track whose pt-PT / pt-BR flavour no signal resolved. PortugueseUnverified, + /// An audio track tagged `und` (or untagged) where none matched the + /// original language: probably the original, but nothing says so. + AudioLanguageUntagged, DolbyVisionProfile(DolbyVisionProfile), Resolution(Resolution), Source(Source), @@ -438,6 +441,7 @@ impl Rule { Self::RequiredAudio => "required_audio".into(), Self::DubBlacklist(_) => "dub_blacklist".into(), Self::PortugueseUnverified => "portuguese_unverified".into(), + Self::AudioLanguageUntagged => "audio_language_untagged".into(), Self::DolbyVisionProfile(_) => "dolby_vision_profile".into(), Self::Resolution(_) => "resolution".into(), Self::Source(_) => "source".into(), diff --git a/crates/arr-core/src/policy.rs b/crates/arr-core/src/policy.rs index bfc2836..40f5bdd 100644 --- a/crates/arr-core/src/policy.rs +++ b/crates/arr-core/src/policy.rs @@ -470,6 +470,13 @@ impl PolicyRule for RequiredAudioRule { if context.overrides.allow_english_audio && languages.contains(&english) { return RuleEvaluation::SoftFail(Rule::RequiredAudio); } + if matches!( + context.policy.required_audio, + RequiredAudio::OriginalLanguage + ) && languages.contains(&Language::Other("und".to_owned())) + { + return RuleEvaluation::SoftFail(Rule::AudioLanguageUntagged); + } Self::failure(context) } } @@ -1242,6 +1249,33 @@ mod tests { ); } + #[test] + fn main_untagged_audio_is_waived_not_rejected() { + let media = probed_audio(vec![track(Language::Other("und".to_owned()))]); + assert_eq!( + verdict_for(&policy(), &en(), Candidate::PostDownload(&media)), + Verdict::Waived(Rule::AudioLanguageUntagged) + ); + } + + #[test] + fn main_untagged_audio_beside_the_original_stays_eligible() { + let media = probed_audio(vec![track(en()), track(Language::Other("und".to_owned()))]); + assert_eq!( + verdict_for(&policy(), &en(), Candidate::PostDownload(&media)), + Verdict::Eligible + ); + } + + #[test] + fn kids_untagged_audio_keeps_the_required_audio_waiver() { + let media = probed_audio(vec![track(Language::Other("und".to_owned()))]); + assert_eq!( + verdict_for(&kids_policy(), &en(), Candidate::PostDownload(&media)), + Verdict::Waived(Rule::RequiredAudio) + ); + } + // §5.2 truth table, `kids` root: require pt-PT, or the original language // when that is already Portuguese; pt-BR never satisfies the requirement. diff --git a/crates/arr-daemon/src/qbit_fake.rs b/crates/arr-daemon/src/qbit_fake.rs index acca1a6..7ebfc9f 100644 --- a/crates/arr-daemon/src/qbit_fake.rs +++ b/crates/arr-daemon/src/qbit_fake.rs @@ -165,14 +165,13 @@ impl FakeQbit { .torrents() .into_iter() .find(|torrent| torrent.hash.eq_ignore_ascii_case(&hash)) - .map(|torrent| { + .map_or_default(|torrent| { torrent .files .into_iter() .map(|(path, size)| json!({"name": path, "size": size})) .collect() - }) - .unwrap_or_default(); + }); ResponseTemplate::new(200).set_body_json(files) } @@ -281,8 +280,7 @@ fn decode(input: &str) -> String { fn text(parts: &HashMap>, key: &str) -> String { parts .get(key) - .map(|bytes| String::from_utf8_lossy(bytes).into_owned()) - .unwrap_or_default() + .map_or_default(|bytes| String::from_utf8_lossy(bytes).into_owned()) } /// The named parts of a `multipart/form-data` body. diff --git a/crates/arr-meta/src/model.rs b/crates/arr-meta/src/model.rs index cc46796..65c4c48 100644 --- a/crates/arr-meta/src/model.rs +++ b/crates/arr-meta/src/model.rs @@ -787,21 +787,19 @@ impl From for Video { } fn cast_from(raw: Option) -> Vec { - let mut cast: Vec = raw - .map(|credits| { - credits - .cast - .into_iter() - .map(|member| CastMember { - tmdb_id: member.id, - name: member.name, - character: member.character, - profile_path: non_empty(member.profile_path), - order: member.order, - }) - .collect() - }) - .unwrap_or_default(); + let mut cast: Vec = raw.map_or_default(|credits| { + credits + .cast + .into_iter() + .map(|member| CastMember { + tmdb_id: member.id, + name: member.name, + character: member.character, + profile_path: non_empty(member.profile_path), + order: member.order, + }) + .collect() + }); // TMDB's own ordering is by `order`; sorting makes the truncation hold // even if a fixture or future API revision sends them shuffled. cast.sort_by_key(|member| member.order); @@ -810,9 +808,8 @@ fn cast_from(raw: Option) -> Vec { } fn trailer_from(raw: Option) -> Option