diff --git a/api.php b/api.php index ef1b0d7..72f58b4 100644 --- a/api.php +++ b/api.php @@ -116,7 +116,7 @@ function emptyPhysicalResult() { ]; } -// ── NOUVELLE FONCTION : SCRAPPING GO-UPC.COM (CORRIGÉE) ── +// ── NOUVELLE FONCTION : SCRAPPING GO-UPC.COM (MODIFIÉE) ── function fetchFromGoUpc($ean) { $empty = emptyPhysicalResult(); $url = "https://go-upc.com/search?q=" . urlencode($ean); @@ -132,6 +132,14 @@ function fetchFromGoUpc($ean) { $empty['title'] = $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'); @@ -157,13 +165,6 @@ function fetchFromGoUpc($ean) { $empty['title'] = trim($empty['title']); } - // ✅ RÉCUPÉRATION DE L'IMAGE DEPUIS GO-UPC - 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]); - } - if (!empty($empty['title'])) { $empty['format'] = detectFormat($empty['title']); }