Actualiser js/admin.js
This commit is contained in:
+30
-22
@@ -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();
|
||||
|
||||
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 || [];
|
||||
|
||||
// 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 (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 };
|
||||
}
|
||||
Reference in New Issue
Block a user