Actualiser api.php

This commit is contained in:
2026-06-26 14:03:45 +02:00
parent 61352a6aa2
commit 311e11cce4
+81 -40
View File
@@ -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 2 : Trouver le lien qui correspond EXACTEMENT au titre
// Pattern : <a href='../film/Saw-3814.php'>Saw</a>
$filmUrl = null;
$filmName = null;
$filmId = null;
// Chercher tous les liens vers des films
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];
// ÉTAPE 3 : Essayer plusieurs pages pour trouver l'image // Vérifier si le titre du lien correspond au titre recherché
$pagesToTry = [ if (strcasecmp($linkTitle, $cleanTitle) === 0 ||
"https://www.cinemapassion.com/jaquette-dvd-{$filmName}-{$filmId}.php", stripos($linkTitle, $cleanTitle) !== false ||
"https://www.cinemapassion.com/jaquette-blu-ray-{$filmName}-{$filmId}.php", stripos($cleanTitle, $linkTitle) !== false) {
"https://www.cinemapassion.com/film/{$filmName}-{$filmId}.php", $filmUrl = "https://www.cinemapassion.com/film/{$linkName}-{$linkId}.php";
"https://www.cinemapassion.com/sticker-dvd-{$filmName}-{$filmId}.php", $filmName = $linkName;
]; $filmId = $linkId;
break;
foreach ($pagesToTry as $pageUrl) {
$pageRes = httpGet($pageUrl, 10);
if ($pageRes) {
// 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', $pageRes, $imgMatches)) {
$posterUrl = $imgMatches[1];
$posterUrl = str_replace('http://', 'https://', $posterUrl);
error_log("CinemaPassion OK: '{$cleanTitle}' → {$posterUrl}");
return ['poster' => $posterUrl, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
}
// 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'];
} }