Répartition des notes sur les fiches de films et séries (Trakt)
deploy / deploy (push) Successful in 42s
deploy / deploy (push) Successful in 42s
- Fonction serveur « ratings » : moyenne, votes et répartition 1→10 de Trakt à partir de l'identifiant TMDB (clé TRAKT_CLIENT_ID côté serveur) - Fiche : la note Trakt remplace celle de TMDB quand il y a au moins 20 votes, avec le graphique comme pour les animes ; sinon rien ne change Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
This commit is contained in:
5 files changed
+130
-5
No files matched your search
+16
-4
@@ -1,6 +1,6 @@
|
||||
import type { MediaInput, MediaType } from '../types'
|
||||
import { region, t, tmdbLanguage } from '../i18n'
|
||||
import { tmdbViaCloud } from './cloud/api'
|
||||
import { ratingsViaCloud, tmdbViaCloud } from './cloud/api'
|
||||
import { TYPE_BY_VALUE } from './constants'
|
||||
import { subtypeLabel, tmdbGenres } from './genres'
|
||||
import { franchiseKey } from './franchise'
|
||||
@@ -998,8 +998,10 @@ export interface TitleExtras {
|
||||
/** Note moyenne du public, sur 10 */
|
||||
average?: number
|
||||
votes?: number
|
||||
/** Répartition des notes du public (AniList) : note sur 10 → nombre de votes */
|
||||
/** Répartition des notes du public (AniList, ou Trakt pour les films et séries) : note sur 10 → nombre de votes */
|
||||
distribution?: { score: number; amount: number }[]
|
||||
/** D'où vient la note moyenne (« Trakt » quand elle remplace celle de TMDB) */
|
||||
ratingSource?: string
|
||||
cast: CastMember[]
|
||||
/** Réalisation (films) ou création (séries) */
|
||||
directors: string[]
|
||||
@@ -1037,6 +1039,8 @@ async function tmdbExtras(externalId: string, key: string): Promise<TitleExtras>
|
||||
const [, kind, id] = externalId.split(':') as ['tmdb', 'movie' | 'tv', string]
|
||||
// Une seule requête pour le casting et « Où regarder ». Si le proxy n'accepte pas encore la combinaison
|
||||
// (fonction serveur pas redéployée), on retombe sur le casting seul.
|
||||
// Répartition des notes : TMDB ne la donne pas, on la demande à Trakt (via notre serveur), en parallèle
|
||||
const trakt = key.trim() === CLOUD_TMDB ? ratingsViaCloud(kind, id).catch(() => null) : Promise.resolve(null)
|
||||
const d = await tmdbFetch<TmdbExtras>(`/${kind}/${id}`, key, { append_to_response: 'credits,watch/providers' }).catch((e: unknown) => {
|
||||
// Seul un refus du paramètre (400) justifie le second essai : hors ligne, 429, 5xx… on ne double pas la requête
|
||||
if (key.trim() !== CLOUD_TMDB || !(e instanceof Error) || e.message !== t('err.tmdbStatus', { status: 400 })) throw e
|
||||
@@ -1055,10 +1059,18 @@ async function tmdbExtras(externalId: string, key: string): Promise<TitleExtras>
|
||||
.filter((c): c is CastMember => !!c.name)
|
||||
const crew = Array.isArray(d.credits?.crew) ? d.credits!.crew! : []
|
||||
const votes = count(d.vote_count, 100_000_000)
|
||||
// Trakt : moyenne, votes et répartition ensemble (même public), dès qu'il y a assez de votes
|
||||
const r = await trakt
|
||||
const useTrakt = !!r && r.rating != null && r.votes >= 20
|
||||
const distribution = useTrakt
|
||||
? Object.entries(r!.distribution).map(([score, amount]) => ({ score: Number(score), amount })).sort((a, b) => a.score - b.score)
|
||||
: undefined
|
||||
return {
|
||||
backdrop: isSafeTmdbPath(d.backdrop_path) ? `${TMDB_IMG}/w780${d.backdrop_path}` : undefined,
|
||||
average: tmdbPublicRating(d.vote_average, d.vote_count),
|
||||
votes,
|
||||
average: useTrakt ? Math.round(r!.rating! * 10) / 10 : tmdbPublicRating(d.vote_average, d.vote_count),
|
||||
votes: useTrakt ? r!.votes : votes,
|
||||
distribution,
|
||||
ratingSource: useTrakt ? 'Trakt' : undefined,
|
||||
cast,
|
||||
directors:
|
||||
kind === 'movie'
|
||||
|
||||
Reference in new issue
Block a user