Actualiser api.php
This commit is contained in:
@@ -137,7 +137,7 @@ function detectFormat($title, $desc = '') {
|
|||||||
return 'Blu-ray';
|
return 'Blu-ray';
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── FONCTION PRINCIPALE : CINEMAPASSION.COM ──
|
// ── 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);
|
||||||
@@ -149,52 +149,93 @@ function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = null) {
|
|||||||
// ÉTAPE 1 : Recherche POST sur /moteur2.php
|
// ÉTAPE 1 : Recherche POST sur /moteur2.php
|
||||||
$searchRes = httpPost('https://www.cinemapassion.com/moteur2.php', ['recherche' => $cleanTitle]);
|
$searchRes = httpPost('https://www.cinemapassion.com/moteur2.php', ['recherche' => $cleanTitle]);
|
||||||
|
|
||||||
if ($searchRes) {
|
if (!$searchRes) {
|
||||||
// ÉTAPE 2 : Extraire le lien vers la page du film
|
error_log("CinemaPassion: Recherche échouée pour '{$cleanTitle}'");
|
||||||
// Pattern : href='../film/Saw-3814.php' ou href='film/Saw-3814.php'
|
return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
||||||
if (preg_match('/href=["\']?(?:\.\.\/)?film\/([^"\'\s]+)-(\d+)\.php["\']?/i', $searchRes, $matches)) {
|
}
|
||||||
$filmName = $matches[1];
|
|
||||||
$filmId = $matches[2];
|
|
||||||
|
|
||||||
// ÉTAPE 3 : Essayer plusieurs pages pour trouver l'image
|
// ÉTAPE 2 : Trouver le lien qui correspond EXACTEMENT au titre
|
||||||
$pagesToTry = [
|
// Pattern : <a href='../film/Saw-3814.php'>Saw</a>
|
||||||
"https://www.cinemapassion.com/jaquette-dvd-{$filmName}-{$filmId}.php",
|
$filmUrl = null;
|
||||||
"https://www.cinemapassion.com/jaquette-blu-ray-{$filmName}-{$filmId}.php",
|
$filmName = null;
|
||||||
"https://www.cinemapassion.com/film/{$filmName}-{$filmId}.php",
|
$filmId = null;
|
||||||
"https://www.cinemapassion.com/sticker-dvd-{$filmName}-{$filmId}.php",
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($pagesToTry as $pageUrl) {
|
// Chercher tous les liens vers des films
|
||||||
$pageRes = httpGet($pageUrl, 10);
|
if (preg_match_all('/<a\s+href=["\']?(?:\.\.\/)?film\/([^"\'\s]+)-(\d+)\.php["\']?[^>]*>([^<]+)<\/a>/i', $searchRes, $matches, PREG_SET_ORDER)) {
|
||||||
|
foreach ($matches as $match) {
|
||||||
|
$linkTitle = trim($match[3]);
|
||||||
|
$linkName = $match[1];
|
||||||
|
$linkId = $match[2];
|
||||||
|
|
||||||
if ($pageRes) {
|
// Vérifier si le titre du lien correspond au titre recherché
|
||||||
// Pattern : src='http://www.cinemapassion.com/covers_temp/covers3/Saw-13005811062007.jpg'
|
if (strcasecmp($linkTitle, $cleanTitle) === 0 ||
|
||||||
if (preg_match('/src=["\']?(https?:\/\/(?:www\.)?cinemapassion\.com\/covers_temp\/covers\d*\/[^"\'\s>]+\.jpg)["\']?/i', $pageRes, $imgMatches)) {
|
stripos($linkTitle, $cleanTitle) !== false ||
|
||||||
$posterUrl = $imgMatches[1];
|
stripos($cleanTitle, $linkTitle) !== false) {
|
||||||
$posterUrl = str_replace('http://', 'https://', $posterUrl);
|
$filmUrl = "https://www.cinemapassion.com/film/{$linkName}-{$linkId}.php";
|
||||||
error_log("CinemaPassion OK: '{$cleanTitle}' → {$posterUrl}");
|
$filmName = $linkName;
|
||||||
return ['poster' => $posterUrl, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
$filmId = $linkId;
|
||||||
}
|
break;
|
||||||
|
|
||||||
// Fallback : image dans lesaffiches/
|
|
||||||
if (preg_match('/src=["\']?(https?:\/\/(?:www\.)?cinemapassion\.com\/lesaffiches\/[^"\'\s>]+\.jpg)["\']?/i', $pageRes, $imgMatches)) {
|
|
||||||
$posterUrl = $imgMatches[1];
|
|
||||||
$posterUrl = str_replace('http://', 'https://', $posterUrl);
|
|
||||||
error_log("CinemaPassion OK (affiche): '{$cleanTitle}' → {$posterUrl}");
|
|
||||||
return ['poster' => $posterUrl, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback : chercher directement une image covers_temp dans les résultats
|
// Si pas de correspondance exacte, prendre le premier résultat
|
||||||
if (preg_match('/src=["\']?(https?:\/\/(?:www\.)?cinemapassion\.com\/covers_temp\/covers\d*\/[^"\'\s>]+\.jpg)["\']?/i', $searchRes, $imgMatches)) {
|
if (!$filmUrl && !empty($matches)) {
|
||||||
$posterUrl = str_replace('http://', 'https://', $imgMatches[1]);
|
$filmName = $matches[0][1];
|
||||||
error_log("CinemaPassion OK (direct): '{$cleanTitle}' → {$posterUrl}");
|
$filmId = $matches[0][2];
|
||||||
return ['poster' => $posterUrl, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
$filmUrl = "https://www.cinemapassion.com/film/{$filmName}-{$filmId}.php";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$filmUrl) {
|
||||||
|
error_log("CinemaPassion: Film non trouvé pour '{$cleanTitle}'");
|
||||||
|
return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ÉTAPE 3 : Aller sur la page du film
|
||||||
|
$filmPageRes = httpGet($filmUrl, 10);
|
||||||
|
|
||||||
|
if (!$filmPageRes) {
|
||||||
|
error_log("CinemaPassion: Page film inaccessible : {$filmUrl}");
|
||||||
|
return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ÉTAPE 4 : Chercher le lien vers la jaquette DVD ou Blu-ray
|
||||||
|
// Pattern : <a href='../jaquette-dvd-Saw-3814.php'> ou <a href='../jaquette-blu-ray-Saw-3814.php'>
|
||||||
|
$jaquetteUrl = null;
|
||||||
|
|
||||||
|
if (preg_match('/href=["\']?(?:\.\.\/)?(jaquette-(?:dvd|blu-ray)-[^"\'\s]+\.php)["\']?/i', $filmPageRes, $matches)) {
|
||||||
|
$jaquettePath = $matches[1];
|
||||||
|
$jaquetteUrl = "https://www.cinemapassion.com/" . str_replace('../', '', $jaquettePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ÉTAPE 5 : Si page jaquette trouvée, aller dessus et extraire l'image covers_temp
|
||||||
|
if ($jaquetteUrl) {
|
||||||
|
$jaquettePageRes = httpGet($jaquetteUrl, 10);
|
||||||
|
|
||||||
|
if ($jaquettePageRes) {
|
||||||
|
// Pattern : src='http://www.cinemapassion.com/covers_temp/covers3/Saw-13005811062007.jpg'
|
||||||
|
if (preg_match('/src=["\']?(https?:\/\/(?:www\.)?cinemapassion\.com\/covers_temp\/covers\d*\/[^"\'\s>]+\.jpg)["\']?/i', $jaquettePageRes, $imgMatches)) {
|
||||||
|
$posterUrl = str_replace('http://', 'https://', $imgMatches[1]);
|
||||||
|
error_log("CinemaPassion OK (jaquette): '{$cleanTitle}' → {$posterUrl}");
|
||||||
|
return ['poster' => $posterUrl, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ÉTAPE 6 : Fallback - Chercher l'image covers_temp directement sur la page du film
|
||||||
|
if (preg_match('/src=["\']?(https?:\/\/(?:www\.)?cinemapassion\.com\/covers_temp\/covers\d*\/[^"\'\s>]+\.jpg)["\']?/i', $filmPageRes, $imgMatches)) {
|
||||||
|
$posterUrl = str_replace('http://', 'https://', $imgMatches[1]);
|
||||||
|
error_log("CinemaPassion OK (covers_temp direct): '{$cleanTitle}' → {$posterUrl}");
|
||||||
|
return ['poster' => $posterUrl, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ÉTAPE 7 : Fallback - Utiliser l'affiche trouvée sur la page du film
|
||||||
|
if (preg_match('/src=["\']?(https?:\/\/(?:www\.)?cinemapassion\.com\/lesaffiches\/[^"\'\s>]+\.jpg)["\']?/i', $filmPageRes, $imgMatches)) {
|
||||||
|
$posterUrl = str_replace('http://', 'https://', $imgMatches[1]);
|
||||||
|
error_log("CinemaPassion OK (affiche fallback): '{$cleanTitle}' → {$posterUrl}");
|
||||||
|
return ['poster' => $posterUrl, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
||||||
|
}
|
||||||
|
|
||||||
error_log("CinemaPassion KO: Image NON trouvée pour '{$cleanTitle}'");
|
error_log("CinemaPassion KO: 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