Actualiser api.php

This commit is contained in:
2026-06-24 14:21:27 +02:00
parent 055a7636cc
commit 2b037a27a0
+7 -15
View File
@@ -105,13 +105,11 @@ function extractYear($dateStr) {
return '';
}
// ── API DVDFr (NOUVELLE APPROCHE : Scraping HTML car l'API XML est cassée) ──
// ── API DVDFr (SANS CACHE - Scraping HTML) ──
function fetchDVDFr($ean, $pdo) {
if (empty($ean) || strlen($ean) < 8) return null;
$cacheKey = 'dvdfr_new_' . md5($ean);
$cached = getCache($pdo, $cacheKey);
if ($cached) return $cached;
// 🔥 SUPPRESSION DES APPELS À getCache() QUI N'EXISTE PLUS
$ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
@@ -140,10 +138,9 @@ function fetchDVDFr($ean, $pdo) {
return null;
}
// Étape 2 : Extraire le lien vers la fiche du film depuis les résultats de recherche
// Étape 2 : Extraire le lien vers la fiche du film
$dvdUrl = null;
// Chercher le premier résultat qui correspond à l'EAN
if (preg_match('/<a[^>]+href=["\']([^"\']+\.html)["\'][^>]*class=["\'][^"\']*result[^"\']*["\'][^>]*>/i', $html, $matches)) {
$dvdUrl = $matches[1];
if (strpos($dvdUrl, 'http') !== 0) {
@@ -151,7 +148,6 @@ function fetchDVDFr($ean, $pdo) {
}
}
// Méthode alternative : chercher directement l'EAN dans le HTML
if (!$dvdUrl && preg_match('/href=["\']([^"\']*' . preg_quote($ean, '/') . '[^"\']*\.html)["\']/i', $html, $matches)) {
$dvdUrl = $matches[1];
if (strpos($dvdUrl, 'http') !== 0) {
@@ -159,7 +155,6 @@ function fetchDVDFr($ean, $pdo) {
}
}
// Méthode 3 : chercher n'importe quel lien vers une fiche DVD/Blu-ray
if (!$dvdUrl && preg_match('/<a[^>]+href=["\'](https:\/\/www\.dvdfr\.com\/(?:dvd|blu-ray)\/[^"\']+\.html)["\']/i', $html, $matches)) {
$dvdUrl = $matches[1];
}
@@ -193,7 +188,7 @@ function fetchDVDFr($ean, $pdo) {
return null;
}
// Étape 4 : Extraire les données depuis le HTML de la fiche
// Étape 4 : Extraire les données depuis le HTML
$result = [
'poster' => '',
'publisher' => '',
@@ -203,7 +198,7 @@ function fetchDVDFr($ean, $pdo) {
'discs' => '',
];
// Extraction de l'affiche (jaquette)
// 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)) {
@@ -217,7 +212,7 @@ function fetchDVDFr($ean, $pdo) {
$result['publisher'] = trim(strip_tags($matches[1]));
}
// Extraction du format (Blu-ray, DVD, 4K, etc.)
// 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) {
@@ -251,10 +246,7 @@ function fetchDVDFr($ean, $pdo) {
return trim(strip_tags(html_entity_decode($val, ENT_QUOTES | ENT_HTML5, 'UTF-8')));
}, $result);
// Mise en cache si on a au moins une donnée
if (!empty($result['poster']) || !empty($result['publisher'])) {
setCache($pdo, $cacheKey, $result, 'dvdfr');
}
// 🔥 SUPPRESSION DE L'APPEL À setCache() QUI N'EXISTE PLUS
return (!empty($result['poster']) || !empty($result['publisher'])) ? $result : null;
}