diff --git a/api.php b/api.php index 69b483e..749d56a 100644 --- a/api.php +++ b/api.php @@ -419,7 +419,6 @@ function fetchFromBlurayCom($ean) { 'publisher' => '', 'format' => 'Blu-ray', 'number_of_discs' => 1, 'aspect_ratio' => '' ]; - $ean = preg_replace('/[^0-9]/', '', (string)$ean); if (strlen($ean) < 8) { error_log("Blu-ray.com: ❌ EAN invalide: $ean"); @@ -436,8 +435,6 @@ function fetchFromBlurayCom($ean) { $lastRequest = microtime(true); error_log("Blu-ray.com: 🔍 Recherche EAN $ean"); - - // Recherche par EAN $searchUrl = "https://www.blu-ray.com/movies/search.php?ean=" . urlencode($ean) . "&action=search"; $ch = curl_init($searchUrl); curl_setopt_array($ch, [ @@ -453,7 +450,6 @@ function fetchFromBlurayCom($ean) { 'Referer: https://www.blu-ray.com/' ] ]); - $searchHtml = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $curlError = curl_error($ch); @@ -464,20 +460,17 @@ function fetchFromBlurayCom($ean) { return $empty; } - // Extraire l'URL du film - regex améliorée + // Extraire l'URL du film if (!preg_match('/href="(https:\/\/www\.blu-ray\.com\/movies\/[^"]+\/(\d+)\/)"/i', $searchHtml, $matches)) { error_log("Blu-ray.com: ❌ Film non trouvé pour EAN $ean"); return $empty; } - $movieUrl = $matches[1]; $movieId = $matches[2]; error_log("Blu-ray.com: ✅ Film trouvé → $movieUrl"); - // Délai avant la 2ème requête - sleep(2); + sleep(2); // Délai avant la 2ème requête - // Récupérer la page du film $ch2 = curl_init($movieUrl); curl_setopt_array($ch2, [ CURLOPT_RETURNTRANSFER => true, @@ -491,7 +484,6 @@ function fetchFromBlurayCom($ean) { 'Referer: https://www.blu-ray.com/' ] ]); - $movieHtml = curl_exec($ch2); curl_close($ch2); @@ -500,26 +492,19 @@ function fetchFromBlurayCom($ean) { return $empty; } - // Extraction des données - regex robustes face à la refonte du site - // (le site a été redesigné : le
([^<]+)<\/PRE>/is', $html, $m)) {
+ $idmc = trim($m[1]);
+ } elseif (preg_match('/ 5000) { // Vérifie que c'est une vraie image (>5Ko)
+ $empty['poster'] = $hd_url;
+ break;
+ }
+ }
+ }
+
+ // Fallback sur le thumbnail si pas d'image HD trouvée
+ if (empty($empty['poster'])) {
+ // CORRECTION : La regex gère le cas où title= est avant src=
+ if (preg_match('/
]*title="Recto[^"]*"[^>]*src="([^"]+)"/i', $html, $m)) {
+ $empty['poster'] = $m[1];
+ } elseif (preg_match('/
]*src="([^"]+)"[^>]*title="Recto/i', $html, $m)) {
+ $empty['poster'] = $m[1];
+ } elseif (preg_match('/]*property="og:image"[^>]*content="([^"]+)"/i', $html, $m)) {
+ $empty['poster'] = $m[1];
+ }
}
// Extraire le réalisateur
@@ -712,15 +666,6 @@ function fetchFromMovieCovers($title, $year = '') {
$empty['description'] = html_entity_decode($m[1]);
}
- // Format haute qualité de l'affiche
- if ($empty['poster']) {
- $empty['poster'] = str_replace('/thumbs/', '/films-l/', $empty['poster']);
- } else {
- error_log("MovieCovers: ⚠️ Jaquette non trouvée pour '$title' (URL: $url) — structure HTML probablement changée");
- }
-
- error_log("MovieCovers: " . (!empty($empty['title']) ? "✅ Données récupérées pour '$title' → " . $empty['title'] : "⚠️ Page trouvée mais titre non extrait pour '$title'"));
-
return $empty;
}