From 9b2931c41b86eed59555f6b4f4938850d073cf87 Mon Sep 17 00:00:00 2001 From: Cedric Date: Tue, 30 Jun 2026 13:25:14 +0200 Subject: [PATCH] Actualiser api.php --- api.php | 110 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 42 deletions(-) diff --git a/api.php b/api.php index 1dd5857..8e3a252 100644 --- a/api.php +++ b/api.php @@ -350,81 +350,107 @@ function fetchFromBlurayCom($ean) { $ean = preg_replace('/[^0-9]/', '', (string)$ean); if (strlen($ean) < 8) return $empty; - // Recherche sur Blu-ray.com via l'EAN - $searchUrl = "https://www.blu-ray.com/movies/search.php?ean=" . urlencode($ean) . "&action=search"; - $html = httpGet($searchUrl, 10, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'); + // 1. Recherche sur Blu-ray.com via l'EAN (URL exacte extraite du site) + $searchUrl = "https://www.blu-ray.com/movies/search.php?ean=" . urlencode($ean) . "&action=search&submit=Search"; - if (!$html) return $empty; + // Requête CURL directe pour éviter les blocages (Referer cinemapassion.com bloqué par Blu-ray.com) + $ch = curl_init($searchUrl); + curl_setopt_array($ch, [ + CURLOPT_RETURNTRANSFER => true, + CURLOPT_TIMEOUT => 15, + CURLOPT_CONNECTTIMEOUT => 5, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36', + CURLOPT_HTTPHEADER => [ + 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', + 'Accept-Language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7', + 'Referer: https://www.blu-ray.com/' // Referer interne pour ne pas être bloqué + ] + ]); + $html = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); - // Extraire l'URL du film depuis les résultats de recherche - if (preg_match('/]+href="(\/movies\/[^\/]+\/(\d+)\/)"[^>]*>\s*]+src="([^"]+)"[^>]*>/i', $html, $matches)) { - $movieUrl = 'https://www.blu-ray.com' . $matches[1]; + if (!$html || $httpCode !== 200) { + error_log("Blu-ray.com: ❌ Échec requête pour EAN $ean (HTTP $httpCode)"); + return $empty; + } + + // 2. Extraction des résultats (Correction du Regex pour matcher l'URL absolue) + // Structure réelle : + if (preg_match('/href="(https?:\/\/www\.blu-ray\.com\/movies\/[^\/]+\/(\d+)\/)"[^>]*>.*?]+class="cover"[^>]+src="([^"]+)"/is', $html, $matches)) { + $movieUrl = $matches[1]; $movieId = $matches[2]; + $posterUrl = $matches[3]; + + // Convertir l'affiche en haute résolution + $posterUrl = str_replace('_small.jpg', '_large.jpg', $posterUrl); + $posterUrl = str_replace('_medium.jpg', '_large.jpg', $posterUrl); + $empty['poster'] = $posterUrl; + + // 3. Récupérer la page du film pour les détails techniques + $ch2 = curl_init($movieUrl); + curl_setopt_array($ch2, [ + CURLOPT_RETURNTRANSFER => true, + CURLOPT_TIMEOUT => 15, + CURLOPT_CONNECTTIMEOUT => 5, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36', + CURLOPT_HTTPHEADER => [ + 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', + 'Accept-Language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7', + 'Referer: https://www.blu-ray.com/' + ] + ]); + $movieHtml = curl_exec($ch2); + curl_close($ch2); - // Récupérer la page du film pour plus de détails - $movieHtml = httpGet($movieUrl, 10); if ($movieHtml) { - // Extraire le titre - if (preg_match('/]*class="h1[^"]*"[^>]*>([^<]+)<\/h1>/i', $movieHtml, $m)) { + // Titre + if (preg_match('/]*>([^<]+)<\/h1>/i', $movieHtml, $m)) { $empty['title'] = trim(strip_tags($m[1])); - } elseif (preg_match('/([^-]+)-\s*Blu-ray\.com/i', $movieHtml, $m)) { + } elseif (preg_match('/<title>([^-<]+)\s*-\s*Blu-ray\.com/i', $movieHtml, $m)) { $empty['title'] = trim($m[1]); } - // Extraire l'année + // Année if (preg_match('/\((\d{4})\)/', $movieHtml, $m)) { $empty['year'] = $m[1]; } - // Extraire l'affiche (convertir en haute résolution) - if (preg_match('/<img[^>]+class="cover"[^>]+src="([^"]+)"/i', $movieHtml, $m)) { - $posterUrl = $m[1]; - // Convertir small/medium en large pour meilleure qualité - $posterUrl = str_replace('_small.jpg', '_large.jpg', $posterUrl); - $posterUrl = str_replace('_medium.jpg', '_large.jpg', $posterUrl); - $empty['poster'] = $posterUrl; - } - - // Extraire le réalisateur - if (preg_match('/Director:[^<]*<a[^>]*>([^<]+)<\/a>/i', $movieHtml, $m)) { - $empty['director'] = trim($m[1]); - } - - // Extraire les acteurs - if (preg_match_all('/<a[^>]*class="hovercard"[^>]*>([^<]+)<\/a>/i', $movieHtml, $actorMatches)) { - $actors = array_map('trim', array_slice($actorMatches[1], 0, 5)); - $empty['actors'] = implode(', ', $actors); - } - - // Extraire la durée (Runtime) + // Durée (Runtime) if (preg_match('/Runtime:[^<]*(\d+)\s*min/i', $movieHtml, $m)) { $empty['length'] = $m[1] . ' min'; } - // Extraire le studio/éditeur + // Studio/Éditeur if (preg_match('/Studio:[^<]*<a[^>]*>([^<]+)<\/a>/i', $movieHtml, $m)) { $empty['publisher'] = trim($m[1]); } - // Extraire le nombre de disques + // Nombre de disques if (preg_match('/Discs:[^<]*(\d+)/i', $movieHtml, $m)) { $empty['number_of_discs'] = (int)$m[1]; } - // Extraire l'aspect ratio - if (preg_match('/Aspect[\s-]*Ratio:[^<]*(\d+:[\d.]+)/i', $movieHtml, $m)) { + // Aspect Ratio + if (preg_match('/Aspect[\s-]*Ratio:[^<]*(\d+[\.\:]\d+)/i', $movieHtml, $m)) { $empty['aspect_ratio'] = trim($m[1]); } - // Extraire le format (Blu-ray, 4K, DVD, etc.) - if (preg_match('/<h2[^>]*>.*?(4K|Blu-ray|DVD|3D).*?<\/h2>/i', $movieHtml, $m)) { - $empty['format'] = trim($m[1]); - } elseif (strpos($movieUrl, '/4k/') !== false) { + // Format + if (strpos($movieUrl, '/4k/') !== false) { $empty['format'] = '4K Ultra HD'; } elseif (strpos($movieUrl, '/3d/') !== false) { $empty['format'] = '3D Blu-ray'; + } else { + $empty['format'] = 'Blu-ray'; } } + } else { + error_log("Blu-ray.com: ❌ Film non trouvé ou structure HTML modifiée pour EAN $ean"); } return $empty;