fix: count pt-BR as pt-PT in subtitle status
ci / web (pull_request) Successful in 1m21s
ci / rust (pull_request) Successful in 5m5s
ci / image (pull_request) Skipped
e2e / e2e (pull_request) Successful in 2m10s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Miguel Palhas
2026-11-15 17:33:16 +00:00
co-authored by Claude Opus 5.5
parent 77e5177e24
commit 2a71e6fb56
5 changed files with 50 additions and 17 deletions
+23 -6
View File
@@ -713,14 +713,13 @@ async fn missing_for(
subtitles: &[Subtitle],
wanted: &[String],
) -> Result<Vec<MissingSubtitle>, ApiError> {
let satisfied: BTreeSet<&str> = subtitles
.iter()
.filter(|subtitle| !subtitle.forced)
.map(|subtitle| subtitle.language.as_str())
.collect();
let gaps: Vec<&String> = wanted
.iter()
.filter(|language| !satisfied.contains(language.as_str()))
.filter(|language| {
!subtitles.iter().any(|subtitle| {
!subtitle.forced && arr_core::subs::satisfies(language, &subtitle.language)
})
})
.collect();
if gaps.is_empty() {
return Ok(Vec::new());
@@ -3183,6 +3182,24 @@ mod tests {
assert_eq!(missing[0]["language"], "en");
}
/// §15: pt-BR satisfies a pt-PT want, so an embedded pt-BR track drops
/// pt-PT from `missing` — the same rule the daemon's gap loop applies.
#[tokio::test]
async fn status_counts_pt_br_as_satisfying_pt_pt() {
let fixture = stub_application().await;
arr_db::subtitles::record_file(
&fixture.pool,
&arr_db::NewSubtitleFile::embedded(1, "pt-BR"),
)
.await
.expect("embedded");
let statuses = status(&format!("{}/api/movies/1/subtitles/status", fixture.base)).await;
let missing = statuses[0]["missing"].as_array().expect("missing");
assert_eq!(missing.len(), 1, "{missing:?}");
assert_eq!(missing[0]["language"], "en");
}
/// #201: `no_candidates`, `capped` and `failed` carry the attempt row's
/// own state, and `failed` also carries `last_failure` as `detail`.
#[tokio::test]
+10
View File
@@ -157,6 +157,16 @@ pub fn rank<'a>(
ranked
}
/// Whether a subtitle in `have` settles a want for `wanted` (§15: pt-PT
/// preferred, pt-BR always fine). An unverified Portuguese embedded track
/// counts too: it satisfies viewing even when no signal resolved the
/// flavour. The daemon's gap loop and the API's `missing` list both read
/// this, so they cannot disagree about what is satisfied.
#[must_use]
pub fn satisfies(wanted: &str, have: &str) -> bool {
have == wanted || (wanted == "pt-PT" && matches!(have, "pt-BR" | "por-unverified"))
}
#[cfg(test)]
mod tests {
use super::*;
+1 -9
View File
@@ -24,7 +24,7 @@ use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::path::{Path, PathBuf};
use std::sync::Arc;
use arr_core::subs::{rank, SubtitleTarget, SubtitleVerdict};
use arr_core::subs::{rank, satisfies, SubtitleTarget, SubtitleVerdict};
use arr_core::{layout, Language};
use arr_db::subtitle_budget::{self as budget, BudgetKind};
use arr_db::subtitles::{self as db, PendingSubtitle, SubtitleOrigin, SubtitleState};
@@ -112,14 +112,6 @@ pub(crate) async fn load_settings(database: &Db) -> Result<Settings, SubtitleErr
})
}
/// Whether a subtitle in `have` settles a want for `wanted` (§15: pt-PT
/// preferred, pt-BR always fine). An unverified Portuguese embedded track
/// counts too: it satisfies viewing even when no signal resolved the
/// flavour.
fn satisfies(wanted: &str, have: &str) -> bool {
have == wanted || (wanted == "pt-PT" && matches!(have, "pt-BR" | "por-unverified"))
}
/// The languages worth fetching when `wanted` is the gap, preferred first.
fn acceptable(wanted: &Language) -> Vec<Language> {
match wanted {
+3 -1
View File
@@ -26,6 +26,7 @@ import {
type SubtitleCandidate,
type SubtitleSearchResults,
type SubtitleStatus,
satisfiesWanted,
searchSubtitles,
subtitleChipLabel,
subtitleRuleLabel,
@@ -84,7 +85,8 @@ function SubtitleChip({
return (
<Chip
data-verdict={
!subtitle.forced && (wanted === null || wanted.includes(subtitle.language))
!subtitle.forced &&
(wanted === null || wanted.some((language) => satisfiesWanted(language, subtitle.language)))
? "eligible"
: undefined
}
+13 -1
View File
@@ -538,6 +538,15 @@ const SUMMARY_SHOWN = 2;
* every non-forced language shows then, which is a superset rather than a
* wrong answer.
*/
/**
* Whether a subtitle in `have` settles a want for `wanted` — §15's pt-PT
* preferred, pt-BR accepted. Mirrors `arr_core::subs::satisfies`, which the
* server's `missing` list is computed with.
*/
export function satisfiesWanted(wanted: string, have: string): boolean {
return have === wanted || (wanted === "pt-PT" && (have === "pt-BR" || have === "por-unverified"));
}
export function wantedSubtitles(subtitles: Subtitle[], wanted: string[] | null): Subtitle[] {
const present = subtitles.filter((subtitle) => !subtitle.forced);
if (wanted === null) {
@@ -545,7 +554,10 @@ export function wantedSubtitles(subtitles: Subtitle[], wanted: string[] | null):
}
// the operator's order, not the file's: two files with the same languages
// must read identically at a glance
return wanted.flatMap((language) => present.filter((subtitle) => subtitle.language === language));
const ordered = wanted.flatMap((language) =>
present.filter((subtitle) => satisfiesWanted(language, subtitle.language)),
);
return [...new Set(ordered)];
}
export function subtitleSummary(status: SubtitleStatus, wanted: string[] | null): SubtitleSummary {