From 52d0eb520c7bd2473bc1f69889350f5bd6f88066 Mon Sep 17 00:00:00 2001 From: Cedric Date: Tue, 23 Jun 2026 15:11:52 +0200 Subject: [PATCH] Actualiser api.php --- api.php | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/api.php b/api.php index edd8e3b..08d5acf 100644 --- a/api.php +++ b/api.php @@ -137,6 +137,34 @@ function fetchUPCitemdb($ean, $pdo) { return null; } +// ── 1.5 API DVDFr (Spécial Jaquettes Physiques FR) ── +function fetchDVDFr($ean, $pdo) { + if (empty($ean) || strlen($ean) < 8) return null; + $cacheKey = 'dvdfr_' . md5($ean); + + $cached = getCache($pdo, $cacheKey); + if ($cached) return $cached; + + $url = "https://www.dvdfr.com/api/search.php?gencode=" . urlencode($ean); + $res = httpGet($url, 5); + if (!$res) return null; + + try { + // DVDFr renvoie du XML, on le parse silencieusement (@) + $xml = @simplexml_load_string($res); + if ($xml && isset($xml->dvd) && isset($xml->dvd[0]->cover)) { + $poster = (string)$xml->dvd[0]->cover; + if (!empty($poster)) { + setCache($pdo, $cacheKey, $poster, 'dvdfr'); + return $poster; + } + } + } catch (\Exception $e) { + return null; + } + return null; +} + // ── 2. API TMDB (Full Extract avec Synopsis et Acteurs) ── function fetchTMDBFull($title, $year, $apiKey, $pdo) { if (empty($apiKey) || empty($title)) return null; @@ -279,7 +307,7 @@ switch ($action) { 'poster' => '', 'publisher' => '', 'format' => '', 'length' => '', 'number_of_discs' => 1, 'aspect_ratio' => '', 'actors' => '' ]; - $upcData = fetchUPCitemdb($ean, $pdo); + $upcData = fetchUPCitemdb($ean, $pdo); $tmdbQueryTitle = ""; if ($upcData) { $tmdbQueryTitle = $upcData['title']; @@ -288,6 +316,12 @@ switch ($action) { $result['publisher'] = $upcData['publisher']; $result['format'] = $upcData['format']; } + + // 🔥 NOUVEAU : DVDFr pour remplacer l'affiche lors d'un ajout manuel + $dvdfrCover = fetchDVDFr($ean, $pdo); + if (!empty($dvdfrCover)) { + $result['poster'] = $dvdfrCover; + } $tmdbKey = getTmdbApiKey($pdo); if ($tmdbKey && $tmdbQueryTitle) { $tmdbData = fetchTMDBFull($tmdbQueryTitle, '', $tmdbKey, $pdo); @@ -393,7 +427,7 @@ switch ($action) { $actors = implode(', ', array_slice($actorsArray, 0, 4)); } - // 1. UPCitemDB +// 1. UPCitemDB if (!empty($ean)) { $upcData = fetchUPCitemdb($ean, $pdo); if ($upcData) { @@ -402,6 +436,12 @@ switch ($action) { if (empty($publisher)) $publisher = $upcData['publisher']; if (empty($format) || $format === 'Blu-ray') $format = $upcData['format']; } + + // 🔥 NOUVEAU : 1.5 DVDFr (Écrase l'affiche UPC avec la vraie jaquette FR) + $dvdfrCover = fetchDVDFr($ean, $pdo); + if (!empty($dvdfrCover)) { + $poster = $dvdfrCover; + } } // 2. TMDB (Écrase les données CSV avec les données officielles)