Actualiser api.php
This commit is contained in:
@@ -118,38 +118,117 @@ function extractYear($dateStr) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── FONCTION POUR RÉCUPÉRER LES IMAGES DEPUIS CINEMAPASSION.COM ──
|
||||||
function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = null) {
|
function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = null) {
|
||||||
$defaultPoster = 'assets/img/default_physical_media.jpg';
|
$defaultPoster = 'assets/img/default_physical_media.jpg';
|
||||||
$cleanTitle = cleanTitle($title);
|
$cleanTitle = cleanTitle($title);
|
||||||
|
|
||||||
// 1. Recherche
|
if (empty($cleanTitle)) {
|
||||||
$searchUrl = "https://www.cinemapassion.com/recherche.php?recherche=" . urlencode($cleanTitle);
|
return ['poster' => $defaultPoster, 'title' => '', 'format' => 'Blu-ray'];
|
||||||
$searchRes = httpGet($searchUrl);
|
}
|
||||||
|
|
||||||
if ($searchRes) {
|
$userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36';
|
||||||
// Recherche d'un lien contenant 'film-' et un chiffre
|
|
||||||
if (preg_match('/href=["\'](\.\.\/film\/[^\'"]+-\d+\.php)["\']/i', $searchRes, $matches)) {
|
// ── ÉTAPE 1 : Recherche via POST sur /moteur2.php (le vrai moteur du site) ──
|
||||||
$filmUrl = 'https://www.cinemapassion.com/' . ltrim($matches[1], './');
|
$searchUrl = "https://www.cinemapassion.com/moteur2.php";
|
||||||
$filmRes = httpGet($filmUrl);
|
|
||||||
|
$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]),
|
||||||
|
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);
|
||||||
|
|
||||||
|
$html = ($code === 200 && $searchRes) ? $searchRes : null;
|
||||||
|
|
||||||
|
if ($html) {
|
||||||
|
// ── ÉTAPE 2 : Extraire le lien vers la page du film ──
|
||||||
|
// Pattern trouvé dans le HTML : href='../film/Saw-3814.php'
|
||||||
|
if (preg_match('/href=["\']([^"\']*film\/[^"\'\/]+-\d+\.php)["\']/i', $html, $matches)) {
|
||||||
|
$filmPath = $matches[1];
|
||||||
|
|
||||||
if ($filmRes) {
|
// Normaliser l'URL (supprimer les ../)
|
||||||
// Regex améliorée : Cherche n'importe quel img src contenant 'covers'
|
$filmPath = str_replace('../', '', $filmPath);
|
||||||
// sans se limiter à 'covers3' et accepte quotes simples ou doubles
|
if (strpos($filmPath, '/') !== 0) {
|
||||||
$pattern = '/src=["\'](http:\/\/www\.cinemapassion\.com\/covers_temp\/covers[^"\']+\.jpg)["\']/i';
|
$filmUrl = 'https://www.cinemapassion.com/' . $filmPath;
|
||||||
|
} else {
|
||||||
|
$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)) {
|
||||||
|
$filmName = $filmMatches[1];
|
||||||
|
$filmId = $filmMatches[2];
|
||||||
|
|
||||||
if (preg_match($pattern, $filmRes, $imgMatches)) {
|
// ── ÉTAPE 3 : Essayer plusieurs pages pour trouver l'image ──
|
||||||
return [
|
$pagesToTry = [
|
||||||
'poster' => $imgMatches[1],
|
// Page jaquette DVD (la plus probable)
|
||||||
'title' => $cleanTitle,
|
"https://www.cinemapassion.com/jaquette-dvd-{$filmName}-{$filmId}.php",
|
||||||
'format' => 'Blu-ray'
|
// Page jaquette Blu-ray
|
||||||
];
|
"https://www.cinemapassion.com/jaquette-blu-ray-{$filmName}-{$filmId}.php",
|
||||||
|
// Page fiche complète du film
|
||||||
|
$filmUrl,
|
||||||
|
// Page sticker
|
||||||
|
"https://www.cinemapassion.com/sticker-dvd-{$filmName}-{$filmId}.php",
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($pagesToTry as $pageUrl) {
|
||||||
|
$pageRes = httpGet($pageUrl, 10, $userAgent);
|
||||||
|
|
||||||
|
if ($pageRes) {
|
||||||
|
// Pattern pour l'image : src='http://www.cinemapassion.com/covers_temp/covers3/Saw-13005811062007.jpg'
|
||||||
|
// Accepte http ET https, covers avec ou sans chiffre (covers, covers2, covers3...)
|
||||||
|
$imgPattern = '/src=["\']?(https?:\/\/www\.cinemapassion\.com\/covers_temp\/covers\d*\/[^"\'\s>]+\.jpg)["\']?/i';
|
||||||
|
|
||||||
|
if (preg_match($imgPattern, $pageRes, $imgMatches)) {
|
||||||
|
$posterUrl = $imgMatches[1];
|
||||||
|
|
||||||
|
// Forcer HTTPS pour éviter les mixed content
|
||||||
|
$posterUrl = str_replace('http://', 'https://', $posterUrl);
|
||||||
|
|
||||||
|
error_log("CinemaPassion: Image trouvée pour '{$cleanTitle}' → {$posterUrl}");
|
||||||
|
|
||||||
|
return [
|
||||||
|
'poster' => $posterUrl,
|
||||||
|
'title' => $cleanTitle,
|
||||||
|
'format' => 'Blu-ray'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── FALLBACK : Chercher directement une image covers_temp dans les résultats ──
|
||||||
|
$imgPattern = '/src=["\']?(https?:\/\/www\.cinemapassion\.com\/covers_temp\/covers\d*\/[^"\'\s>]+\.jpg)["\']?/i';
|
||||||
|
if (preg_match($imgPattern, $html, $imgMatches)) {
|
||||||
|
$posterUrl = str_replace('http://', 'https://', $imgMatches[1]);
|
||||||
|
error_log("CinemaPassion: Image trouvée (fallback) pour '{$cleanTitle}' → {$posterUrl}");
|
||||||
|
return [
|
||||||
|
'poster' => $posterUrl,
|
||||||
|
'title' => $cleanTitle,
|
||||||
|
'format' => 'Blu-ray'
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log si l'image n'est pas trouvée pour pouvoir debugger
|
error_log("CinemaPassion: Image NON trouvée pour '{$cleanTitle}'");
|
||||||
error_log("CinemaPassion: Image non trouvée pour " . $cleanTitle);
|
|
||||||
return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user