diff --git a/api.php b/api.php
index 4d4924f..446ebc7 100644
--- a/api.php
+++ b/api.php
@@ -340,10 +340,7 @@ function fetchTmdbPosterAndSynopsis($title, $year = '', $pdo = null) {
// ── FONCTION POUR RÉCUPÉRER LES DONNÉES DEPUIS BLU-RAY.COM ──
function fetchFromBlurayCom($ean) {
- static $lastRequest = null;
- if ($lastRequest === null) {
- $lastRequest = microtime(true);
- }
+ static $lastRequest = 0;
$empty = [
'title' => '', 'year' => '', 'director' => '', 'actors' => '',
'poster' => '', 'description' => '', 'length' => '',
@@ -354,10 +351,10 @@ function fetchFromBlurayCom($ean) {
$ean = preg_replace('/[^0-9]/', '', (string)$ean);
if (strlen($ean) < 8) return $empty;
- // ✅ THROTTLE : Attendre 3 secondes entre chaque requête pour éviter le blocage
+ // ✅ THROTTLE : 2 secondes entre chaque requête
$now = microtime(true);
- if ($lastRequest > 0 && ($now - $lastRequest) < 1.5) {
- usleep((int)((1.5 - ($now - $lastRequest)) * 1000000));
+ if ($lastRequest > 0 && ($now - $lastRequest) < 2) {
+ usleep((int)((2 - ($now - $lastRequest)) * 1000000));
}
$lastRequest = microtime(true);
@@ -383,7 +380,6 @@ function fetchFromBlurayCom($ean) {
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
- // ✅ GESTION D'ERREUR : Si Blu-ray.com bloque (403, 429, 503), on retourne vide
if (!$searchHtml || $httpCode !== 200) {
error_log("Blu-ray.com: ❌ Échec recherche EAN $ean (HTTP $httpCode)");
return $empty;
@@ -399,7 +395,7 @@ function fetchFromBlurayCom($ean) {
$movieId = $matches[2];
// ✅ THROTTLE avant la 2ème requête
- usleep(1000000); // 1 seconde
+ usleep(1000000);
// ÉTAPE 2 : Récupérer la page du film
$ch2 = curl_init($movieUrl);
@@ -428,33 +424,33 @@ function fetchFromBlurayCom($ean) {
// === EXTRACTION DES DONNÉES ===
- // Titre (depuis
)
+ // Titre
if (preg_match('/]*>([^<]+)<\/h1>/i', $movieHtml, $m)) {
$rawTitle = trim(strip_tags($m[1]));
$empty['title'] = trim(preg_replace('/\s*(Blu-ray|4K|3D|DVD|UHD).*$/i', '', $rawTitle));
}
- // Année (depuis 2015)
+ // Année
if (preg_match('/href="[^"]*year=(\d{4})[^"]*"[^>]*>(\d{4})<\/a>/i', $movieHtml, $m)) {
$empty['year'] = $m[1];
}
- // Studio/Éditeur (depuis Warner Bros.)
+ // Studio/Éditeur
if (preg_match('/href="[^"]*studioid=\d+[^"]*"[^>]*>([^<]+)<\/a>/i', $movieHtml, $m)) {
$empty['publisher'] = trim($m[1]);
}
- // Durée (depuis 120 min)
+ // Durée
if (preg_match('/]*id="runtime"[^>]*>(\d+)\s*min<\/span>/i', $movieHtml, $m)) {
$empty['length'] = $m[1] . ' min';
}
- // Aspect ratio (depuis "Aspect ratio: 2.40:1
")
+ // Aspect ratio
if (preg_match('/Aspect[\s-]*ratio:\s*([\d\.]+:[\d\.]+)/i', $movieHtml, $m)) {
$empty['aspect_ratio'] = trim($m[1]);
}
- // Nombre de disques (depuis "Two-disc set" ou "Single disc set")
+ // Nombre de disques
if (preg_match('/(\w+)-disc\s+set/i', $movieHtml, $m)) {
$wordToNum = [
'single' => 1, 'two' => 2, 'three' => 3, 'four' => 4,
@@ -466,7 +462,7 @@ function fetchFromBlurayCom($ean) {
$empty['number_of_discs'] = (int)$m[1];
}
- // Format (déterminé depuis l'URL ou le contenu)
+ // Format
if (strpos($movieUrl, '/4k/') !== false || stripos($movieHtml, '4K Ultra HD') !== false) {
$empty['format'] = '4K Ultra HD';
} elseif (strpos($movieUrl, '/3d/') !== false || stripos($movieHtml, '3D Blu-ray') !== false) {
@@ -475,35 +471,32 @@ function fetchFromBlurayCom($ean) {
$empty['format'] = 'Blu-ray';
}
- // Affiche HD (depuis
)
- if (preg_match('/
]*class="coverfront"[^>]*src="([^"]+)"/i', $movieHtml, $m)) {
+ // Affiche HD
+ if (preg_match('/src="(https:\/\/images\.static-bluray\.com\/movies\/covers\/\d+_front\.jpg[^"]*)"/i', $movieHtml, $m)) {
+ $empty['poster'] = $m[1];
+ } elseif (preg_match('/
]*class="coverfront"[^>]*src="([^"]+)"/i', $movieHtml, $m)) {
$posterUrl = $m[1];
- // Convertir _large.jpg en _front.jpg pour meilleure qualité
$posterUrl = preg_replace('/_large\.jpg/', '_front.jpg', $posterUrl);
$empty['poster'] = $posterUrl;
- } elseif (preg_match('/
]*class="coverfront"[^>]*src="([^"]+)"/i', $movieHtml, $m)) {
- $posterUrl = $m[1];
- $posterUrl = preg_replace('/_large\.jpg/', '_front.jpg', $posterUrl);
- $empty['poster'] = $posterUrl;
- }
+ }
- // Synopsis, Réalisateur, Acteurs (depuis )
+ // Synopsis, Réalisateur, Acteurs
if (preg_match('/
]*id="movie_info"[^>]*>(.*?)
]*id="movie_review_intro"/is', $movieHtml, $infoBlock)) {
$infoHtml = $infoBlock[1];
- // Synopsis (texte après
et avant
Director:)
+ // Synopsis
if (preg_match('/<\/center>
\s*(.*?)
Director:/is', $infoHtml, $m)) {
$synopsis = trim(strip_tags($m[1]));
$synopsis = preg_replace('/\s+/', ' ', $synopsis);
$empty['description'] = $synopsis;
}
- // Réalisateur (depuis "Director:
George Miller")
+ // Réalisateur
if (preg_match('/Director:\s*]*>([^<]+)<\/a>/i', $infoHtml, $m)) {
$empty['director'] = trim($m[1]);
}
- // Acteurs (depuis "Starring: Tom Hardy, Charlize Theron, ...")
+ // Acteurs
if (preg_match('/Starring:\s*(.*?)(?:
|<\/div>)/is', $infoHtml, $m)) {
$actorsHtml = $m[1];
preg_match_all('/]*>([^<]+)<\/a>/i', $actorsHtml, $actorMatches);
@@ -675,7 +668,7 @@ case 'import_batch':
foreach ($items as $item) {
$ean = preg_replace('/[^0-9]/', '', (string)($item['ean'] ?? ''));
- $csvTitle = trim($item['title'] ?? ''); // ✅ Titre issu du CSV (fallback)
+ $csvTitle = trim($item['title'] ?? ''); // ✅ Titre issu du CSV
// ✅ On ne skip que si on n'a ni EAN ni titre
if (strlen($ean) < 8 && empty($csvTitle)) {
@@ -683,7 +676,7 @@ case 'import_batch':
continue;
}
- // 1. Données physiques via BLU-RAY.COM (prioritaire)
+ // 1. ✅ Données physiques via BLU-RAY.COM (prioritaire)
$blurayData = !empty($ean) ? fetchFromBlurayCom($ean) : [];
// ✅ Si Blu-ray.com trouve le film, on prend son titre. Sinon, on prend celui du CSV.