fix: count pt-BR as pt-PT in subtitle status
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
77e5177e24
commit
2a71e6fb56
@@ -713,14 +713,13 @@ async fn missing_for(
|
|||||||
subtitles: &[Subtitle],
|
subtitles: &[Subtitle],
|
||||||
wanted: &[String],
|
wanted: &[String],
|
||||||
) -> Result<Vec<MissingSubtitle>, ApiError> {
|
) -> 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
|
let gaps: Vec<&String> = wanted
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|language| !satisfied.contains(language.as_str()))
|
.filter(|language| {
|
||||||
|
!subtitles.iter().any(|subtitle| {
|
||||||
|
!subtitle.forced && arr_core::subs::satisfies(language, &subtitle.language)
|
||||||
|
})
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
if gaps.is_empty() {
|
if gaps.is_empty() {
|
||||||
return Ok(Vec::new());
|
return Ok(Vec::new());
|
||||||
@@ -3183,6 +3182,24 @@ mod tests {
|
|||||||
assert_eq!(missing[0]["language"], "en");
|
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
|
/// #201: `no_candidates`, `capped` and `failed` carry the attempt row's
|
||||||
/// own state, and `failed` also carries `last_failure` as `detail`.
|
/// own state, and `failed` also carries `last_failure` as `detail`.
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
@@ -157,6 +157,16 @@ pub fn rank<'a>(
|
|||||||
ranked
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ use std::collections::{BTreeMap, BTreeSet, HashSet};
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::Arc;
|
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_core::{layout, Language};
|
||||||
use arr_db::subtitle_budget::{self as budget, BudgetKind};
|
use arr_db::subtitle_budget::{self as budget, BudgetKind};
|
||||||
use arr_db::subtitles::{self as db, PendingSubtitle, SubtitleOrigin, SubtitleState};
|
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.
|
/// The languages worth fetching when `wanted` is the gap, preferred first.
|
||||||
fn acceptable(wanted: &Language) -> Vec<Language> {
|
fn acceptable(wanted: &Language) -> Vec<Language> {
|
||||||
match wanted {
|
match wanted {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import {
|
|||||||
type SubtitleCandidate,
|
type SubtitleCandidate,
|
||||||
type SubtitleSearchResults,
|
type SubtitleSearchResults,
|
||||||
type SubtitleStatus,
|
type SubtitleStatus,
|
||||||
|
satisfiesWanted,
|
||||||
searchSubtitles,
|
searchSubtitles,
|
||||||
subtitleChipLabel,
|
subtitleChipLabel,
|
||||||
subtitleRuleLabel,
|
subtitleRuleLabel,
|
||||||
@@ -84,7 +85,8 @@ function SubtitleChip({
|
|||||||
return (
|
return (
|
||||||
<Chip
|
<Chip
|
||||||
data-verdict={
|
data-verdict={
|
||||||
!subtitle.forced && (wanted === null || wanted.includes(subtitle.language))
|
!subtitle.forced &&
|
||||||
|
(wanted === null || wanted.some((language) => satisfiesWanted(language, subtitle.language)))
|
||||||
? "eligible"
|
? "eligible"
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-1
@@ -538,6 +538,15 @@ const SUMMARY_SHOWN = 2;
|
|||||||
* every non-forced language shows then, which is a superset rather than a
|
* every non-forced language shows then, which is a superset rather than a
|
||||||
* wrong answer.
|
* 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[] {
|
export function wantedSubtitles(subtitles: Subtitle[], wanted: string[] | null): Subtitle[] {
|
||||||
const present = subtitles.filter((subtitle) => !subtitle.forced);
|
const present = subtitles.filter((subtitle) => !subtitle.forced);
|
||||||
if (wanted === null) {
|
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
|
// the operator's order, not the file's: two files with the same languages
|
||||||
// must read identically at a glance
|
// 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 {
|
export function subtitleSummary(status: SubtitleStatus, wanted: string[] | null): SubtitleSummary {
|
||||||
|
|||||||
Reference in New Issue
Block a user