Actualiser api.php

This commit is contained in:
2026-06-26 13:52:27 +02:00
parent edc602c16e
commit 60e0903c4f
+22 -14
View File
@@ -154,7 +154,8 @@ function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = null) {
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch); curl_close($ch);
$html = ($code === 200 && $searchRes) ? $searchRes : null; // ✅ CORRECTION : Vérifier que $searchRes n'est pas null ou false
$html = ($code === 200 && $searchRes && is_string($searchRes)) ? $searchRes : null;
if ($html) { if ($html) {
// ── ÉTAPE 2 : Extraire le lien vers la page du film ── // ── ÉTAPE 2 : Extraire le lien vers la page du film ──
@@ -183,8 +184,9 @@ function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = null) {
foreach ($pagesToTry as $pageUrl) { foreach ($pagesToTry as $pageUrl) {
$pageRes = httpGet($pageUrl, 10, $userAgent); $pageRes = httpGet($pageUrl, 10, $userAgent);
if ($pageRes) { // ✅ CORRECTION : Vérifier que $pageRes est une string valide
// Pattern plus flexible pour capturer l'image if ($pageRes && is_string($pageRes) && strlen($pageRes) > 0) {
// Pattern pour l'image
if (preg_match('/src=["\']?(https?:\/\/[^"\'\s>]*cinemapassion\.com[^"\'\s>]*covers[^"\'\s>]*\.jpg)["\']?/i', $pageRes, $imgMatches)) { if (preg_match('/src=["\']?(https?:\/\/[^"\'\s>]*cinemapassion\.com[^"\'\s>]*covers[^"\'\s>]*\.jpg)["\']?/i', $pageRes, $imgMatches)) {
$posterUrl = $imgMatches[1]; $posterUrl = $imgMatches[1];
$posterUrl = str_replace('http://', 'https://', $posterUrl); $posterUrl = str_replace('http://', 'https://', $posterUrl);
@@ -645,16 +647,19 @@ case 'debug_cinemapassion_detailed':
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch); curl_close($ch);
// ✅ CORRECTION : Vérifier que $searchRes est une string
$searchResStr = ($searchRes && is_string($searchRes)) ? $searchRes : '';
$debugInfo['steps']['search'] = [ $debugInfo['steps']['search'] = [
'url' => $searchUrl, 'url' => $searchUrl,
'http_code' => $code, 'http_code' => $code,
'response_length' => strlen($searchRes), 'response_length' => strlen($searchResStr),
'success' => ($code === 200 && !empty($searchRes)) 'success' => ($code === 200 && strlen($searchResStr) > 0)
]; ];
if ($code === 200 && $searchRes) { if ($code === 200 && strlen($searchResStr) > 0) {
// ÉTAPE 2 : Extraction du lien film // ÉTAPE 2 : Extraction du lien film
if (preg_match('/href=["\']([^"\']*film\/[^"\'\/]+-\d+\.php)["\']/i', $searchRes, $matches)) { if (preg_match('/href=["\']([^"\']*film\/[^"\'\/]+-\d+\.php)["\']/i', $searchResStr, $matches)) {
$filmPath = $matches[1]; $filmPath = $matches[1];
$filmPath = str_replace('../', '', $filmPath); $filmPath = str_replace('../', '', $filmPath);
$filmUrl = 'https://www.cinemapassion.com/' . $filmPath; $filmUrl = 'https://www.cinemapassion.com/' . $filmPath;
@@ -686,15 +691,18 @@ case 'debug_cinemapassion_detailed':
foreach ($pagesToTry as $index => $pageUrl) { foreach ($pagesToTry as $index => $pageUrl) {
$pageRes = httpGet($pageUrl, 10, $userAgent); $pageRes = httpGet($pageUrl, 10, $userAgent);
// ✅ CORRECTION : Vérifier que $pageRes est une string
$pageResStr = ($pageRes && is_string($pageRes)) ? $pageRes : '';
$pageDebug = [ $pageDebug = [
'url' => $pageUrl, 'url' => $pageUrl,
'success' => !empty($pageRes), 'success' => (strlen($pageResStr) > 0),
'response_length' => strlen($pageRes) 'response_length' => strlen($pageResStr)
]; ];
if ($pageRes) { if (strlen($pageResStr) > 0) {
// Test du pattern d'image // Test du pattern d'image
if (preg_match('/src=["\']?(https?:\/\/[^"\'\s>]*cinemapassion\.com[^"\'\s>]*covers[^"\'\s>]*\.jpg)["\']?/i', $pageRes, $imgMatches)) { if (preg_match('/src=["\']?(https?:\/\/[^"\'\s>]*cinemapassion\.com[^"\'\s>]*covers[^"\'\s>]*\.jpg)["\']?/i', $pageResStr, $imgMatches)) {
$posterUrl = str_replace('http://', 'https://', $imgMatches[1]); $posterUrl = str_replace('http://', 'https://', $imgMatches[1]);
$pageDebug['image_found'] = true; $pageDebug['image_found'] = true;
$pageDebug['image_url'] = $posterUrl; $pageDebug['image_url'] = $posterUrl;
@@ -712,7 +720,7 @@ case 'debug_cinemapassion_detailed':
} else { } else {
$pageDebug['image_found'] = false; $pageDebug['image_found'] = false;
// Extraire un extrait du HTML pour debug // Extraire un extrait du HTML pour debug
$pageDebug['html_snippet'] = substr($pageRes, 0, 500); $pageDebug['html_snippet'] = substr($pageResStr, 0, 500);
} }
} }
@@ -722,12 +730,12 @@ case 'debug_cinemapassion_detailed':
} else { } else {
$debugInfo['steps']['film_link'] = [ $debugInfo['steps']['film_link'] = [
'found' => false, 'found' => false,
'html_snippet' => substr($searchRes, 0, 1000) 'html_snippet' => substr($searchResStr, 0, 1000)
]; ];
} }
// Test du fallback // Test du fallback
if (preg_match('/src=["\']?(https?:\/\/[^"\'\s>]*cinemapassion\.com[^"\'\s>]*covers[^"\'\s>]*\.jpg)["\']?/i', $searchRes, $imgMatches)) { if (preg_match('/src=["\']?(https?:\/\/[^"\'\s>]*cinemapassion\.com[^"\'\s>]*covers[^"\'\s>]*\.jpg)["\']?/i', $searchResStr, $imgMatches)) {
$posterUrl = str_replace('http://', 'https://', $imgMatches[1]); $posterUrl = str_replace('http://', 'https://', $imgMatches[1]);
$debugInfo['steps']['fallback'] = [ $debugInfo['steps']['fallback'] = [
'success' => true, 'success' => true,