From 01442282c2f90235df8fe5477e228b9bb9ccee8c Mon Sep 17 00:00:00 2001 From: Cedric Date: Fri, 19 Jun 2026 14:37:41 +0200 Subject: [PATCH] Actualiser api.php --- api.php | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/api.php b/api.php index ad3a74b..3ea6b93 100644 --- a/api.php +++ b/api.php @@ -101,6 +101,7 @@ function fetchTmdbData($title, $year, $apiKey) { $movie = $searchData['results'][0]; $movieId = $movie['id']; $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"; $creditsRes = @file_get_contents($creditsUrl); 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 ──