Actualiser api.php
This commit is contained in:
@@ -154,7 +154,8 @@ function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = null) {
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
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) {
|
||||
// ── É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) {
|
||||
$pageRes = httpGet($pageUrl, 10, $userAgent);
|
||||
|
||||
if ($pageRes) {
|
||||
// Pattern plus flexible pour capturer l'image
|
||||
// ✅ CORRECTION : Vérifier que $pageRes est une string valide
|
||||
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)) {
|
||||
$posterUrl = $imgMatches[1];
|
||||
$posterUrl = str_replace('http://', 'https://', $posterUrl);
|
||||
@@ -645,16 +647,19 @@ case 'debug_cinemapassion_detailed':
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
// ✅ CORRECTION : Vérifier que $searchRes est une string
|
||||
$searchResStr = ($searchRes && is_string($searchRes)) ? $searchRes : '';
|
||||
|
||||
$debugInfo['steps']['search'] = [
|
||||
'url' => $searchUrl,
|
||||
'http_code' => $code,
|
||||
'response_length' => strlen($searchRes),
|
||||
'success' => ($code === 200 && !empty($searchRes))
|
||||
'response_length' => strlen($searchResStr),
|
||||
'success' => ($code === 200 && strlen($searchResStr) > 0)
|
||||
];
|
||||
|
||||
if ($code === 200 && $searchRes) {
|
||||
if ($code === 200 && strlen($searchResStr) > 0) {
|
||||
// É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 = str_replace('../', '', $filmPath);
|
||||
$filmUrl = 'https://www.cinemapassion.com/' . $filmPath;
|
||||
@@ -686,15 +691,18 @@ case 'debug_cinemapassion_detailed':
|
||||
foreach ($pagesToTry as $index => $pageUrl) {
|
||||
$pageRes = httpGet($pageUrl, 10, $userAgent);
|
||||
|
||||
// ✅ CORRECTION : Vérifier que $pageRes est une string
|
||||
$pageResStr = ($pageRes && is_string($pageRes)) ? $pageRes : '';
|
||||
|
||||
$pageDebug = [
|
||||
'url' => $pageUrl,
|
||||
'success' => !empty($pageRes),
|
||||
'response_length' => strlen($pageRes)
|
||||
'success' => (strlen($pageResStr) > 0),
|
||||
'response_length' => strlen($pageResStr)
|
||||
];
|
||||
|
||||
if ($pageRes) {
|
||||
if (strlen($pageResStr) > 0) {
|
||||
// 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]);
|
||||
$pageDebug['image_found'] = true;
|
||||
$pageDebug['image_url'] = $posterUrl;
|
||||
@@ -712,7 +720,7 @@ case 'debug_cinemapassion_detailed':
|
||||
} else {
|
||||
$pageDebug['image_found'] = false;
|
||||
// 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 {
|
||||
$debugInfo['steps']['film_link'] = [
|
||||
'found' => false,
|
||||
'html_snippet' => substr($searchRes, 0, 1000)
|
||||
'html_snippet' => substr($searchResStr, 0, 1000)
|
||||
];
|
||||
}
|
||||
|
||||
// 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]);
|
||||
$debugInfo['steps']['fallback'] = [
|
||||
'success' => true,
|
||||
|
||||
Reference in New Issue
Block a user