Actualiser api.php

This commit is contained in:
2026-06-26 13:07:17 +02:00
parent b0810fe59d
commit db4b030087
+54 -67
View File
@@ -120,8 +120,8 @@ function extractYear($dateStr) {
return '';
}
// ── FONCTION POUR RÉCUPÉRER LES IMAGES DEPUIS NOTRECINEMA.COM ──
function fetchNotreCinema($title, $year = '', $ean = '', $pdo = null) {
// ── FONCTION POUR RÉCUPÉRER LES IMAGES DEPUIS CINEMAPASSION.COM ──
function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = null) {
$defaultPoster = 'assets/img/default_physical_media.jpg';
if (empty($title)) {
@@ -131,60 +131,44 @@ function fetchNotreCinema($title, $year = '', $ean = '', $pdo = null) {
$cleanTitle = cleanTitle($title);
$userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
// ÉTAPE 1 : Recherche via l'URL de recherche de notrecinema.com
$searchUrl = "https://www.notrecinema.com/communaute/recherche.php3?recherche=" . urlencode($cleanTitle);
if (!empty($year)) {
$searchUrl .= "&annee=" . $year;
}
// ÉTAPE 1 : Recherche sur cinemapassion.com
$searchUrl = "https://www.cinemapassion.com/recherche.php?recherche=" . urlencode($cleanTitle);
$searchRes = httpGet($searchUrl, 10, $userAgent);
if ($searchRes) {
// Extraire l'ID du film depuis les liens vers les fiches
// Format : /communaute/v1_detail_film.php3?lefilm=123
if (preg_match('/v1_detail_film\.php3\?lefilm=(\d+)/i', $searchRes, $matches)) {
$filmId = $matches[1];
// Extraire le lien vers la page du film
// Pattern typique : <a href="film-12345.html"> ou similaire
if (preg_match('/<a href="([^"]*film[^"]*\.php|[^"]*film[^"]*\.html)"[^>]*>' . preg_quote($cleanTitle, '/') . '/i', $searchRes, $matches)) {
$filmUrl = $matches[1];
if (strpos($filmUrl, 'http') !== 0) {
$filmUrl = 'https://www.cinemapassion.com' . (strpos($filmUrl, '/') === 0 ? '' : '/') . $filmUrl;
}
// ÉTAPE 2 : Récupérer la page des jaquettes
$jaquettesUrl = "https://www.notrecinema.com/communaute/pdf/complete.php3?lefilm=" . $filmId;
$jaquettesRes = httpGet($jaquettesUrl, 10, $userAgent);
$filmRes = httpGet($filmUrl, 10, $userAgent);
if ($jaquettesRes) {
if ($filmRes) {
$posterUrl = null;
// Méthode 1 : Extraire depuis data-src des img.poster (lazy loading)
if (preg_match_all('/<img[^>]*class=[\'"]poster[\'"][^>]*data-src=[\'"]([^\'"]+)[\'"][^>]*>/i', $jaquettesRes, $imgMatches)) {
if (!empty($imgMatches[1])) {
$posterUrl = $imgMatches[1][0];
}
// Méthode 1 : Chercher l'image d'affiche principale
if (preg_match('/<img[^>]*class=[\'"](?:affiche|poster|movie-poster)[^"]*"[^>]*src=[\'"]([^\'"]+)[\'"][^>]*>/i', $filmRes, $imgMatches)) {
$posterUrl = $imgMatches[1];
}
// Méthode 2 : Fallback sur les images dans <noscript>
if (empty($posterUrl)) {
if (preg_match_all('/<noscript>.*?<img[^>]*src=[\'"]([^\'"]+\.jpg)[\'"][^>]*>/is', $jaquettesRes, $noscriptMatches)) {
if (!empty($noscriptMatches[1])) {
$posterUrl = $noscriptMatches[1][0];
}
}
// Méthode 2 : Chercher dans une div dédiée
elseif (preg_match('/<div[^>]*class=[\'"](?:affiche|poster|movie-poster)[^"]*"[^>]*>.*?<img[^>]*src=[\'"]([^\'"]+)[\'"][^>]*>/is', $filmRes, $imgMatches)) {
$posterUrl = $imgMatches[1];
}
// Méthode 3 : Chercher toute image de jaquette
if (empty($posterUrl)) {
if (preg_match('/https?:\/\/[ac]\.notrecinema\.com\/[^"\']+\/jaquette[^"\']*\.jpg/i', $jaquettesRes, $imgMatches)) {
$posterUrl = $imgMatches[0];
}
// Méthode 3 : Chercher toute image de film
elseif (preg_match('/<img[^>]*src=[\'"](https?:\/\/www\.cinemapassion\.com\/[^\'"]*\/?(?:affiches|posters|images|films)[^\'"]*\.(?:jpg|jpeg|png|webp))[^>]*>/i', $filmRes, $imgMatches)) {
$posterUrl = $imgMatches[1];
}
if (!empty($posterUrl)) {
// S'assurer que l'URL est absolue
if (strpos($posterUrl, 'http') !== 0) {
$posterUrl = 'https://www.notrecinema.com' . $posterUrl;
$posterUrl = 'https://www.cinemapassion.com' . (strpos($posterUrl, '/') === 0 ? '' : '/') . $posterUrl;
}
// Convertir les vignettes en images complètes si possible
$posterUrl = str_replace('/vign/', '/', $posterUrl);
$posterUrl = str_replace('vign_', '', $posterUrl);
return [
'poster' => $posterUrl,
'title' => $cleanTitle,
@@ -193,25 +177,27 @@ function fetchNotreCinema($title, $year = '', $ean = '', $pdo = null) {
}
}
}
}
// ÉTAPE 3 : Recherche alternative par EAN si disponible
if (!empty($ean)) {
$cleanEan = preg_replace('/[^0-9]/', '', $ean);
$searchUrl = "https://www.notrecinema.com/communaute/recherche.php3?recherche=" . urlencode($cleanEan);
$searchRes = httpGet($searchUrl, 10, $userAgent);
if ($searchRes && preg_match('/v1_detail_film\.php3\?lefilm=(\d+)/i', $searchRes, $matches)) {
$filmId = $matches[1];
$jaquettesUrl = "https://www.notrecinema.com/communaute/pdf/complete.php3?lefilm=" . $filmId;
$jaquettesRes = httpGet($jaquettesUrl, 10, $userAgent);
// ÉTAPE 2 : Recherche alternative par EAN si disponible
if (!empty($ean)) {
$cleanEan = preg_replace('/[^0-9]/', '', $ean);
$searchUrl = "https://www.cinemapassion.com/recherche.php?recherche=" . urlencode($cleanEan);
if ($jaquettesRes) {
if (preg_match('/https?:\/\/[ac]\.notrecinema\.com\/[^"\']+\/jaquette[^"\']*\.jpg/i', $jaquettesRes, $imgMatches)) {
$posterUrl = $imgMatches[0];
$posterUrl = str_replace('/vign/', '/', $posterUrl);
$posterUrl = str_replace('vign_', '', $posterUrl);
$searchRes = httpGet($searchUrl, 10, $userAgent);
if ($searchRes && preg_match('/<a href="([^"]*film[^"]*\.php|[^"]*film[^"]*\.html)"[^>]*>/i', $searchRes, $matches)) {
$filmUrl = $matches[1];
if (strpos($filmUrl, 'http') !== 0) {
$filmUrl = 'https://www.cinemapassion.com' . (strpos($filmUrl, '/') === 0 ? '' : '/') . $filmUrl;
}
$filmRes = httpGet($filmUrl, 10, $userAgent);
if ($filmRes && preg_match('/<img[^>]*src=[\'"](https?:\/\/www\.cinemapassion\.com\/[^\'"]*\/?(?:affiches|posters|images|films)[^\'"]*\.(?:jpg|jpeg|png|webp))[^>]*>/i', $filmRes, $imgMatches)) {
$posterUrl = $imgMatches[1];
if (strpos($posterUrl, 'http') !== 0) {
$posterUrl = 'https://www.cinemapassion.com' . (strpos($posterUrl, '/') === 0 ? '' : '/') . $posterUrl;
}
return [
'poster' => $posterUrl,
@@ -555,9 +541,9 @@ case 'get_config_keys':
$id = makeStableId('videotheque', $title, $year);
// Utiliser notrecinema.com pour récupérer l'image
$notreCinemaData = fetchNotreCinema($title, $year, $ean, $pdo);
$poster = $notreCinemaData['poster'];
// Utiliser cinemapassion.com pour récupérer l'image
$cinemaPassionData = fetchCinemaPassion($title, $year, $ean, $pdo);
$poster = $cinemaPassionData['poster'];
// Déterminer le format
$format = 'Blu-ray';
@@ -598,13 +584,14 @@ case 'get_config_keys':
echo json_encode(["success" => true, "imported" => $imported]);
break;
case 'debug_notrecinema':
$title = $_GET['title'] ?? '';
$year = $_GET['year'] ?? '';
$result = fetchNotreCinema($title, $year, '', $pdo);
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
exit;
break;
case 'debug_cinemapassion':
$title = $_GET['title'] ?? '';
$year = $_GET['year'] ?? '';
$ean = $_GET['ean'] ?? '';
$result = fetchCinemaPassion($title, $year, $ean, $pdo);
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
exit;
break;
}
?>