fix(watchlist): preserve prev country when TMDB tv lacks production_countries
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
e0e0462836
commit
a5ebb6f088
2 changed files with 31 additions and 1 deletions
|
|
@ -63,6 +63,10 @@ function pickTrailer(videos: TmdbDetail): string {
|
|||
return '';
|
||||
}
|
||||
|
||||
function isBareIsoCode(s: string): boolean {
|
||||
return /^[A-Z]{2}$/.test(s);
|
||||
}
|
||||
|
||||
export function buildRecord(details: TmdbDetail, isMovie: boolean, prev: Record<string, string>): WatchlistRecord {
|
||||
const genres: string[] = (details.genres ?? []).map((g: any) => g.name);
|
||||
const language = langName(details);
|
||||
|
|
@ -119,7 +123,16 @@ export function buildRecord(details: TmdbDetail, isMovie: boolean, prev: Record<
|
|||
contentRating = usCertFromContentRatings(details.content_ratings ?? {});
|
||||
const prodCountries: any[] = details.production_countries ?? [];
|
||||
const originCountries: string[] = details.origin_country ?? [];
|
||||
country = prodCountries[0]?.name ?? originCountries[0] ?? '';
|
||||
if (prodCountries[0]?.name) {
|
||||
country = prodCountries[0].name;
|
||||
} else {
|
||||
const prevCountry = stripQuotes(prev['country']);
|
||||
if (prevCountry && !isBareIsoCode(prevCountry)) {
|
||||
country = prevCountry;
|
||||
} else {
|
||||
country = originCountries[0] ?? '';
|
||||
}
|
||||
}
|
||||
seasons = details.number_of_seasons ?? null;
|
||||
episodes = details.number_of_episodes ?? null;
|
||||
vod = (details.networks ?? []).map((n: any) => n.name);
|
||||
|
|
|
|||
|
|
@ -146,6 +146,23 @@ describe('TV country derivation', () => {
|
|||
const r = buildRecord(noProdCountries, false, EMPTY_PREV);
|
||||
expect(r.country).toBe('US');
|
||||
});
|
||||
test('TV no production_countries, prev full country name → preserves prev', () => {
|
||||
const { production_countries, ...noProdCountries } = tvDetail as any;
|
||||
const prev = { country: 'United States of America' };
|
||||
const r = buildRecord(noProdCountries, false, prev);
|
||||
expect(r.country).toBe('United States of America');
|
||||
});
|
||||
test('TV no production_countries, prev bare ISO code → uses origin_country fallback', () => {
|
||||
const { production_countries, ...noProdCountries } = tvDetail as any;
|
||||
const prev = { country: 'US' };
|
||||
const r = buildRecord(noProdCountries, false, prev);
|
||||
expect(r.country).toBe('US');
|
||||
});
|
||||
test('TV production_countries present, prev differs → uses production_countries name', () => {
|
||||
const prev = { country: 'Canada' };
|
||||
const r = buildRecord(tvDetail, false, prev);
|
||||
expect(r.country).toBe('United States of America');
|
||||
});
|
||||
});
|
||||
|
||||
describe('tmdb_rating rounding', () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue