Actualiser api.php

This commit is contained in:
2026-06-19 14:37:41 +02:00
parent 37af023c3e
commit 01442282c2
+44 -1
View File
@@ -101,6 +101,7 @@ function fetchTmdbData($title, $year, $apiKey) {
$movie = $searchData['results'][0]; $movie = $searchData['results'][0];
$movieId = $movie['id']; $movieId = $movie['id'];
$poster = !empty($movie['poster_path']) ? "https://image.tmdb.org/t/p/w500" . $movie['poster_path'] : ''; $poster = !empty($movie['poster_path']) ? "https://image.tmdb.org/t/p/w500" . $movie['poster_path'] : '';
$creditsUrl = "https://api.themoviedb.org/3/movie/{$movieId}/credits?api_key={$apiKey}&language=fr-FR"; $creditsUrl = "https://api.themoviedb.org/3/movie/{$movieId}/credits?api_key={$apiKey}&language=fr-FR";
$creditsRes = @file_get_contents($creditsUrl); $creditsRes = @file_get_contents($creditsUrl);
if (!$creditsRes && function_exists('curl_init')) { if (!$creditsRes && function_exists('curl_init')) {
@@ -122,7 +123,49 @@ function fetchTmdbData($title, $year, $apiKey) {
} }
} }
} }
return ['director' => $director, 'poster' => $poster];
// 🎬 NOUVEAU : Récupération des plateformes de streaming (France)
$streaming = '';
$watchUrl = "https://api.themoviedb.org/3/movie/{$movieId}/watch/providers?api_key={$apiKey}";
$watchRes = @file_get_contents($watchUrl);
if (!$watchRes && function_exists('curl_init')) {
$ch = curl_init($watchUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$watchRes = curl_exec($ch);
curl_close($ch);
}
if ($watchRes) {
$watchData = json_decode($watchRes, true);
$frProviders = $watchData['results']['FR'] ?? [];
$platforms = [];
// On récupère les plateformes d'abonnement (flatrate) en priorité
if (!empty($frProviders['flatrate'])) {
foreach ($frProviders['flatrate'] as $p) {
$platforms[] = $p['provider_name'];
}
}
// Puis location (rent) et achat (buy) si pas de flatrate
if (empty($platforms)) {
if (!empty($frProviders['rent'])) {
foreach ($frProviders['rent'] as $p) {
$platforms[] = $p['provider_name'] . ' (location)';
}
}
if (!empty($frProviders['buy'])) {
foreach ($frProviders['buy'] as $p) {
$platforms[] = $p['provider_name'] . ' (achat)';
}
}
}
if (!empty($platforms)) {
$streaming = implode(', ', array_unique($platforms));
}
}
return ['director' => $director, 'poster' => $poster, 'streaming' => $streaming];
} }
// ── ROUTEUR PRINCIPAL ── // ── ROUTEUR PRINCIPAL ──