diff --git a/packages/obsidian/src/watchlist/build.ts b/packages/obsidian/src/watchlist/build.ts index bc78de9..33f89d0 100644 --- a/packages/obsidian/src/watchlist/build.ts +++ b/packages/obsidian/src/watchlist/build.ts @@ -117,8 +117,9 @@ export function buildRecord(details: TmdbDetail, isMovie: boolean, prev: Record< runtime = rt.length > 0 ? rt[0] : null; status = details.status ?? ''; contentRating = usCertFromContentRatings(details.content_ratings ?? {}); - const countries: string[] = details.origin_country ?? []; - country = countries[0] ?? ''; + const prodCountries: any[] = details.production_countries ?? []; + const originCountries: string[] = details.origin_country ?? []; + country = prodCountries[0]?.name ?? originCountries[0] ?? ''; seasons = details.number_of_seasons ?? null; episodes = details.number_of_episodes ?? null; vod = (details.networks ?? []).map((n: any) => n.name); @@ -166,7 +167,7 @@ export function buildRecord(details: TmdbDetail, isMovie: boolean, prev: Record< watchStatus, rating, ratingStars, year: yearDisp, runtime, seasons, episodes, vod, genre: genres, status, language, country, director, writer, producer, contentRating, - tmdbRating: details.vote_average ?? null, tmdbId: String(details.id), + tmdbRating: details.vote_average != null ? Math.round(details.vote_average * 10) / 10 : null, tmdbId: String(details.id), imdbId, releaseDate, lastAirDate, nextAirDate, lastEpisode, upcomingEpisode: upEpisode, poster, trailer, homepage: details.homepage ?? '', imdbPage: imdbId ? `https://www.imdb.com/title/${imdbId}/` : '', diff --git a/tests/fixtures/tmdb-tv-loki.json b/tests/fixtures/tmdb-tv-loki.json index 0e6085a..3ab5b80 100644 --- a/tests/fixtures/tmdb-tv-loki.json +++ b/tests/fixtures/tmdb-tv-loki.json @@ -33,7 +33,13 @@ } ], "origin_country": [ - "United States of America" + "US" + ], + "production_countries": [ + { + "iso_3166_1": "US", + "name": "United States of America" + } ], "created_by": [ { diff --git a/tests/watchlist-build.test.ts b/tests/watchlist-build.test.ts index 3414565..53827f8 100644 --- a/tests/watchlist-build.test.ts +++ b/tests/watchlist-build.test.ts @@ -136,6 +136,33 @@ describe('TV crew preservation', () => { }); }); +describe('TV country derivation', () => { + test('prefers production_countries full name over raw origin_country code', () => { + const r = buildRecord(tvDetail, false, EMPTY_PREV); + expect(r.country).toBe('United States of America'); + }); + test('no production_countries → falls back to raw origin_country code', () => { + const { production_countries, ...noProdCountries } = tvDetail as any; + const r = buildRecord(noProdCountries, false, EMPTY_PREV); + expect(r.country).toBe('US'); + }); +}); + +describe('tmdb_rating rounding', () => { + test('6.537 → 6.5', () => { + expect(buildRecord({ ...tvDetail, vote_average: 6.537 }, false, EMPTY_PREV).tmdbRating).toBe(6.5); + }); + test('7.854 → 7.9', () => { + expect(buildRecord({ ...tvDetail, vote_average: 7.854 }, false, EMPTY_PREV).tmdbRating).toBe(7.9); + }); + test('8.2 → 8.2 (unaffected)', () => { + expect(buildRecord(tvDetail, false, EMPTY_PREV).tmdbRating).toBe(8.2); + }); + test('null → null', () => { + expect(buildRecord({ ...tvDetail, vote_average: null }, false, EMPTY_PREV).tmdbRating).toBeNull(); + }); +}); + describe('eng_name derivation', () => { test('non-Latin original → engName = localized title', () => { const jp = { ...movieDetail, title: 'A Silent Voice: The Movie', original_title: '映画 聲の形' };