Actualiser api.php
This commit is contained in:
@@ -100,84 +100,95 @@ function detectFormat($title, $desc = '') {
|
|||||||
return 'Blu-ray';
|
return 'Blu-ray';
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 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);
|
||||||
|
|
||||||
if (empty($cleanTitle)) return ['poster' => $defaultPoster, 'title' => '', 'format' => 'Blu-ray'];
|
if (empty($cleanTitle)) return ['poster' => $defaultPoster, 'title' => '', 'format' => 'Blu-ray'];
|
||||||
|
|
||||||
$baseUrl = 'https://www.cinemapassion.com';
|
$baseUrl = 'https://www.cinemapassion.com';
|
||||||
$ch = curl_init();
|
|
||||||
curl_setopt_array($ch, [
|
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
|
||||||
CURLOPT_FOLLOWLOCATION => true, // Indispensable si le site redirige directement vers le film
|
|
||||||
CURLOPT_MAXREDIRS => 5,
|
|
||||||
CURLOPT_TIMEOUT => 15,
|
|
||||||
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
|
|
||||||
CURLOPT_COOKIEFILE => '', // Garde les cookies en RAM
|
|
||||||
CURLOPT_REFERER => 'https://www.cinemapassion.com/',
|
|
||||||
CURLOPT_SSL_VERIFYPEER => false
|
|
||||||
]);
|
|
||||||
|
|
||||||
// 1. Recherche initiale
|
// Helper curl GET réutilisable (toujours FOLLOW)
|
||||||
curl_setopt($ch, CURLOPT_URL, $baseUrl . '/recherche.php?recherche=' . urlencode($cleanTitle));
|
$curlGet = function(string $url) use ($baseUrl): ?string {
|
||||||
$html = curl_exec($ch);
|
$ch = curl_init($url);
|
||||||
$finalUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
|
curl_setopt_array($ch, [
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_FOLLOWLOCATION => true,
|
||||||
|
CURLOPT_MAXREDIRS => 5,
|
||||||
|
CURLOPT_TIMEOUT => 15,
|
||||||
|
CURLOPT_CONNECTTIMEOUT => 5,
|
||||||
|
CURLOPT_SSL_VERIFYPEER => false,
|
||||||
|
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
|
||||||
|
CURLOPT_REFERER => $baseUrl . '/',
|
||||||
|
CURLOPT_HTTPHEADER => ['Accept-Language: fr-FR,fr;q=0.8'],
|
||||||
|
]);
|
||||||
|
$res = curl_exec($ch);
|
||||||
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
curl_close($ch);
|
||||||
|
return ($code === 200 && is_string($res) && strlen($res) > 0) ? $res : null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper : extraire l'URL de l'image covers_temp dans un bloc HTML
|
||||||
|
$extractImage = function(?string $html): ?string {
|
||||||
|
if (!$html) return null;
|
||||||
|
if (preg_match(
|
||||||
|
'/src=["\']?(https?:\/\/(?:www\.)?cinemapassion\.com\/covers_temp\/covers[^"\'\s>]+)["\']?/i',
|
||||||
|
$html, $m
|
||||||
|
)) {
|
||||||
|
$img = str_replace('http://', 'https://', $m[1]);
|
||||||
|
// Exclure les miniatures/vignettes
|
||||||
|
if (strpos($img, 'miniature') === false && strpos($img, 'vign') === false) {
|
||||||
|
return $img;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// ── ÉTAPE 1 : recherche ──
|
||||||
|
$searchHtml = $curlGet($baseUrl . '/recherche.php?recherche=' . urlencode($cleanTitle));
|
||||||
|
if (!$searchHtml) {
|
||||||
|
// Fallback POST
|
||||||
|
$ch = curl_init($baseUrl . '/moteur2.php');
|
||||||
|
curl_setopt_array($ch, [
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_FOLLOWLOCATION => true,
|
||||||
|
CURLOPT_MAXREDIRS => 5,
|
||||||
|
CURLOPT_TIMEOUT => 15,
|
||||||
|
CURLOPT_SSL_VERIFYPEER => false,
|
||||||
|
CURLOPT_POST => true,
|
||||||
|
CURLOPT_POSTFIELDS => http_build_query(['recherche' => $cleanTitle]),
|
||||||
|
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
|
||||||
|
CURLOPT_REFERER => $baseUrl . '/',
|
||||||
|
]);
|
||||||
|
$searchHtml = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
}
|
||||||
|
if (!$searchHtml) return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
||||||
|
|
||||||
|
// ── ÉTAPE 2 : trouver la fiche film ──
|
||||||
|
// Si la recherche a déjà livré une page film (redirection directe)
|
||||||
$filmHtml = null;
|
$filmHtml = null;
|
||||||
$regexFilm = '/href=["\']?(?:https?:\/\/(?:www\.)?cinemapassion\.com\/)?(?:\.\.\/)?(film[\/-][^"\'\s>]+)["\']?/i';
|
if (preg_match('/covers_temp\/covers/i', $searchHtml)) {
|
||||||
|
// La page de recherche est déjà la page jaquette (cas rare)
|
||||||
// Si la recherche a redirigé directement sur la fiche du film (1 seul résultat)
|
$filmHtml = $searchHtml;
|
||||||
if (strpos($finalUrl, 'film-') !== false || strpos($finalUrl, '/film/') !== false || preg_match('/jaquette-(?:dvd|blu-ray)-/i', $html)) {
|
} elseif (preg_match('/href=["\']?(?:https?:\/\/(?:www\.)?cinemapassion\.com\/)?(film[\/\-][^"\'\s>]+)["\']?/i', $searchHtml, $m)) {
|
||||||
$filmHtml = $html;
|
$filmHtml = $curlGet($baseUrl . '/' . ltrim($m[1], './'));
|
||||||
} else {
|
|
||||||
// Chercher le lien dans les résultats de recherche GET
|
|
||||||
if ($html && preg_match($regexFilm, $html, $matches)) {
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $baseUrl . '/' . ltrim($matches[1], './'));
|
|
||||||
$filmHtml = curl_exec($ch);
|
|
||||||
} else {
|
|
||||||
// Tentative via POST si le GET échoue
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $baseUrl . '/moteur2.php');
|
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(['recherche' => $cleanTitle]));
|
|
||||||
$htmlPost = curl_exec($ch);
|
|
||||||
curl_setopt($ch, CURLOPT_POST, false);
|
|
||||||
|
|
||||||
$finalUrlPost = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
|
|
||||||
if (strpos($finalUrlPost, 'film-') !== false || strpos($finalUrlPost, '/film/') !== false) {
|
|
||||||
$filmHtml = $htmlPost;
|
|
||||||
} elseif ($htmlPost && preg_match($regexFilm, $htmlPost, $matches)) {
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $baseUrl . '/' . ltrim($matches[1], './'));
|
|
||||||
$filmHtml = curl_exec($ch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si on a récupéré le code de la fiche film
|
if (!$filmHtml) return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
||||||
if ($filmHtml) {
|
|
||||||
// Chercher la sous-page contenant la jaquette
|
|
||||||
if (preg_match('/href=["\']?(?:https?:\/\/(?:www\.)?cinemapassion\.com\/)?(?:\.\.\/)?(jaquette-(?:dvd|blu-ray)-[^"\'\s>]+)["\']?/i', $filmHtml, $jaqMatches)) {
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $baseUrl . '/' . ltrim($jaqMatches[1], './'));
|
|
||||||
$jaqHtml = curl_exec($ch);
|
|
||||||
|
|
||||||
// Extraire l'image haute définition
|
// ── ÉTAPE 3 : trouver la page jaquette depuis la fiche film ──
|
||||||
if ($jaqHtml && preg_match('/src=["\']?(https?:\/\/(?:www\.)?cinemapassion\.com\/covers_temp\/covers[^"\'\s>]+)["\']?/i', $jaqHtml, $imgMatches)) {
|
// Pattern : /jaquette-dvd-Saw-3814.php ou /jaquette-blu-ray-...
|
||||||
curl_close($ch);
|
if (preg_match('/href=["\']?(?:https?:\/\/(?:www\.)?cinemapassion\.com\/)?(jaquette-(?:dvd|blu-ray)-[^"\'\s>]+)["\']?/i', $filmHtml, $m)) {
|
||||||
return ['poster' => str_replace('http://', 'https://', $imgMatches[1]), 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
$jaqHtml = $curlGet($baseUrl . '/' . ltrim($m[1], './'));
|
||||||
}
|
// curl suit automatiquement la redirection vers /dump/generation_page_covers3.php
|
||||||
}
|
$img = $extractImage($jaqHtml);
|
||||||
|
if ($img) return ['poster' => $img, 'title' => $cleanTitle, 'format' => detectFormat($cleanTitle)];
|
||||||
// Fallback direct sur la fiche du film si la sous-page jaquette n'existe pas
|
|
||||||
if (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) {
|
|
||||||
curl_close($ch);
|
|
||||||
return ['poster' => str_replace('http://', 'https://', $imgMatches[1]), 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_close($ch);
|
// ── Fallback : image directement sur la fiche film ──
|
||||||
|
$img = $extractImage($filmHtml);
|
||||||
|
if ($img) return ['poster' => $img, 'title' => $cleanTitle, 'format' => detectFormat($cleanTitle)];
|
||||||
|
|
||||||
return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user