Actualiser api.php

This commit is contained in:
2026-06-19 15:06:25 +02:00
parent b8e6ff1f7a
commit f6ed6d7512
+11 -42
View File
@@ -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"; $searchUrl = "https://api.themoviedb.org/3/search/movie?api_key={$apiKey}&query=" . urlencode($title) . "&year={$year}&language=fr-FR";
$searchRes = @file_get_contents($searchUrl); $searchRes = @file_get_contents($searchUrl);
if (!$searchRes && function_exists('curl_init')) { if (!$searchRes && function_exists('curl_init')) {
$ch = curl_init($searchUrl); $ch = curl_init($searchUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 5); $searchRes = curl_exec($ch); curl_close($ch);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$searchRes = curl_exec($ch);
curl_close($ch);
} }
if (!$searchRes) return null; if (!$searchRes) return null;
$searchData = json_decode($searchRes, true); $searchData = json_decode($searchRes, true);
if (empty($searchData['results'])) return null; if (empty($searchData['results'])) return null;
$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'] : '';
// Récupération Réalisateur
$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')) {
$ch = curl_init($creditsUrl); $ch = curl_init($creditsUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 5); $creditsRes = curl_exec($ch); curl_close($ch);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$creditsRes = curl_exec($ch);
curl_close($ch);
} }
$director = ''; $director = '';
if ($creditsRes) { if ($creditsRes) {
$creditsData = json_decode($creditsRes, true); $creditsData = json_decode($creditsRes, true);
if (!empty($creditsData['crew'])) { if (!empty($creditsData['crew'])) {
foreach ($creditsData['crew'] as $crew) { foreach ($creditsData['crew'] as $crew) {
if ($crew['job'] === 'Director' || $crew['job'] === 'Directing') { if ($crew['job'] === 'Director' || $crew['job'] === 'Directing') { $director = $crew['name']; break; }
$director = $crew['name'];
break;
}
} }
} }
} }
// 🎬 NOUVEAU : Récupération des plateformes de streaming (France) // 🎬 Récupération Streaming (France)
$streaming = ''; $streaming = '';
$watchUrl = "https://api.themoviedb.org/3/movie/{$movieId}/watch/providers?api_key={$apiKey}"; $watchUrl = "https://api.themoviedb.org/3/movie/{$movieId}/watch/providers?api_key={$apiKey}";
$watchRes = @file_get_contents($watchUrl); $watchRes = @file_get_contents($watchUrl);
if (!$watchRes && function_exists('curl_init')) { if (!$watchRes && function_exists('curl_init')) {
$ch = curl_init($watchUrl); $ch = curl_init($watchUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 5); $watchRes = curl_exec($ch); curl_close($ch);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$watchRes = curl_exec($ch);
curl_close($ch);
} }
if ($watchRes) { if ($watchRes) {
$watchData = json_decode($watchRes, true); $watchData = json_decode($watchRes, true);
$frProviders = $watchData['results']['FR'] ?? []; $frProviders = $watchData['results']['FR'] ?? [];
$platforms = []; $platforms = [];
if (!empty($frProviders['flatrate'])) { foreach ($frProviders['flatrate'] as $p) $platforms[] = $p['provider_name']; }
// 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($platforms)) {
if (!empty($frProviders['rent'])) { if (!empty($frProviders['rent'])) { foreach ($frProviders['rent'] as $p) $platforms[] = $p['provider_name'] . ' (loc.)'; }
foreach ($frProviders['rent'] as $p) { if (!empty($frProviders['buy'])) { foreach ($frProviders['buy'] as $p) $platforms[] = $p['provider_name'] . ' (achat)'; }
$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($platforms)) $streaming = implode(', ', array_unique($platforms));
} }
return ['director' => $director, 'poster' => $poster, 'streaming' => $streaming]; return ['director' => $director, 'poster' => $poster, 'streaming' => $streaming];