fix: count pt-BR as pt-PT in subtitle status (#286)
This commit was merged in pull request #286.
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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::*;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user