Actualiser api.php
This commit is contained in:
@@ -189,31 +189,71 @@ function fetchDVDFr($ean, $pdo) {
|
||||
}
|
||||
|
||||
// Étape 4 : Extraire les données depuis le HTML
|
||||
$result = [
|
||||
$result = [
|
||||
'poster' => '',
|
||||
'publisher' => '',
|
||||
'format' => '',
|
||||
'length' => '',
|
||||
'aspect' => '',
|
||||
'discs' => '',
|
||||
];
|
||||
];
|
||||
|
||||
// Extraction de l'affiche
|
||||
if (preg_match('/<img[^>]+class=["\'][^"\']*cover[^"\']*["\'][^>]+src=["\']([^"\']+)["\']/i', $ficheHtml, $matches)) {
|
||||
$result['poster'] = $matches[1];
|
||||
} elseif (preg_match('/<img[^>]+alt=["\'][^"\']*(?:jaquette|cover|pochette)[^"\']*["\'][^>]+src=["\']([^"\']+)["\']/i', $ficheHtml, $matches)) {
|
||||
$result['poster'] = $matches[1];
|
||||
} elseif (preg_match('/src=["\']([^"\']+(?:cover|jaquette|pochette)[^"\']*\.(?:jpg|png|webp))["\']/i', $ficheHtml, $matches)) {
|
||||
$result['poster'] = $matches[1];
|
||||
// 🔥 EXTRACTION ROBUSTE DE L'AFFICHE (plusieurs méthodes fallback)
|
||||
// Méthode 1 : Chercher toutes les images et filtrer par taille/URL
|
||||
preg_match_all('/<img[^>]+src=["\']([^"\']+)["\'][^>]*>/i', $ficheHtml, $allImages);
|
||||
if (!empty($allImages[1])) {
|
||||
foreach ($allImages[1] as $imgUrl) {
|
||||
// Filtrer les images qui ressemblent à une jaquette
|
||||
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
|
||||
if (preg_match('/(?:éditeur|distributeur|studio)\s*[:<\/]>\s*([^<]+)/i', $ficheHtml, $matches)) {
|
||||
// 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)) {
|
||||
$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
|
||||
if (preg_match('/(4k\s*ultra\s*hd|ultra\s*hd|blu[\s-]?ray|dvd|coffret)/i', $ficheHtml, $matches)) {
|
||||
// Extraction du format
|
||||
if (preg_match('/(4k\s*ultra\s*hd|ultra\s*hd|blu[\s-]?ray|dvd|coffret)/i', $ficheHtml, $matches)) {
|
||||
$format = strtoupper(trim($matches[1]));
|
||||
if (strpos($format, '4K') !== false || strpos($format, 'ULTRA') !== false) {
|
||||
$result['format'] = '4K Ultra HD';
|
||||
@@ -224,31 +264,32 @@ function fetchDVDFr($ean, $pdo) {
|
||||
} elseif (strpos($format, 'COFFRET') !== false) {
|
||||
$result['format'] = 'Coffret';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Extraction de la durée
|
||||
if (preg_match('/(?:durée|duree|duration)\s*[:<\/]>\s*(\d+)\s*(?:min|mn|h)/i', $ficheHtml, $matches)) {
|
||||
// Extraction de la durée
|
||||
if (preg_match('/(?:durée|duree|duration)\s*[:<\/]>\s*(\d+)\s*(?:min|mn|h)/i', $ficheHtml, $matches)) {
|
||||
$result['length'] = trim($matches[1]) . ' min';
|
||||
}
|
||||
}
|
||||
|
||||
// Extraction de l'aspect ratio
|
||||
if (preg_match('/(?:format\s*image|aspect\s*ratio|ratio)\s*[:<\/]>\s*([0-9.]+\s*[:\.]\s*[0-9.]+)/i', $ficheHtml, $matches)) {
|
||||
// Extraction de l'aspect ratio
|
||||
if (preg_match('/(?:format\s*image|aspect\s*ratio|ratio)\s*[:<\/]>\s*([0-9.]+\s*[:\.]\s*[0-9.]+)/i', $ficheHtml, $matches)) {
|
||||
$result['aspect'] = trim($matches[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// Extraction du nombre de disques
|
||||
if (preg_match('/(?:nombre\s*de\s*disques?|disques?|nb\s*disques?)\s*[:<\/]>\s*(\d+)/i', $ficheHtml, $matches)) {
|
||||
// Extraction du nombre de disques
|
||||
if (preg_match('/(?:nombre\s*de\s*disques?|disques?|nb\s*disques?)\s*[:<\/]>\s*(\d+)/i', $ficheHtml, $matches)) {
|
||||
$result['discs'] = trim($matches[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// Nettoyage des données
|
||||
$result = array_map(function($val) {
|
||||
// Nettoyage des données
|
||||
$result = array_map(function($val) {
|
||||
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;
|
||||
}
|
||||
|
||||
// ── 2. API TMDB (SANS CACHE - TITRE FRANÇAIS) ──
|
||||
|
||||
Reference in New Issue
Block a user