Actualiser api.php
This commit is contained in:
@@ -198,18 +198,58 @@ function fetchDVDFr($ean, $pdo) {
|
|||||||
'discs' => '',
|
'discs' => '',
|
||||||
];
|
];
|
||||||
|
|
||||||
// Extraction de l'affiche
|
// 🔥 EXTRACTION ROBUSTE DE L'AFFICHE (plusieurs méthodes fallback)
|
||||||
if (preg_match('/<img[^>]+class=["\'][^"\']*cover[^"\']*["\'][^>]+src=["\']([^"\']+)["\']/i', $ficheHtml, $matches)) {
|
// Méthode 1 : Chercher toutes les images et filtrer par taille/URL
|
||||||
$result['poster'] = $matches[1];
|
preg_match_all('/<img[^>]+src=["\']([^"\']+)["\'][^>]*>/i', $ficheHtml, $allImages);
|
||||||
} elseif (preg_match('/<img[^>]+alt=["\'][^"\']*(?:jaquette|cover|pochette)[^"\']*["\'][^>]+src=["\']([^"\']+)["\']/i', $ficheHtml, $matches)) {
|
if (!empty($allImages[1])) {
|
||||||
$result['poster'] = $matches[1];
|
foreach ($allImages[1] as $imgUrl) {
|
||||||
} elseif (preg_match('/src=["\']([^"\']+(?:cover|jaquette|pochette)[^"\']*\.(?:jpg|png|webp))["\']/i', $ficheHtml, $matches)) {
|
// Filtrer les images qui ressemblent à une jaquette
|
||||||
$result['poster'] = $matches[1];
|
if (preg_match('/(cover|jaquette|pochette|affiche|poster|front)/i', $imgUrl) ||
|
||||||
|
preg_match('/\.(jpg|jpeg|png|webp)$/i', $imgUrl)) {
|
||||||
|
// Vérifier que c'est bien une URL complète
|
||||||
|
if (strpos($imgUrl, 'http') === 0) {
|
||||||
|
$result['poster'] = $imgUrl;
|
||||||
|
error_log("DVDFr: Affiche trouvée (méthode 1) - $imgUrl");
|
||||||
|
break;
|
||||||
|
} elseif (strpos($imgUrl, '//') === 0) {
|
||||||
|
$result['poster'] = 'https:' . $imgUrl;
|
||||||
|
error_log("DVDFr: Affiche trouvée (méthode 1b) - " . $result['poster']);
|
||||||
|
break;
|
||||||
|
} elseif (strpos($imgUrl, '/') === 0) {
|
||||||
|
$result['poster'] = 'https://www.dvdfr.com' . $imgUrl;
|
||||||
|
error_log("DVDFr: Affiche trouvée (méthode 1c) - " . $result['poster']);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extraction de l'éditeur
|
// Méthode 2 : Chercher dans les balises meta (Open Graph)
|
||||||
|
if (empty($result['poster']) && preg_match('/<meta[^>]+property=["\']og:image["\'][^>]+content=["\']([^"\']+)["\']/i', $ficheHtml, $matches)) {
|
||||||
|
$result['poster'] = $matches[1];
|
||||||
|
error_log("DVDFr: Affiche trouvée (méthode 2 - og:image) - " . $result['poster']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode 3 : Chercher dans les balises link (rel="image_src")
|
||||||
|
if (empty($result['poster']) && preg_match('/<link[^>]+rel=["\']image_src["\'][^>]+href=["\']([^"\']+)["\']/i', $ficheHtml, $matches)) {
|
||||||
|
$result['poster'] = $matches[1];
|
||||||
|
error_log("DVDFr: Affiche trouvée (méthode 3 - link image_src) - " . $result['poster']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode 4 : Chercher dans les données JSON-LD (structured data)
|
||||||
|
if (empty($result['poster']) && preg_match('/<script[^>]+type=["\']application\/ld\+json["\'][^>]*>([^<]+)<\/script>/i', $ficheHtml, $matches)) {
|
||||||
|
$jsonData = json_decode($matches[1], true);
|
||||||
|
if ($jsonData && isset($jsonData['image'])) {
|
||||||
|
$result['poster'] = is_array($jsonData['image']) ? $jsonData['image'][0] : $jsonData['image'];
|
||||||
|
error_log("DVDFr: Affiche trouvée (méthode 4 - JSON-LD) - " . $result['poster']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extraction de l'éditeur (plusieurs méthodes)
|
||||||
if (preg_match('/(?:éditeur|distributeur|studio)\s*[:<\/]>\s*([^<]+)/i', $ficheHtml, $matches)) {
|
if (preg_match('/(?:éditeur|distributeur|studio)\s*[:<\/]>\s*([^<]+)/i', $ficheHtml, $matches)) {
|
||||||
$result['publisher'] = trim(strip_tags($matches[1]));
|
$result['publisher'] = trim(strip_tags($matches[1]));
|
||||||
|
} elseif (preg_match('/<span[^>]+class=["\'][^"\']*publisher[^"\']*["\'][^>]*>([^<]+)<\/span>/i', $ficheHtml, $matches)) {
|
||||||
|
$result['publisher'] = trim(strip_tags($matches[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extraction du format
|
// Extraction du format
|
||||||
@@ -246,7 +286,8 @@ function fetchDVDFr($ean, $pdo) {
|
|||||||
return trim(strip_tags(html_entity_decode($val, ENT_QUOTES | ENT_HTML5, 'UTF-8')));
|
return trim(strip_tags(html_entity_decode($val, ENT_QUOTES | ENT_HTML5, 'UTF-8')));
|
||||||
}, $result);
|
}, $result);
|
||||||
|
|
||||||
// 🔥 SUPPRESSION DE L'APPEL À setCache() QUI N'EXISTE PLUS
|
// 🔥 LOG DE DÉBOGAGE
|
||||||
|
error_log("DVDFr: Données finales - " . json_encode($result));
|
||||||
|
|
||||||
return (!empty($result['poster']) || !empty($result['publisher'])) ? $result : null;
|
return (!empty($result['poster']) || !empty($result['publisher'])) ? $result : null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user