Actualiser api.php
This commit is contained in:
@@ -120,7 +120,7 @@ function extractYear($dateStr) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Fanart.tv API (Jaquettes DVD/Blu-ray françaises uniquement) ──
|
// ── Fanart.tv API (Jaquettes exclusives) ──
|
||||||
function fetchFanartTv($title, $year = '', $format = 'bluray', $pdo = null) {
|
function fetchFanartTv($title, $year = '', $format = 'bluray', $pdo = null) {
|
||||||
if (empty($title)) return null;
|
if (empty($title)) return null;
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ function fetchFanartTv($title, $year = '', $format = 'bluray', $pdo = null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Étape 1 : Chercher le film sur TMDB pour obtenir son ID
|
// 1. Récupération silencieuse de l'ID via TMDB
|
||||||
$tmdbKey = getTmdbApiKey($pdo);
|
$tmdbKey = getTmdbApiKey($pdo);
|
||||||
if (!$tmdbKey) {
|
if (!$tmdbKey) {
|
||||||
error_log("Fanart.tv: Clé TMDB requise");
|
error_log("Fanart.tv: Clé TMDB requise");
|
||||||
@@ -156,71 +156,49 @@ function fetchFanartTv($title, $year = '', $format = 'bluray', $pdo = null) {
|
|||||||
|
|
||||||
if (empty($searchData['results'])) {
|
if (empty($searchData['results'])) {
|
||||||
error_log("Fanart.tv: Film non trouvé sur TMDB pour '$title'");
|
error_log("Fanart.tv: Film non trouvé sur TMDB pour '$title'");
|
||||||
return null;
|
// Verrouillage : TMDB ne le trouve pas, on force l'image par défaut
|
||||||
|
return ['poster' => 'assets/img/default_physical_media.jpg', 'title' => $cleanTitle, 'format' => $format];
|
||||||
}
|
}
|
||||||
|
|
||||||
$tmdbId = $searchData['results'][0]['id'];
|
$tmdbId = $searchData['results'][0]['id'];
|
||||||
|
$poster = null; // Initialisation stricte
|
||||||
|
|
||||||
// Étape 2 : Récupérer les artworks depuis fanart.tv
|
// 2. Interrogation exclusive de Fanart.tv avec l'ID obtenu
|
||||||
$fanartUrl = "https://webservice.fanart.tv/v3/movies/{$tmdbId}?api_key={$apiKey}";
|
$fanartUrl = "https://webservice.fanart.tv/v3/movies/{$tmdbId}?api_key={$apiKey}";
|
||||||
$fanartRes = httpGet($fanartUrl, 5);
|
$fanartRes = httpGet($fanartUrl, 5);
|
||||||
$fanartData = $fanartRes ? json_decode($fanartRes, true) : [];
|
$fanartData = $fanartRes ? json_decode($fanartRes, true) : [];
|
||||||
|
|
||||||
if (isset($fanartData['error'])) {
|
if (!isset($fanartData['error']) && !empty($fanartData['movieposter'])) {
|
||||||
error_log("Fanart.tv: Erreur API - " . $fanartData['error']);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$poster = '';
|
|
||||||
|
|
||||||
// PRIORITÉ 1 : movieposter en français (jaquettes DVD/Blu-ray FR)
|
|
||||||
if (!empty($fanartData['movieposter'])) {
|
|
||||||
$posters = $fanartData['movieposter'];
|
$posters = $fanartData['movieposter'];
|
||||||
|
|
||||||
// Filtrer uniquement les jaquettes françaises
|
// PRIORITÉ 1 : Français
|
||||||
$frenchPosters = array_filter($posters, function($p) {
|
$frenchPosters = array_filter($posters, function($p) { return isset($p['lang']) && $p['lang'] === 'fr'; });
|
||||||
return isset($p['lang']) && $p['lang'] === 'fr';
|
|
||||||
});
|
|
||||||
|
|
||||||
// Trier par likes (le plus populaire en premier)
|
|
||||||
if (!empty($frenchPosters)) {
|
if (!empty($frenchPosters)) {
|
||||||
usort($frenchPosters, function($a, $b) {
|
usort($frenchPosters, function($a, $b) { return ($b['likes'] ?? 0) - ($a['likes'] ?? 0); });
|
||||||
return ($b['likes'] ?? 0) - ($a['likes'] ?? 0);
|
|
||||||
});
|
|
||||||
$poster = $frenchPosters[0]['url'];
|
$poster = $frenchPosters[0]['url'];
|
||||||
error_log("Fanart.tv: Jaquette FR trouvée - {$poster}");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// PRIORITÉ 2 : Si pas de jaquette FR, prendre movieposter en anglais
|
|
||||||
if (empty($poster) && !empty($fanartData['movieposter'])) {
|
|
||||||
$posters = $fanartData['movieposter'];
|
|
||||||
$englishPosters = array_filter($posters, function($p) {
|
|
||||||
return isset($p['lang']) && $p['lang'] === 'en';
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!empty($englishPosters)) {
|
// PRIORITÉ 2 : Anglais (fallback)
|
||||||
usort($englishPosters, function($a, $b) {
|
if (empty($poster)) {
|
||||||
return ($b['likes'] ?? 0) - ($a['likes'] ?? 0);
|
$englishPosters = array_filter($posters, function($p) { return isset($p['lang']) && $p['lang'] === 'en'; });
|
||||||
});
|
if (!empty($englishPosters)) {
|
||||||
$poster = $englishPosters[0]['url'];
|
usort($englishPosters, function($a, $b) { return ($b['likes'] ?? 0) - ($a['likes'] ?? 0); });
|
||||||
error_log("Fanart.tv: Jaquette EN trouvée (fallback) - {$poster}");
|
$poster = $englishPosters[0]['url'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PRIORITÉ 3 : N'importe quelle langue
|
||||||
|
if (empty($poster)) {
|
||||||
|
usort($posters, function($a, $b) { return ($b['likes'] ?? 0) - ($a['likes'] ?? 0); });
|
||||||
|
$poster = $posters[0]['url'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PRIORITÉ 3 : Fallback sur n'importe quelle langue
|
// 3. Verrouillage final
|
||||||
if (empty($poster) && !empty($fanartData['movieposter'])) {
|
|
||||||
$posters = $fanartData['movieposter'];
|
|
||||||
usort($posters, function($a, $b) {
|
|
||||||
return ($b['likes'] ?? 0) - ($a['likes'] ?? 0);
|
|
||||||
});
|
|
||||||
$poster = $posters[0]['url'];
|
|
||||||
error_log("Fanart.tv: Jaquette trouvée (toute langue) - {$poster}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($poster)) {
|
if (empty($poster)) {
|
||||||
error_log("Fanart.tv: Aucune jaquette trouvée pour TMDB ID {$tmdbId}");
|
error_log("Fanart.tv: Aucune jaquette trouvée pour TMDB ID {$tmdbId}");
|
||||||
return null;
|
// AUCUN retour vers TMDB, on force l'image locale
|
||||||
|
$poster = 'assets/img/default_physical_media.jpg';
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|||||||
Reference in New Issue
Block a user