From e6d0c99a0765a50d0e7d4e1df3679e8d9903031e Mon Sep 17 00:00:00 2001 From: Cedric Date: Wed, 24 Jun 2026 12:57:18 +0200 Subject: [PATCH] Actualiser api.php --- api.php | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/api.php b/api.php index 404951f..970248a 100644 --- a/api.php +++ b/api.php @@ -100,9 +100,14 @@ function extractYear($dateStr) { function fetchDVDFr($ean, $pdo) { if (empty($ean) || strlen($ean) < 8) return null; + $cacheKey = 'dvdfr_' . md5($ean); + $cached = getCache($pdo, $cacheKey); + if ($cached) return $cached; + + // DVDFr exige un User-Agent propre $ua = 'MonCinema/1.0 (collection privée; contact@moncineapp.fr)'; - // Étape 1 : recherche par gencode + // Étape 1 : recherche par gencode → récupère l'id DVDFr $searchUrl = "https://www.dvdfr.com/api/search.php?gencode=" . urlencode($ean); $ch = curl_init($searchUrl); curl_setopt_array($ch, [ @@ -126,7 +131,7 @@ function fetchDVDFr($ean, $pdo) { $dvdId = (string)$xml->dvd[0]->id; if (empty($dvdId)) return null; - // Étape 2 : fiche complète + // Étape 2 : fiche complète via dvd.php?id= $ficheUrl = "https://www.dvdfr.com/api/dvd.php?id=" . urlencode($dvdId); $ch2 = curl_init($ficheUrl); curl_setopt_array($ch2, [ @@ -149,19 +154,36 @@ function fetchDVDFr($ean, $pdo) { $dvd = $fiche->dvd[0]; + // 🔥 Extraction de la jaquette (CORRECTION) $poster = ''; - if (isset($dvd->cover)) $poster = (string)$dvd->cover; - if (empty($poster) && isset($dvd->covers->cover[0])) $poster = (string)$dvd->covers->cover[0]; + // Méthode 1 : cover directe + if (isset($dvd->cover)) { + $poster = (string)$dvd->cover; // ✅ CORRECTION ICI + } + // Méthode 2 : covers->cover[0] + if (empty($poster) && isset($dvd->covers->cover[0])) { + $poster = (string)$dvd->covers->cover[0]; + } + // Méthode 3 : image directe + if (empty($poster) && isset($dvd->image)) { + $poster = (string)$dvd->image; + } + // Extraction des métadonnées techniques $result = [ - 'poster' => $poster, - 'publisher' => isset($dvd->editeur) ? (string)$dvd->editeur : '', - 'format' => isset($dvd->type) ? (string)$dvd->type : '', - 'length' => isset($dvd->duree) ? (string)$dvd->duree : '', - 'aspect' => isset($dvd->formatimage) ? (string)$dvd->formatimage : '', - 'discs' => isset($dvd->nbdisques) ? (string)$dvd->nbdisques : '', + 'poster' => $poster, + 'publisher' => isset($dvd->editeur) ? (string)$dvd->editeur : '', + 'format' => isset($dvd->type) ? (string)$dvd->type : '', + 'length' => isset($dvd->duree) ? (string)$dvd->duree : '', + 'aspect' => isset($dvd->formatimage) ? (string)$dvd->formatimage : '', + 'discs' => isset($dvd->nbdisques) ? (string)$dvd->nbdisques : '', ]; + // Ne met en cache que si on a au moins une affiche ou un éditeur + if (!empty($result['poster']) || !empty($result['publisher'])) { + setCache($pdo, $cacheKey, $result, 'dvdfr'); + } + return !empty($result['poster']) || !empty($result['publisher']) ? $result : null; }