From 835b875f0f7d799d9c70ea73c6d330a0fd7fd0af Mon Sep 17 00:00:00 2001 From: Cedric Date: Fri, 26 Jun 2026 13:37:11 +0200 Subject: [PATCH] Actualiser api.php --- api.php | 119 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 99 insertions(+), 20 deletions(-) diff --git a/api.php b/api.php index 9e53116..2677605 100644 --- a/api.php +++ b/api.php @@ -118,38 +118,117 @@ function extractYear($dateStr) { return ''; } +// ── FONCTION POUR RÉCUPÉRER LES IMAGES DEPUIS CINEMAPASSION.COM ── function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = null) { $defaultPoster = 'assets/img/default_physical_media.jpg'; $cleanTitle = cleanTitle($title); - // 1. Recherche - $searchUrl = "https://www.cinemapassion.com/recherche.php?recherche=" . urlencode($cleanTitle); - $searchRes = httpGet($searchUrl); + if (empty($cleanTitle)) { + return ['poster' => $defaultPoster, 'title' => '', 'format' => 'Blu-ray']; + } - if ($searchRes) { - // Recherche d'un lien contenant 'film-' et un chiffre - if (preg_match('/href=["\'](\.\.\/film\/[^\'"]+-\d+\.php)["\']/i', $searchRes, $matches)) { - $filmUrl = 'https://www.cinemapassion.com/' . ltrim($matches[1], './'); - $filmRes = httpGet($filmUrl); + $userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36'; + + // ── ÉTAPE 1 : Recherche via POST sur /moteur2.php (le vrai moteur du site) ── + $searchUrl = "https://www.cinemapassion.com/moteur2.php"; + + $ch = curl_init($searchUrl); + curl_setopt_array($ch, [ + CURLOPT_RETURNTRANSFER => true, + CURLOPT_TIMEOUT => 15, + CURLOPT_CONNECTTIMEOUT => 5, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_USERAGENT => $userAgent, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => http_build_query(['recherche' => $cleanTitle]), + CURLOPT_REFERER => 'https://www.cinemapassion.com/', + CURLOPT_HTTPHEADER => [ + 'Content-Type: application/x-www-form-urlencoded', + 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', + 'Accept-Language: fr-FR,fr;q=0.8', + 'Origin: https://www.cinemapassion.com' + ], + ]); + $searchRes = curl_exec($ch); + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + $html = ($code === 200 && $searchRes) ? $searchRes : null; + + if ($html) { + // ── ÉTAPE 2 : Extraire le lien vers la page du film ── + // Pattern trouvé dans le HTML : href='../film/Saw-3814.php' + if (preg_match('/href=["\']([^"\']*film\/[^"\'\/]+-\d+\.php)["\']/i', $html, $matches)) { + $filmPath = $matches[1]; - if ($filmRes) { - // Regex améliorée : Cherche n'importe quel img src contenant 'covers' - // sans se limiter à 'covers3' et accepte quotes simples ou doubles - $pattern = '/src=["\'](http:\/\/www\.cinemapassion\.com\/covers_temp\/covers[^"\']+\.jpg)["\']/i'; + // Normaliser l'URL (supprimer les ../) + $filmPath = str_replace('../', '', $filmPath); + if (strpos($filmPath, '/') !== 0) { + $filmUrl = 'https://www.cinemapassion.com/' . $filmPath; + } else { + $filmUrl = 'https://www.cinemapassion.com' . $filmPath; + } + + // Extraire le nom-slug et l'ID numérique + // Ex: film/Saw-3814.php → filmName=Saw, filmId=3814 + if (preg_match('/film\/([^\/]+)-(\d+)\.php/i', $filmUrl, $filmMatches)) { + $filmName = $filmMatches[1]; + $filmId = $filmMatches[2]; - if (preg_match($pattern, $filmRes, $imgMatches)) { - return [ - 'poster' => $imgMatches[1], - 'title' => $cleanTitle, - 'format' => 'Blu-ray' - ]; + // ── ÉTAPE 3 : Essayer plusieurs pages pour trouver l'image ── + $pagesToTry = [ + // Page jaquette DVD (la plus probable) + "https://www.cinemapassion.com/jaquette-dvd-{$filmName}-{$filmId}.php", + // Page jaquette Blu-ray + "https://www.cinemapassion.com/jaquette-blu-ray-{$filmName}-{$filmId}.php", + // Page fiche complète du film + $filmUrl, + // Page sticker + "https://www.cinemapassion.com/sticker-dvd-{$filmName}-{$filmId}.php", + ]; + + foreach ($pagesToTry as $pageUrl) { + $pageRes = httpGet($pageUrl, 10, $userAgent); + + if ($pageRes) { + // Pattern pour l'image : src='http://www.cinemapassion.com/covers_temp/covers3/Saw-13005811062007.jpg' + // Accepte http ET https, covers avec ou sans chiffre (covers, covers2, covers3...) + $imgPattern = '/src=["\']?(https?:\/\/www\.cinemapassion\.com\/covers_temp\/covers\d*\/[^"\'\s>]+\.jpg)["\']?/i'; + + if (preg_match($imgPattern, $pageRes, $imgMatches)) { + $posterUrl = $imgMatches[1]; + + // Forcer HTTPS pour éviter les mixed content + $posterUrl = str_replace('http://', 'https://', $posterUrl); + + error_log("CinemaPassion: Image trouvée pour '{$cleanTitle}' → {$posterUrl}"); + + return [ + 'poster' => $posterUrl, + 'title' => $cleanTitle, + 'format' => 'Blu-ray' + ]; + } + } } } } + + // ── FALLBACK : Chercher directement une image covers_temp dans les résultats ── + $imgPattern = '/src=["\']?(https?:\/\/www\.cinemapassion\.com\/covers_temp\/covers\d*\/[^"\'\s>]+\.jpg)["\']?/i'; + if (preg_match($imgPattern, $html, $imgMatches)) { + $posterUrl = str_replace('http://', 'https://', $imgMatches[1]); + error_log("CinemaPassion: Image trouvée (fallback) pour '{$cleanTitle}' → {$posterUrl}"); + return [ + 'poster' => $posterUrl, + 'title' => $cleanTitle, + 'format' => 'Blu-ray' + ]; + } } - // Log si l'image n'est pas trouvée pour pouvoir debugger - error_log("CinemaPassion: Image non trouvée pour " . $cleanTitle); + error_log("CinemaPassion: Image NON trouvée pour '{$cleanTitle}'"); return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray']; }