Actualiser api.php
This commit is contained in:
@@ -350,81 +350,107 @@ function fetchFromBlurayCom($ean) {
|
|||||||
$ean = preg_replace('/[^0-9]/', '', (string)$ean);
|
$ean = preg_replace('/[^0-9]/', '', (string)$ean);
|
||||||
if (strlen($ean) < 8) return $empty;
|
if (strlen($ean) < 8) return $empty;
|
||||||
|
|
||||||
// Recherche sur Blu-ray.com via l'EAN
|
// 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";
|
$searchUrl = "https://www.blu-ray.com/movies/search.php?ean=" . urlencode($ean) . "&action=search&submit=Search";
|
||||||
$html = httpGet($searchUrl, 10, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36');
|
|
||||||
|
|
||||||
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 (!$html || $httpCode !== 200) {
|
||||||
if (preg_match('/<a[^>]+href="(\/movies\/[^\/]+\/(\d+)\/)"[^>]*>\s*<img[^>]+src="([^"]+)"[^>]*>/i', $html, $matches)) {
|
error_log("Blu-ray.com: ❌ Échec requête pour EAN $ean (HTTP $httpCode)");
|
||||||
$movieUrl = 'https://www.blu-ray.com' . $matches[1];
|
return $empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Extraction des résultats (Correction du Regex pour matcher l'URL absolue)
|
||||||
|
// Structure réelle : <a ... href="https://www.blu-ray.com/movies/.../132053/" ...><img class="cover" ... src="..."></a>
|
||||||
|
if (preg_match('/href="(https?:\/\/www\.blu-ray\.com\/movies\/[^\/]+\/(\d+)\/)"[^>]*>.*?<img[^>]+class="cover"[^>]+src="([^"]+)"/is', $html, $matches)) {
|
||||||
|
$movieUrl = $matches[1];
|
||||||
$movieId = $matches[2];
|
$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) {
|
if ($movieHtml) {
|
||||||
// Extraire le titre
|
// Titre
|
||||||
if (preg_match('/<h1[^>]*class="h1[^"]*"[^>]*>([^<]+)<\/h1>/i', $movieHtml, $m)) {
|
if (preg_match('/<h1[^>]*>([^<]+)<\/h1>/i', $movieHtml, $m)) {
|
||||||
$empty['title'] = trim(strip_tags($m[1]));
|
$empty['title'] = trim(strip_tags($m[1]));
|
||||||
} elseif (preg_match('/<title>([^-]+)-\s*Blu-ray\.com/i', $movieHtml, $m)) {
|
} elseif (preg_match('/<title>([^-<]+)\s*-\s*Blu-ray\.com/i', $movieHtml, $m)) {
|
||||||
$empty['title'] = trim($m[1]);
|
$empty['title'] = trim($m[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extraire l'année
|
// Année
|
||||||
if (preg_match('/\((\d{4})\)/', $movieHtml, $m)) {
|
if (preg_match('/\((\d{4})\)/', $movieHtml, $m)) {
|
||||||
$empty['year'] = $m[1];
|
$empty['year'] = $m[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extraire l'affiche (convertir en haute résolution)
|
// Durée (Runtime)
|
||||||
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)
|
|
||||||
if (preg_match('/Runtime:[^<]*(\d+)\s*min/i', $movieHtml, $m)) {
|
if (preg_match('/Runtime:[^<]*(\d+)\s*min/i', $movieHtml, $m)) {
|
||||||
$empty['length'] = $m[1] . ' min';
|
$empty['length'] = $m[1] . ' min';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extraire le studio/éditeur
|
// Studio/Éditeur
|
||||||
if (preg_match('/Studio:[^<]*<a[^>]*>([^<]+)<\/a>/i', $movieHtml, $m)) {
|
if (preg_match('/Studio:[^<]*<a[^>]*>([^<]+)<\/a>/i', $movieHtml, $m)) {
|
||||||
$empty['publisher'] = trim($m[1]);
|
$empty['publisher'] = trim($m[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extraire le nombre de disques
|
// Nombre de disques
|
||||||
if (preg_match('/Discs:[^<]*(\d+)/i', $movieHtml, $m)) {
|
if (preg_match('/Discs:[^<]*(\d+)/i', $movieHtml, $m)) {
|
||||||
$empty['number_of_discs'] = (int)$m[1];
|
$empty['number_of_discs'] = (int)$m[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extraire l'aspect ratio
|
// Aspect Ratio
|
||||||
if (preg_match('/Aspect[\s-]*Ratio:[^<]*(\d+:[\d.]+)/i', $movieHtml, $m)) {
|
if (preg_match('/Aspect[\s-]*Ratio:[^<]*(\d+[\.\:]\d+)/i', $movieHtml, $m)) {
|
||||||
$empty['aspect_ratio'] = trim($m[1]);
|
$empty['aspect_ratio'] = trim($m[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extraire le format (Blu-ray, 4K, DVD, etc.)
|
// Format
|
||||||
if (preg_match('/<h2[^>]*>.*?(4K|Blu-ray|DVD|3D).*?<\/h2>/i', $movieHtml, $m)) {
|
if (strpos($movieUrl, '/4k/') !== false) {
|
||||||
$empty['format'] = trim($m[1]);
|
|
||||||
} elseif (strpos($movieUrl, '/4k/') !== false) {
|
|
||||||
$empty['format'] = '4K Ultra HD';
|
$empty['format'] = '4K Ultra HD';
|
||||||
} elseif (strpos($movieUrl, '/3d/') !== false) {
|
} elseif (strpos($movieUrl, '/3d/') !== false) {
|
||||||
$empty['format'] = '3D Blu-ray';
|
$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;
|
return $empty;
|
||||||
|
|||||||
Reference in New Issue
Block a user