Actualiser api.php
This commit is contained in:
@@ -158,11 +158,9 @@ function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = 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 ──
|
||||||
// Pattern : href='../film/Saw-3814.php'
|
|
||||||
if (preg_match('/href=["\']([^"\']*film\/[^"\'\/]+-\d+\.php)["\']/i', $html, $matches)) {
|
if (preg_match('/href=["\']([^"\']*film\/[^"\'\/]+-\d+\.php)["\']/i', $html, $matches)) {
|
||||||
$filmPath = $matches[1];
|
$filmPath = $matches[1];
|
||||||
|
|
||||||
// Normaliser l'URL
|
|
||||||
$filmPath = str_replace('../', '', $filmPath);
|
$filmPath = str_replace('../', '', $filmPath);
|
||||||
if (strpos($filmPath, '/') !== 0) {
|
if (strpos($filmPath, '/') !== 0) {
|
||||||
$filmUrl = 'https://www.cinemapassion.com/' . $filmPath;
|
$filmUrl = 'https://www.cinemapassion.com/' . $filmPath;
|
||||||
@@ -170,8 +168,6 @@ function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = null) {
|
|||||||
$filmUrl = 'https://www.cinemapassion.com' . $filmPath;
|
$filmUrl = 'https://www.cinemapassion.com' . $filmPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extraire le nom-slug et l'ID numérique
|
|
||||||
// Ex: film/Saw-3814.php → filmName=Saw, filmId=3814
|
|
||||||
if (preg_match('/film\/([^\/]+)-(\d+)\.php/i', $filmUrl, $filmMatches)) {
|
if (preg_match('/film\/([^\/]+)-(\d+)\.php/i', $filmUrl, $filmMatches)) {
|
||||||
$filmName = $filmMatches[1];
|
$filmName = $filmMatches[1];
|
||||||
$filmId = $filmMatches[2];
|
$filmId = $filmMatches[2];
|
||||||
@@ -188,13 +184,9 @@ function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = null) {
|
|||||||
$pageRes = httpGet($pageUrl, 10, $userAgent);
|
$pageRes = httpGet($pageUrl, 10, $userAgent);
|
||||||
|
|
||||||
if ($pageRes) {
|
if ($pageRes) {
|
||||||
// Pattern : src='http://www.cinemapassion.com/covers_temp/covers3/Saw-13005811062007.jpg'
|
// Pattern plus flexible pour capturer l'image
|
||||||
$imgPattern = '/src=["\']?(https?:\/\/www\.cinemapassion\.com\/covers_temp\/covers\d*\/[^"\'\s>]+\.jpg)["\']?/i';
|
if (preg_match('/src=["\']?(https?:\/\/[^"\'\s>]*cinemapassion\.com[^"\'\s>]*covers[^"\'\s>]*\.jpg)["\']?/i', $pageRes, $imgMatches)) {
|
||||||
|
|
||||||
if (preg_match($imgPattern, $pageRes, $imgMatches)) {
|
|
||||||
$posterUrl = $imgMatches[1];
|
$posterUrl = $imgMatches[1];
|
||||||
|
|
||||||
// Forcer HTTPS
|
|
||||||
$posterUrl = str_replace('http://', 'https://', $posterUrl);
|
$posterUrl = str_replace('http://', 'https://', $posterUrl);
|
||||||
|
|
||||||
error_log("CinemaPassion: Image trouvée pour '{$cleanTitle}' → {$posterUrl}");
|
error_log("CinemaPassion: Image trouvée pour '{$cleanTitle}' → {$posterUrl}");
|
||||||
@@ -211,8 +203,7 @@ function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ── FALLBACK : Chercher directement une image dans les résultats ──
|
// ── FALLBACK : Chercher directement une image dans les résultats ──
|
||||||
$imgPattern = '/src=["\']?(https?:\/\/www\.cinemapassion\.com\/covers_temp\/covers\d*\/[^"\'\s>]+\.jpg)["\']?/i';
|
if (preg_match('/src=["\']?(https?:\/\/[^"\'\s>]*cinemapassion\.com[^"\'\s>]*covers[^"\'\s>]*\.jpg)["\']?/i', $html, $imgMatches)) {
|
||||||
if (preg_match($imgPattern, $html, $imgMatches)) {
|
|
||||||
$posterUrl = str_replace('http://', 'https://', $imgMatches[1]);
|
$posterUrl = str_replace('http://', 'https://', $imgMatches[1]);
|
||||||
error_log("CinemaPassion: Image trouvée (fallback) pour '{$cleanTitle}' → {$posterUrl}");
|
error_log("CinemaPassion: Image trouvée (fallback) pour '{$cleanTitle}' → {$posterUrl}");
|
||||||
return [
|
return [
|
||||||
@@ -614,14 +605,158 @@ case 'get_config_keys':
|
|||||||
echo json_encode(["success" => true, "imported" => $imported]);
|
echo json_encode(["success" => true, "imported" => $imported]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'debug_cinemapassion':
|
// ── ENDPOINT DE DEBUG DÉTAILLÉ ──
|
||||||
$title = $_GET['title'] ?? '';
|
case 'debug_cinemapassion_detailed':
|
||||||
$year = $_GET['year'] ?? '';
|
$title = $_GET['title'] ?? 'Saw';
|
||||||
$ean = $_GET['ean'] ?? '';
|
$year = $_GET['year'] ?? '';
|
||||||
|
$ean = $_GET['ean'] ?? '';
|
||||||
|
|
||||||
$result = fetchCinemaPassion($title, $year, $ean, $pdo);
|
$debugInfo = [
|
||||||
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
'title' => $title,
|
||||||
exit;
|
'year' => $year,
|
||||||
break;
|
'ean' => $ean,
|
||||||
|
'cleanTitle' => cleanTitle($title),
|
||||||
|
'steps' => []
|
||||||
|
];
|
||||||
|
|
||||||
|
$userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36';
|
||||||
|
|
||||||
|
// ÉTAPE 1 : Test de la recherche POST
|
||||||
|
$searchUrl = "https://www.cinemapassion.com/moteur2.php";
|
||||||
|
$ch = curl_init($searchUrl);
|
||||||
|
curl_setopt_array($ch, [
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_TIMEOUT => 15,
|
||||||
|
CURLOPT_CONNECTTIMEOUT => 5,
|
||||||
|
CURLOPT_SSL_VERIFYPEER => false,
|
||||||
|
CURLOPT_USERAGENT => $userAgent,
|
||||||
|
CURLOPT_FOLLOWLOCATION => true,
|
||||||
|
CURLOPT_POST => true,
|
||||||
|
CURLOPT_POSTFIELDS => http_build_query(['recherche' => cleanTitle($title)]),
|
||||||
|
CURLOPT_REFERER => 'https://www.cinemapassion.com/',
|
||||||
|
CURLOPT_HTTPHEADER => [
|
||||||
|
'Content-Type: application/x-www-form-urlencoded',
|
||||||
|
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
||||||
|
'Accept-Language: fr-FR,fr;q=0.8',
|
||||||
|
'Origin: https://www.cinemapassion.com'
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
$searchRes = curl_exec($ch);
|
||||||
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
$debugInfo['steps']['search'] = [
|
||||||
|
'url' => $searchUrl,
|
||||||
|
'http_code' => $code,
|
||||||
|
'response_length' => strlen($searchRes),
|
||||||
|
'success' => ($code === 200 && !empty($searchRes))
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($code === 200 && $searchRes) {
|
||||||
|
// ÉTAPE 2 : Extraction du lien film
|
||||||
|
if (preg_match('/href=["\']([^"\']*film\/[^"\'\/]+-\d+\.php)["\']/i', $searchRes, $matches)) {
|
||||||
|
$filmPath = $matches[1];
|
||||||
|
$filmPath = str_replace('../', '', $filmPath);
|
||||||
|
$filmUrl = 'https://www.cinemapassion.com/' . $filmPath;
|
||||||
|
|
||||||
|
$debugInfo['steps']['film_link'] = [
|
||||||
|
'found' => true,
|
||||||
|
'filmPath' => $filmPath,
|
||||||
|
'filmUrl' => $filmUrl
|
||||||
|
];
|
||||||
|
|
||||||
|
// ÉTAPE 3 : Extraction du nom et ID
|
||||||
|
if (preg_match('/film\/([^\/]+)-(\d+)\.php/i', $filmUrl, $filmMatches)) {
|
||||||
|
$filmName = $filmMatches[1];
|
||||||
|
$filmId = $filmMatches[2];
|
||||||
|
|
||||||
|
$debugInfo['steps']['film_details'] = [
|
||||||
|
'filmName' => $filmName,
|
||||||
|
'filmId' => $filmId
|
||||||
|
];
|
||||||
|
|
||||||
|
// ÉTAPE 4 : Test des pages de jaquettes
|
||||||
|
$pagesToTry = [
|
||||||
|
"https://www.cinemapassion.com/jaquette-dvd-{$filmName}-{$filmId}.php",
|
||||||
|
"https://www.cinemapassion.com/jaquette-blu-ray-{$filmName}-{$filmId}.php",
|
||||||
|
$filmUrl,
|
||||||
|
"https://www.cinemapassion.com/sticker-dvd-{$filmName}-{$filmId}.php",
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($pagesToTry as $index => $pageUrl) {
|
||||||
|
$pageRes = httpGet($pageUrl, 10, $userAgent);
|
||||||
|
|
||||||
|
$pageDebug = [
|
||||||
|
'url' => $pageUrl,
|
||||||
|
'success' => !empty($pageRes),
|
||||||
|
'response_length' => strlen($pageRes)
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($pageRes) {
|
||||||
|
// Test du pattern d'image
|
||||||
|
if (preg_match('/src=["\']?(https?:\/\/[^"\'\s>]*cinemapassion\.com[^"\'\s>]*covers[^"\'\s>]*\.jpg)["\']?/i', $pageRes, $imgMatches)) {
|
||||||
|
$posterUrl = str_replace('http://', 'https://', $imgMatches[1]);
|
||||||
|
$pageDebug['image_found'] = true;
|
||||||
|
$pageDebug['image_url'] = $posterUrl;
|
||||||
|
|
||||||
|
$debugInfo['steps']['pages_tested'][$index] = $pageDebug;
|
||||||
|
$debugInfo['final_result'] = [
|
||||||
|
'success' => true,
|
||||||
|
'poster' => $posterUrl,
|
||||||
|
'title' => cleanTitle($title),
|
||||||
|
'format' => 'Blu-ray'
|
||||||
|
];
|
||||||
|
|
||||||
|
echo json_encode($debugInfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
} else {
|
||||||
|
$pageDebug['image_found'] = false;
|
||||||
|
// Extraire un extrait du HTML pour debug
|
||||||
|
$pageDebug['html_snippet'] = substr($pageRes, 0, 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$debugInfo['steps']['pages_tested'][$index] = $pageDebug;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$debugInfo['steps']['film_link'] = [
|
||||||
|
'found' => false,
|
||||||
|
'html_snippet' => substr($searchRes, 0, 1000)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test du fallback
|
||||||
|
if (preg_match('/src=["\']?(https?:\/\/[^"\'\s>]*cinemapassion\.com[^"\'\s>]*covers[^"\'\s>]*\.jpg)["\']?/i', $searchRes, $imgMatches)) {
|
||||||
|
$posterUrl = str_replace('http://', 'https://', $imgMatches[1]);
|
||||||
|
$debugInfo['steps']['fallback'] = [
|
||||||
|
'success' => true,
|
||||||
|
'image_url' => $posterUrl
|
||||||
|
];
|
||||||
|
$debugInfo['final_result'] = [
|
||||||
|
'success' => true,
|
||||||
|
'poster' => $posterUrl,
|
||||||
|
'title' => cleanTitle($title),
|
||||||
|
'format' => 'Blu-ray'
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$debugInfo['steps']['fallback'] = [
|
||||||
|
'success' => false
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($debugInfo['final_result'])) {
|
||||||
|
$debugInfo['final_result'] = [
|
||||||
|
'success' => false,
|
||||||
|
'poster' => 'assets/img/default_physical_media.jpg',
|
||||||
|
'title' => cleanTitle($title),
|
||||||
|
'format' => 'Blu-ray'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($debugInfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user