From 325a6df04e47a6767fa6f6bfcd65ff18b74fca2a Mon Sep 17 00:00:00 2001 From: Cedric Date: Wed, 24 Jun 2026 11:16:45 +0200 Subject: [PATCH] Actualiser api.php --- api.php | 59 +++++++++++++++++++++++++-------------------------------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/api.php b/api.php index 161f094..d2bb717 100644 --- a/api.php +++ b/api.php @@ -63,19 +63,13 @@ function getTmdbApiKey($pdo) { return $row ? decryptData($row['key_value']) : null; } -function httpGet($url, $timeout = 2) { // đŸ”„ RĂ©duit Ă  2 secondes par dĂ©faut - if (!function_exists('curl_init')) { - $ctx = stream_context_create(['http' => ['timeout' => $timeout, 'user_agent' => 'MonCinema/5.0']]); - return @file_get_contents($url, false, $ctx); - } +function httpGet($url, $timeout = 5) { $ch = curl_init($url); curl_setopt_array($ch, [ - CURLOPT_RETURNTRANSFER => true, - CURLOPT_TIMEOUT => $timeout, - CURLOPT_CONNECTTIMEOUT => 2, // đŸ”„ N'attend pas plus de 2s pour la connexion - CURLOPT_SSL_VERIFYPEER => false, - CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) MonCinema/5.0', // đŸ”„ User-Agent standard - CURLOPT_FOLLOWLOCATION => true + CURLOPT_RETURNTRANSFER => true, + CURLOPT_TIMEOUT => $timeout, + CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', + CURLOPT_SSL_VERIFYPEER => false ]); $res = curl_exec($ch); curl_close($ch); @@ -122,28 +116,29 @@ function extractYear($dateStr) { function fetchDVDFr($ean, $pdo) { - if (empty($ean)) return null; + if (empty($ean) || strlen($ean) < 8) return null; $cacheKey = 'dvdfr_full_' . md5($ean); $cached = getCache($pdo, $cacheKey); if ($cached) return $cached; - - // RĂ©cupĂ©ration de la page + $url = "https://www.dvdfr.com/api/search.php?gencode=" . urlencode($ean); - $res = httpGet($url, 10); - if (!$res) return null; - + $res = httpGet($url, 10); // AugmentĂ© Ă  10s pour Ă©viter les timeouts + if (!$res) { + file_put_contents('dvdfr_error.log', "Échec requĂȘte pour EAN: $ean"); + return null; + } + try { $xml = @simplexml_load_string($res); if ($xml && isset($xml->dvd[0])) { - $dvd = $xml->dvd[0]; - - // Extraction des donnĂ©es + $d = $xml->dvd[0]; + // On extrait tout ce que DVDfr nous donne $data = [ - 'poster' => (string)$dvd->cover, - 'title' => (string)$dvd->title, - 'director' => (string)$dvd->directors->director->name, - 'actors' => '', // DVDFr API est limitĂ©e sur les acteurs, souvent vide - 'year' => (string)$dvd->year + 'poster' => (string)$d->cover, + 'format' => (string)$d->media, + 'publisher' => (string)$d->editor, + 'length' => (string)$d->duration, + 'aspect' => (string)$d->ratio ]; setCache($pdo, $cacheKey, $data, 'dvdfr'); @@ -449,16 +444,14 @@ case 'import_batch': $poster = $rowData['poster'] ?? ''; $director = ''; - // 1.5 DVDFr : rĂ©cupĂ©ration complĂšte des mĂ©tadonnĂ©es via EAN + // Remplacez votre bloc de gestion DVDFr actuel par ceci : $dvdfrData = fetchDVDFr($ean, $pdo); if (!empty($dvdfrData)) { - // RĂ©cupĂ©ration de TOUS les champs retournĂ©s par DVDfr - if (!empty($dvdfrData['poster'])) $poster = $dvdfrData['poster']; - if (!empty($dvdfrData['publisher'])) $publisher = $dvdfrData['publisher']; - if (!empty($dvdfrData['format'])) $format = $dvdfrData['format']; - if (!empty($dvdfrData['length'])) $length = $dvdfrData['length']; - if (!empty($dvdfrData['aspect'])) $aspect = $dvdfrData['aspect']; - if (!empty($dvdfrData['discs'])) $discs = (int)$dvdfrData['discs']; + if (empty($poster) && !empty($dvdfrData['poster'])) $poster = $dvdfrData['poster']; + if (empty($format) && !empty($dvdfrData['format'])) $format = $dvdfrData['format']; + if (empty($publisher) && !empty($dvdfrData['publisher'])) $publisher = $dvdfrData['publisher']; + if (empty($length) && !empty($dvdfrData['length'])) $length = $dvdfrData['length']; + if (empty($aspect) && !empty($dvdfrData['aspect'])) $aspect = $dvdfrData['aspect']; } // 2. TMDB (DonnĂ©es Officielles & Synopsis)