From 04b8c1efa44ac7e4bc0451c595f8cc609e62280c Mon Sep 17 00:00:00 2001 From: Cedric Date: Thu, 2 Jul 2026 16:17:05 +0200 Subject: [PATCH] Actualiser api.php --- api.php | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/api.php b/api.php index 752eba0..ef1b0d7 100644 --- a/api.php +++ b/api.php @@ -116,7 +116,7 @@ function emptyPhysicalResult() { ]; } -// ── NOUVELLE FONCTION : SCRAPPING GO-UPC.COM (MODIFIÉE) ── +// ── NOUVELLE FONCTION : SCRAPPING GO-UPC.COM (CORRIGÉE) ── function fetchFromGoUpc($ean) { $empty = emptyPhysicalResult(); $url = "https://go-upc.com/search?q=" . urlencode($ean); @@ -132,20 +132,38 @@ function fetchFromGoUpc($ean) { $empty['title'] = $title; } + // ✅ NETTOYAGE DU TITRE + if (!empty($empty['title'])) { + $empty['title'] = html_entity_decode($empty['title'], ENT_QUOTES | ENT_HTML5, 'UTF-8'); + + // ✅ APPLIQUER cleanTitle() pour supprimer les suffixes comme "- DVD", "- Édition Collector" + $empty['title'] = cleanTitle($empty['title']); + + // ✅ Supprimer le nom du réalisateur au début si présent + // Pattern : "Prénom Nom Titre du film" → "Titre du film" + // Exemple : "Lilly Wachowski Matrix" → "Matrix" + // Exemple : "Andrew Niccol Lord Of War" → "Lord Of War" + if (preg_match('/^([A-Z][a-z]+\s+[A-Z][a-z]+)\s+(.+)$/u', $empty['title'], $nameMatch)) { + $possibleDirector = $nameMatch[1]; + $possibleTitle = $nameMatch[2]; + + // Vérifier si le "titre" restant semble être un vrai titre (pas juste un mot) + if (strlen($possibleTitle) > 3 && !preg_match('/^(DVD|Blu-ray|4K|VHS|CD|Vinyl)$/i', $possibleTitle)) { + $empty['director'] = $possibleDirector; + $empty['title'] = $possibleTitle; + } + } + + $empty['title'] = trim($empty['title']); + } + // ✅ RÉCUPÉRATION DE L'IMAGE DEPUIS GO-UPC - // Chercher dans les figures product-image if (preg_match('/]*class="product-image[^"]*"[^>]*>.*?]*src="([^"]+\.(?:jpg|jpeg|png|webp))"/is', $html, $m)) { $empty['poster'] = trim($m[1]); } elseif (preg_match('/]*src="([^"]+go-upc\.s3\.amazonaws\.com[^"]+)"/i', $html, $m)) { $empty['poster'] = trim($m[1]); } - // Nettoyage du titre - if (!empty($empty['title'])) { - $empty['title'] = html_entity_decode($empty['title'], ENT_QUOTES | ENT_HTML5, 'UTF-8'); - $empty['title'] = trim($empty['title']); - } - if (!empty($empty['title'])) { $empty['format'] = detectFormat($empty['title']); }