Actualiser api.php
This commit is contained in:
@@ -120,7 +120,7 @@ function extractYear($dateStr) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// ── FONCTION POUR RÉCUPÉRER LES IMAGES DEPUIS CINEMAPASSION.COM ──
|
||||
// ── FONCTION DE RÉCUPÉRATION (Mise à jour TMDB / OMDb) ──
|
||||
function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = null) {
|
||||
$defaultPoster = 'assets/img/default_physical_media.jpg';
|
||||
|
||||
@@ -129,88 +129,43 @@ function fetchCinemaPassion($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 sur cinemapassion.com
|
||||
$searchUrl = "https://www.cinemapassion.com/recherche.php?recherche=" . urlencode($cleanTitle);
|
||||
|
||||
$searchRes = httpGet($searchUrl, 10, $userAgent);
|
||||
|
||||
if ($searchRes) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
$filmRes = httpGet($filmUrl, 10, $userAgent);
|
||||
|
||||
if ($filmRes) {
|
||||
$posterUrl = null;
|
||||
|
||||
// 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];
|
||||
// 1. Recherche ultra-rapide via TMDB (Déjà configuré et prioritaire)
|
||||
$tmdbKey = getTmdbApiKey($pdo);
|
||||
if ($tmdbKey) {
|
||||
$tmdbData = fetchTMDBFull($cleanTitle, $year, $tmdbKey, $pdo);
|
||||
if ($tmdbData && !empty($tmdbData['poster'])) {
|
||||
$posterUrl = $tmdbData['poster'];
|
||||
}
|
||||
// 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 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.cinemapassion.com' . (strpos($posterUrl, '/') === 0 ? '' : '/') . $posterUrl;
|
||||
// 2. Fallback sur OMDb (si l'API est configurée en BDD)
|
||||
if (empty($posterUrl)) {
|
||||
$stmt = $pdo->prepare("SELECT key_value FROM config WHERE key_name = 'omdb_api_key'");
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch();
|
||||
$omdbKey = $row ? decryptData($row['key_value']) : null;
|
||||
|
||||
if ($omdbKey) {
|
||||
$omdbUrl = "http://www.omdbapi.com/?apikey=" . urlencode($omdbKey) . "&t=" . urlencode($cleanTitle);
|
||||
if (!empty($year)) $omdbUrl .= "&y=" . urlencode($year);
|
||||
|
||||
$omdbRes = httpGet($omdbUrl, 5);
|
||||
$omdbData = $omdbRes ? json_decode($omdbRes, true) : null;
|
||||
|
||||
if ($omdbData && isset($omdbData['Poster']) && $omdbData['Poster'] !== 'N/A') {
|
||||
$posterUrl = $omdbData['Poster'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'poster' => $posterUrl,
|
||||
'poster' => $posterUrl ?: $defaultPoster,
|
||||
'title' => $cleanTitle,
|
||||
'format' => 'Blu-ray'
|
||||
'format' => 'Blu-ray' // Le format réel est affiné par detectFormat() plus tard
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// É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);
|
||||
|
||||
$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,
|
||||
'title' => $cleanTitle,
|
||||
'format' => 'Blu-ray'
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
||||
}
|
||||
|
||||
// ── ROUTEUR PRINCIPAL ──
|
||||
|
||||
|
||||
Reference in New Issue
Block a user