diff --git a/api.php b/api.php index 16cd1ea..ff1f9f8 100644 --- a/api.php +++ b/api.php @@ -89,80 +89,49 @@ function fetchTmdbData($title, $year, $apiKey) { $searchUrl = "https://api.themoviedb.org/3/search/movie?api_key={$apiKey}&query=" . urlencode($title) . "&year={$year}&language=fr-FR"; $searchRes = @file_get_contents($searchUrl); if (!$searchRes && function_exists('curl_init')) { - $ch = curl_init($searchUrl); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_TIMEOUT, 5); - $searchRes = curl_exec($ch); - curl_close($ch); + $ch = curl_init($searchUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 5); $searchRes = curl_exec($ch); curl_close($ch); } if (!$searchRes) return null; $searchData = json_decode($searchRes, true); if (empty($searchData['results'])) return null; + $movie = $searchData['results'][0]; $movieId = $movie['id']; $poster = !empty($movie['poster_path']) ? "https://image.tmdb.org/t/p/w500" . $movie['poster_path'] : ''; + // Récupération Réalisateur $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')) { - $ch = curl_init($creditsUrl); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_TIMEOUT, 5); - $creditsRes = curl_exec($ch); - curl_close($ch); + $ch = curl_init($creditsUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 5); $creditsRes = curl_exec($ch); curl_close($ch); } $director = ''; if ($creditsRes) { $creditsData = json_decode($creditsRes, true); if (!empty($creditsData['crew'])) { foreach ($creditsData['crew'] as $crew) { - if ($crew['job'] === 'Director' || $crew['job'] === 'Directing') { - $director = $crew['name']; - break; - } + if ($crew['job'] === 'Director' || $crew['job'] === 'Directing') { $director = $crew['name']; break; } } } } - // 🎬 NOUVEAU : Récupération des plateformes de streaming (France) + // 🎬 Récupération 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); + $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($frProviders['flatrate'])) { foreach ($frProviders['flatrate'] as $p) $platforms[] = $p['provider_name']; } 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)); + if (!empty($frProviders['rent'])) { foreach ($frProviders['rent'] as $p) $platforms[] = $p['provider_name'] . ' (loc.)'; } + 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];