Actualiser api.php

This commit is contained in:
2026-07-02 16:29:33 +02:00
parent 04b8c1efa4
commit 6b046a8053
+9 -8
View File
@@ -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('/<figure[^>]*class="product-image[^"]*"[^>]*>.*?<img[^>]*src="([^"]+\.(?:jpg|jpeg|png|webp))"/is', $html, $m)) {
$empty['poster'] = trim($m[1]);
} elseif (preg_match('/<img[^>]*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('/<figure[^>]*class="product-image[^"]*"[^>]*>.*?<img[^>]*src="([^"]+\.(?:jpg|jpeg|png|webp))"/is', $html, $m)) {
$empty['poster'] = trim($m[1]);
} elseif (preg_match('/<img[^>]*src="([^"]+go-upc\.s3\.amazonaws\.com[^"]+)"/i', $html, $m)) {
$empty['poster'] = trim($m[1]);
}
if (!empty($empty['title'])) {
$empty['format'] = detectFormat($empty['title']);
}