Actualiser api.php
This commit is contained in:
@@ -105,13 +105,11 @@ function extractYear($dateStr) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── API DVDFr (NOUVELLE APPROCHE : Scraping HTML car l'API XML est cassée) ──
|
// ── API DVDFr (SANS CACHE - Scraping HTML) ──
|
||||||
function fetchDVDFr($ean, $pdo) {
|
function fetchDVDFr($ean, $pdo) {
|
||||||
if (empty($ean) || strlen($ean) < 8) return null;
|
if (empty($ean) || strlen($ean) < 8) return null;
|
||||||
|
|
||||||
$cacheKey = 'dvdfr_new_' . md5($ean);
|
// 🔥 SUPPRESSION DES APPELS À getCache() QUI N'EXISTE PLUS
|
||||||
$cached = getCache($pdo, $cacheKey);
|
|
||||||
if ($cached) return $cached;
|
|
||||||
|
|
||||||
$ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
|
$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;
|
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;
|
$dvdUrl = null;
|
||||||
|
|
||||||
// Chercher le premier résultat qui correspond à l'EAN
|
|
||||||
if (preg_match('/<a[^>]+href=["\']([^"\']+\.html)["\'][^>]*class=["\'][^"\']*result[^"\']*["\'][^>]*>/i', $html, $matches)) {
|
if (preg_match('/<a[^>]+href=["\']([^"\']+\.html)["\'][^>]*class=["\'][^"\']*result[^"\']*["\'][^>]*>/i', $html, $matches)) {
|
||||||
$dvdUrl = $matches[1];
|
$dvdUrl = $matches[1];
|
||||||
if (strpos($dvdUrl, 'http') !== 0) {
|
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)) {
|
if (!$dvdUrl && preg_match('/href=["\']([^"\']*' . preg_quote($ean, '/') . '[^"\']*\.html)["\']/i', $html, $matches)) {
|
||||||
$dvdUrl = $matches[1];
|
$dvdUrl = $matches[1];
|
||||||
if (strpos($dvdUrl, 'http') !== 0) {
|
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)) {
|
if (!$dvdUrl && preg_match('/<a[^>]+href=["\'](https:\/\/www\.dvdfr\.com\/(?:dvd|blu-ray)\/[^"\']+\.html)["\']/i', $html, $matches)) {
|
||||||
$dvdUrl = $matches[1];
|
$dvdUrl = $matches[1];
|
||||||
}
|
}
|
||||||
@@ -193,7 +188,7 @@ function fetchDVDFr($ean, $pdo) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Étape 4 : Extraire les données depuis le HTML de la fiche
|
// Étape 4 : Extraire les données depuis le HTML
|
||||||
$result = [
|
$result = [
|
||||||
'poster' => '',
|
'poster' => '',
|
||||||
'publisher' => '',
|
'publisher' => '',
|
||||||
@@ -203,7 +198,7 @@ function fetchDVDFr($ean, $pdo) {
|
|||||||
'discs' => '',
|
'discs' => '',
|
||||||
];
|
];
|
||||||
|
|
||||||
// Extraction de l'affiche (jaquette)
|
// Extraction de l'affiche
|
||||||
if (preg_match('/<img[^>]+class=["\'][^"\']*cover[^"\']*["\'][^>]+src=["\']([^"\']+)["\']/i', $ficheHtml, $matches)) {
|
if (preg_match('/<img[^>]+class=["\'][^"\']*cover[^"\']*["\'][^>]+src=["\']([^"\']+)["\']/i', $ficheHtml, $matches)) {
|
||||||
$result['poster'] = $matches[1];
|
$result['poster'] = $matches[1];
|
||||||
} elseif (preg_match('/<img[^>]+alt=["\'][^"\']*(?:jaquette|cover|pochette)[^"\']*["\'][^>]+src=["\']([^"\']+)["\']/i', $ficheHtml, $matches)) {
|
} 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]));
|
$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)) {
|
if (preg_match('/(4k\s*ultra\s*hd|ultra\s*hd|blu[\s-]?ray|dvd|coffret)/i', $ficheHtml, $matches)) {
|
||||||
$format = strtoupper(trim($matches[1]));
|
$format = strtoupper(trim($matches[1]));
|
||||||
if (strpos($format, '4K') !== false || strpos($format, 'ULTRA') !== false) {
|
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')));
|
return trim(strip_tags(html_entity_decode($val, ENT_QUOTES | ENT_HTML5, 'UTF-8')));
|
||||||
}, $result);
|
}, $result);
|
||||||
|
|
||||||
// Mise en cache si on a au moins une donnée
|
// 🔥 SUPPRESSION DE L'APPEL À setCache() QUI N'EXISTE PLUS
|
||||||
if (!empty($result['poster']) || !empty($result['publisher'])) {
|
|
||||||
setCache($pdo, $cacheKey, $result, 'dvdfr');
|
|
||||||
}
|
|
||||||
|
|
||||||
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