Actualiser api.php
This commit is contained in:
@@ -376,107 +376,5 @@ switch ($action) {
|
|||||||
echo json_encode(["success" => false, "error" => $e->getMessage()]);
|
echo json_encode(["success" => false, "error" => $e->getMessage()]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// ── ENDPOINT DE DEBUG DÉTAILLÉ ──
|
|
||||||
case 'debug_cinemapassion':
|
|
||||||
$title = $_GET['title'] ?? 'Saw';
|
|
||||||
$debugInfo = [
|
|
||||||
'title' => $title,
|
|
||||||
'cleanTitle' => cleanTitle($title),
|
|
||||||
'steps' => []
|
|
||||||
];
|
|
||||||
|
|
||||||
$baseUrl = 'https://www.cinemapassion.com';
|
|
||||||
$ch = curl_init();
|
|
||||||
curl_setopt_array($ch, [
|
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
|
||||||
CURLOPT_FOLLOWLOCATION => true,
|
|
||||||
CURLOPT_MAXREDIRS => 5,
|
|
||||||
CURLOPT_TIMEOUT => 15,
|
|
||||||
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
|
|
||||||
CURLOPT_COOKIEFILE => '',
|
|
||||||
CURLOPT_REFERER => 'https://www.cinemapassion.com/',
|
|
||||||
CURLOPT_SSL_VERIFYPEER => false
|
|
||||||
]);
|
|
||||||
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $baseUrl . '/recherche.php?recherche=' . urlencode(cleanTitle($title)));
|
|
||||||
$html = curl_exec($ch);
|
|
||||||
$finalUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
|
|
||||||
|
|
||||||
$debugInfo['steps']['search_get'] = [
|
|
||||||
'final_url' => $finalUrl,
|
|
||||||
'success' => !empty($html)
|
|
||||||
];
|
|
||||||
|
|
||||||
$filmHtml = null;
|
|
||||||
$regexFilm = '/href=["\']?(?:https?:\/\/(?:www\.)?cinemapassion\.com\/)?(?:\.\.\/)?(film[\/-][^"\'\s>]+)["\']?/i';
|
|
||||||
|
|
||||||
if (strpos($finalUrl, 'film-') !== false || strpos($finalUrl, '/film/') !== false || preg_match('/jaquette-(?:dvd|blu-ray)-/i', $html)) {
|
|
||||||
$filmHtml = $html;
|
|
||||||
$debugInfo['steps']['film_found'] = 'Redirection directe ou page film détectée';
|
|
||||||
} else {
|
|
||||||
if ($html && preg_match($regexFilm, $html, $matches)) {
|
|
||||||
$filmUrl = $baseUrl . '/' . ltrim($matches[1], './');
|
|
||||||
$debugInfo['steps']['film_found'] = $filmUrl;
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $filmUrl);
|
|
||||||
$filmHtml = curl_exec($ch);
|
|
||||||
} else {
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $baseUrl . '/moteur2.php');
|
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(['recherche' => cleanTitle($title)]));
|
|
||||||
$htmlPost = curl_exec($ch);
|
|
||||||
curl_setopt($ch, CURLOPT_POST, false);
|
|
||||||
$finalUrlPost = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
|
|
||||||
|
|
||||||
$debugInfo['steps']['search_post'] = [
|
|
||||||
'final_url' => $finalUrlPost,
|
|
||||||
'success' => !empty($htmlPost)
|
|
||||||
];
|
|
||||||
|
|
||||||
if (strpos($finalUrlPost, 'film-') !== false || strpos($finalUrlPost, '/film/') !== false) {
|
|
||||||
$filmHtml = $htmlPost;
|
|
||||||
$debugInfo['steps']['film_found'] = 'Redirection via POST';
|
|
||||||
} elseif ($htmlPost && preg_match($regexFilm, $htmlPost, $matches)) {
|
|
||||||
$filmUrl = $baseUrl . '/' . ltrim($matches[1], './');
|
|
||||||
$debugInfo['steps']['film_found'] = $filmUrl;
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $filmUrl);
|
|
||||||
$filmHtml = curl_exec($ch);
|
|
||||||
} else {
|
|
||||||
$debugInfo['steps']['fail'] = 'Aucun lien de film trouvé';
|
|
||||||
$debugInfo['html_snippet'] = substr($htmlPost ?: $html, 0, 1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($filmHtml) {
|
|
||||||
if (preg_match('/href=["\']?(?:https?:\/\/(?:www\.)?cinemapassion\.com\/)?(?:\.\.\/)?(jaquette-(?:dvd|blu-ray)-[^"\'\s>]+)["\']?/i', $filmHtml, $jaqMatches)) {
|
|
||||||
$jaqUrl = $baseUrl . '/' . ltrim($jaqMatches[1], './');
|
|
||||||
$debugInfo['steps']['jaquette_page'] = $jaqUrl;
|
|
||||||
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $jaqUrl);
|
|
||||||
$jaqHtml = curl_exec($ch);
|
|
||||||
|
|
||||||
if ($jaqHtml && preg_match('/src=["\']?(https?:\/\/(?:www\.)?cinemapassion\.com\/covers_temp\/covers[^"\'\s>]+)["\']?/i', $jaqHtml, $imgMatches)) {
|
|
||||||
$debugInfo['final_result'] = str_replace('http://', 'https://', $imgMatches[1]);
|
|
||||||
} else {
|
|
||||||
$debugInfo['steps']['jaquette_fail'] = 'Image covers_temp non trouvée sur la page jaquette';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($debugInfo['final_result']) && preg_match('/src=["\']?(https?:\/\/(?:www\.)?cinemapassion\.com\/covers_temp\/covers[^"\'\s>]+)["\']?/i', $filmHtml, $imgMatches)) {
|
|
||||||
if (strpos($imgMatches[1], 'miniature') === false && strpos($imgMatches[1], 'vign') === false) {
|
|
||||||
$debugInfo['final_result'] = str_replace('http://', 'https://', $imgMatches[1]);
|
|
||||||
$debugInfo['steps']['fallback'] = 'Trouvé directement sur la page du film';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($debugInfo['final_result'])) {
|
|
||||||
$debugInfo['final_result'] = 'assets/img/default_physical_media.jpg';
|
|
||||||
}
|
|
||||||
|
|
||||||
curl_close($ch);
|
|
||||||
echo json_encode($debugInfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user