]*class=[\'"](?:affiche|poster|movie-poster)[^"]*"[^>]*>.*?
![]()
]*src=[\'"]([^\'"]+)[\'"][^>]*>/is', $filmRes, $imgMatches)) {
- $posterUrl = $imgMatches[1];
- }
- // Méthode 3 : Chercher toute image de film
- elseif (preg_match('/
![]()
]*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;
- }
-
- return [
- 'poster' => $posterUrl,
- 'title' => $cleanTitle,
- 'format' => 'Blu-ray'
- ];
- }
- }
+ $posterUrl = null;
+
+ // 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'];
}
+ }
+
+ // 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;
- // É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 ($omdbKey) {
+ $omdbUrl = "http://www.omdbapi.com/?apikey=" . urlencode($omdbKey) . "&t=" . urlencode($cleanTitle);
+ if (!empty($year)) $omdbUrl .= "&y=" . urlencode($year);
- $searchRes = httpGet($searchUrl, 10, $userAgent);
+ $omdbRes = httpGet($omdbUrl, 5);
+ $omdbData = $omdbRes ? json_decode($omdbRes, true) : null;
- if ($searchRes && preg_match('/
]*>/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('/
]*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'
- ];
- }
+ if ($omdbData && isset($omdbData['Poster']) && $omdbData['Poster'] !== 'N/A') {
+ $posterUrl = $omdbData['Poster'];
}
}
}
-
- return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
+
+ return [
+ 'poster' => $posterUrl ?: $defaultPoster,
+ 'title' => $cleanTitle,
+ 'format' => 'Blu-ray' // Le format réel est affiné par detectFormat() plus tard
+ ];
}
// ── ROUTEUR PRINCIPAL ──