feat(watchlist): preserve existing TV crew fields until per-episode enrichment
This commit is contained in:
parent
b0f3dce76d
commit
2c663568ca
2 changed files with 40 additions and 3 deletions
|
|
@ -18,6 +18,13 @@ function langName(details: TmdbDetail): string {
|
||||||
return LANG_FALLBACK[code] ?? code;
|
return LANG_FALLBACK[code] ?? code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function prevCrewList(prev: Record<string, string>, key: string): string[] {
|
||||||
|
return stripQuotes(prev[key])
|
||||||
|
.split(/,\s*/)
|
||||||
|
.map(s => s.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
function crewNames(crew: any[], jobs: Set<string>): string[] {
|
function crewNames(crew: any[], jobs: Set<string>): string[] {
|
||||||
const seen = new Set<string>();
|
const seen = new Set<string>();
|
||||||
const out: string[] = [];
|
const out: string[] = [];
|
||||||
|
|
@ -94,9 +101,14 @@ export function buildRecord(details: TmdbDetail, isMovie: boolean, prev: Record<
|
||||||
const agg = details.aggregate_credits ?? {};
|
const agg = details.aggregate_credits ?? {};
|
||||||
cast = (agg.cast ?? []).slice(0, 12).map((c: any) => c.name);
|
cast = (agg.cast ?? []).slice(0, 12).map((c: any) => c.name);
|
||||||
const createdBy: string[] = (details.created_by ?? []).map((c: any) => c.name);
|
const createdBy: string[] = (details.created_by ?? []).map((c: any) => c.name);
|
||||||
director = createdBy; // series: creators (latest-episode director needs extra call — Phase 3)
|
// series: creators (latest-episode director needs extra call — Phase 3)
|
||||||
writer = createdBy;
|
// prev user-set crew wins over created_by fallback until per-episode enrichment lands
|
||||||
producer = [];
|
const prevDirector = prevCrewList(prev, 'director');
|
||||||
|
const prevWriter = prevCrewList(prev, 'writer');
|
||||||
|
const prevProducer = prevCrewList(prev, 'producer');
|
||||||
|
director = prevDirector.length ? prevDirector : createdBy;
|
||||||
|
writer = prevWriter.length ? prevWriter : createdBy;
|
||||||
|
producer = prevProducer.length ? prevProducer : [];
|
||||||
title = details.name ?? '';
|
title = details.name ?? '';
|
||||||
originalTitle = details.original_name ?? '';
|
originalTitle = details.original_name ?? '';
|
||||||
mediaType = 'TV Series';
|
mediaType = 'TV Series';
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,31 @@ describe('watch-status rule (TV)', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('TV crew preservation', () => {
|
||||||
|
test('TV + prev crew present → prev wins over created_by', () => {
|
||||||
|
const prev = {
|
||||||
|
director: '"Aaron Moorhead, Justin Benson"',
|
||||||
|
writer: 'Eric Martin',
|
||||||
|
producer: '"Rachel Alter, Tommy Turtle"',
|
||||||
|
};
|
||||||
|
const r = buildRecord(tvDetail, false, prev);
|
||||||
|
expect(r.director).toEqual(['Aaron Moorhead', 'Justin Benson']);
|
||||||
|
expect(r.writer).toEqual(['Eric Martin']);
|
||||||
|
expect(r.producer).toEqual(['Rachel Alter', 'Tommy Turtle']);
|
||||||
|
});
|
||||||
|
test('TV + empty prev crew → falls back to created_by', () => {
|
||||||
|
const r = buildRecord(tvDetail, false, EMPTY_PREV);
|
||||||
|
expect(r.director).toEqual(['Michael Waldron']);
|
||||||
|
expect(r.writer).toEqual(['Michael Waldron']);
|
||||||
|
expect(r.producer).toEqual([]);
|
||||||
|
});
|
||||||
|
test('Movie + prev crew present → prev ignored, TMDB credits win', () => {
|
||||||
|
const prev = { director: 'Someone Else' };
|
||||||
|
const r = buildRecord(movieDetail, true, prev);
|
||||||
|
expect(r.director).toEqual(['Denis Villeneuve']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('eng_name derivation', () => {
|
describe('eng_name derivation', () => {
|
||||||
test('non-Latin original → engName = localized title', () => {
|
test('non-Latin original → engName = localized title', () => {
|
||||||
const jp = { ...movieDetail, title: 'A Silent Voice: The Movie', original_title: '映画 聲の形' };
|
const jp = { ...movieDetail, title: 'A Silent Voice: The Movie', original_title: '映画 聲の形' };
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue