Actualiser js/admin.js

This commit is contained in:
2026-06-15 22:37:19 +02:00
parent c80aa67c50
commit 753fe7aba8
+30 -22
View File
@@ -824,39 +824,47 @@ async function fetchTmdbDetails(title, year) {
try {
const yearParam = year ? `&year=${year}` : '';
const res = await fetch(`https://api.themoviedb.org/3/search/movie?api_key=${key}&query=${encodeURIComponent(title)}&language=fr-FR${yearParam}`);
// Step 1 : Recherche du film pour obtenir son ID TMDB
const res = await fetch(
`https://api.themoviedb.org/3/search/movie?api_key=${key}&query=${encodeURIComponent(title)}&language=fr-FR${yearParam}`
);
const data = await res.json();
let movie = data.results && data.results.length > 0 ? data.results[0] : null;
if (!movie && year) {
const res2 = await fetch(`https://api.themoviedb.org/3/search/movie?api_key=${key}&query=${encodeURIComponent(title)}&language=fr-FR`);
const data2 = await res2.json();
if (data2.results && data2.results.length > 0) movie = data2.results[0];
}
if (movie) {
const poster = movie.poster_path ? `https://image.tmdb.org/t/p/w500${movie.poster_path}` : '';
let streaming = streamingDefault;
if (data.results && data.results.length > 0) {
const movie = data.results[0];
const movieId = movie.id;
const posterPath = movie.poster_path ? `https://image.tmdb.org/t/p/w500${movie.poster_path}` : '';
let streamingInfo = streamingDefault;
// Step 2 : Requête sur l'endpoint "watch/providers" pour avoir le streaming en France (FR)
try {
const providerRes = await fetch(`https://api.themoviedb.org/3/movie/${movie.id}/watch/providers?api_key=${key}`);
const providerData = await providerRes.json();
const watchRes = await fetch(
`https://api.themoviedb.org/3/movie/${movieId}/watch/providers?api_key=${key}`
);
const watchData = await watchRes.json();
// On cherche les plateformes d'abonnement (flatrate) disponibles en France (FR)
if (providerData.results && providerData.results.FR && providerData.results.FR.flatrate) {
const providers = providerData.results.FR.flatrate.map(p => p.provider_name);
if (watchData.results && watchData.results.FR) {
const frProviders = watchData.results.FR;
// On privilégie les plateformes incluses dans un abonnement (flatrate), sinon à la location/achat
const providers = frProviders.flatrate || frProviders.buy || frProviders.rent || [];
if (providers.length > 0) {
streaming = providers.join(', ');
// Extrait les noms des plateformes trouvées (ex: Netflix, Canal+, Disney Plus)
const names = providers.map(p => p.provider_name);
// On supprime les doublons potentiels et on limite aux 3 premières pour l'affichage
const uniqueNames = [...new Set(names)].slice(0, 3);
streamingInfo = `Disponible sur : ${uniqueNames.join(', ')}`;
}
}
} catch (e) {
console.error("Erreur fournisseurs streaming:", e);
} catch (watchErr) {
console.error("Erreur watch providers TMDB:", watchErr);
}
return { poster, streaming };
return { poster: posterPath, streaming: streamingInfo };
}
} catch (e) {
console.error("Erreur recherche TMDB:", e);
console.error("Erreur globale fetchTmdbDetails:", e);
}
return { poster: '', streaming: streamingDefault };
}