Actualiser api.php
This commit is contained in:
@@ -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 <h1>)
|
||||
// Titre
|
||||
if (preg_match('/<h1[^>]*>([^<]+)<\/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 <a class="grey" href="...?year=2015"...>2015</a>)
|
||||
// Année
|
||||
if (preg_match('/href="[^"]*year=(\d{4})[^"]*"[^>]*>(\d{4})<\/a>/i', $movieHtml, $m)) {
|
||||
$empty['year'] = $m[1];
|
||||
}
|
||||
|
||||
// Studio/Éditeur (depuis <a class="grey" href="...?studioid=9"...>Warner Bros.</a>)
|
||||
// Studio/Éditeur
|
||||
if (preg_match('/href="[^"]*studioid=\d+[^"]*"[^>]*>([^<]+)<\/a>/i', $movieHtml, $m)) {
|
||||
$empty['publisher'] = trim($m[1]);
|
||||
}
|
||||
|
||||
// Durée (depuis <span id="runtime"...>120 min</span>)
|
||||
// Durée
|
||||
if (preg_match('/<span[^>]*id="runtime"[^>]*>(\d+)\s*min<\/span>/i', $movieHtml, $m)) {
|
||||
$empty['length'] = $m[1] . ' min';
|
||||
}
|
||||
|
||||
// Aspect ratio (depuis "Aspect ratio: 2.40:1<br>")
|
||||
// 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 <img id="largefrontimage" src="..._front.jpg">)
|
||||
if (preg_match('/<img[^>]*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('/<img[^>]*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('/<img[^>]*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 <div id="movie_info">)
|
||||
// Synopsis, Réalisateur, Acteurs
|
||||
if (preg_match('/<div[^>]*id="movie_info"[^>]*>(.*?)<div[^>]*id="movie_review_intro"/is', $movieHtml, $infoBlock)) {
|
||||
$infoHtml = $infoBlock[1];
|
||||
|
||||
// Synopsis (texte après </center><br> et avant <br><br><br>Director:)
|
||||
// Synopsis
|
||||
if (preg_match('/<\/center><br>\s*(.*?)<br><br><br>Director:/is', $infoHtml, $m)) {
|
||||
$synopsis = trim(strip_tags($m[1]));
|
||||
$synopsis = preg_replace('/\s+/', ' ', $synopsis);
|
||||
$empty['description'] = $synopsis;
|
||||
}
|
||||
|
||||
// Réalisateur (depuis "Director: <a...>George Miller</a>")
|
||||
// Réalisateur
|
||||
if (preg_match('/Director:\s*<a[^>]*>([^<]+)<\/a>/i', $infoHtml, $m)) {
|
||||
$empty['director'] = trim($m[1]);
|
||||
}
|
||||
|
||||
// Acteurs (depuis "Starring: <a...>Tom Hardy</a>, <a...>Charlize Theron</a>, ...")
|
||||
// Acteurs
|
||||
if (preg_match('/Starring:\s*(.*?)(?:<br>|<\/div>)/is', $infoHtml, $m)) {
|
||||
$actorsHtml = $m[1];
|
||||
preg_match_all('/<a[^>]*>([^<]+)<\/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.
|
||||
|
||||
Reference in New Issue
Block a user