Actualiser api.php
This commit is contained in:
@@ -107,7 +107,6 @@ function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = null) {
|
||||
|
||||
$baseUrl = 'https://www.cinemapassion.com';
|
||||
|
||||
// Helper curl GET réutilisable (toujours FOLLOW)
|
||||
$curlGet = function(string $url) use ($baseUrl): ?string {
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, [
|
||||
@@ -127,7 +126,6 @@ function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = null) {
|
||||
return ($code === 200 && is_string($res) && strlen($res) > 0) ? $res : null;
|
||||
};
|
||||
|
||||
// Helper : extraire l'URL de l'image covers_temp dans un bloc HTML
|
||||
$extractImage = function(?string $html): ?string {
|
||||
if (!$html) return null;
|
||||
if (preg_match(
|
||||
@@ -135,7 +133,6 @@ function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = null) {
|
||||
$html, $m
|
||||
)) {
|
||||
$img = str_replace('http://', 'https://', $m[1]);
|
||||
// Exclure les miniatures/vignettes
|
||||
if (strpos($img, 'miniature') === false && strpos($img, 'vign') === false) {
|
||||
return $img;
|
||||
}
|
||||
@@ -145,6 +142,7 @@ function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = null) {
|
||||
|
||||
// ── ÉTAPE 1 : recherche ──
|
||||
$searchHtml = $curlGet($baseUrl . '/recherche.php?recherche=' . urlencode($cleanTitle));
|
||||
|
||||
if (!$searchHtml) {
|
||||
// Fallback POST
|
||||
$ch = curl_init($baseUrl . '/moteur2.php');
|
||||
@@ -159,27 +157,31 @@ function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = null) {
|
||||
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
|
||||
CURLOPT_REFERER => $baseUrl . '/',
|
||||
]);
|
||||
$searchHtml = curl_exec($ch);
|
||||
$searchHtml = curl_exec($ch) ?: null;
|
||||
curl_close($ch);
|
||||
}
|
||||
if (!$searchHtml) return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
||||
|
||||
// ── ÉTAPE 2 : trouver la fiche film ──
|
||||
// Si la recherche a déjà livré une page film (redirection directe)
|
||||
// ── ÉTAPE 2 : trouver et charger la fiche film ──
|
||||
// Regex corrigée : gère /film/, ../film/, et URL absolue complète
|
||||
$regexFilm = '/href=["\']?(?:https?:\/\/(?:www\.)?cinemapassion\.com)?\/? (?:\.\./)?(film[\/-][^"\'\s>]+)["\']?/i';
|
||||
|
||||
$filmHtml = null;
|
||||
if (preg_match('/covers_temp\/covers/i', $searchHtml)) {
|
||||
// La page de recherche est déjà la page jaquette (cas rare)
|
||||
if ($extractImage($searchHtml)) {
|
||||
// Redirection directe sur la page jaquette
|
||||
$filmHtml = $searchHtml;
|
||||
} elseif (preg_match('/href=["\']?(?:https?:\/\/(?:www\.)?cinemapassion\.com\/)?(film[\/\-][^"\'\s>]+)["\']?/i', $searchHtml, $m)) {
|
||||
$filmHtml = $curlGet($baseUrl . '/' . ltrim($m[1], './'));
|
||||
} elseif (preg_match($regexFilm, $searchHtml, $m)) {
|
||||
$filmHtml = $curlGet($baseUrl . '/' . ltrim($m[1], '/'));
|
||||
}
|
||||
|
||||
if (!$filmHtml) return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
||||
|
||||
// ── ÉTAPE 3 : trouver la page jaquette depuis la fiche film ──
|
||||
// Pattern : /jaquette-dvd-Saw-3814.php ou /jaquette-blu-ray-...
|
||||
if (preg_match('/href=["\']?(?:https?:\/\/(?:www\.)?cinemapassion\.com\/)?(jaquette-(?:dvd|blu-ray)-[^"\'\s>]+)["\']?/i', $filmHtml, $m)) {
|
||||
$jaqHtml = $curlGet($baseUrl . '/' . ltrim($m[1], './'));
|
||||
// ── ÉTAPE 3 : page jaquette depuis la fiche film ──
|
||||
// Regex corrigée : gère /jaquette-, ../jaquette-, et URL absolue complète
|
||||
$regexJaq = '/href=["\']?(?:https?:\/\/(?:www\.)?cinemapassion\.com)?\/? (?:\.\./)?(jaquette-(?:dvd|blu-ray)-[^"\'\s>]+)["\']?/i';
|
||||
|
||||
if (preg_match($regexJaq, $filmHtml, $m)) {
|
||||
$jaqHtml = $curlGet($baseUrl . '/' . ltrim($m[1], '/'));
|
||||
// curl suit automatiquement la redirection vers /dump/generation_page_covers3.php
|
||||
$img = $extractImage($jaqHtml);
|
||||
if ($img) return ['poster' => $img, 'title' => $cleanTitle, 'format' => detectFormat($cleanTitle)];
|
||||
@@ -192,67 +194,6 @@ function fetchCinemaPassion($title, $year = '', $ean = '', $pdo = null) {
|
||||
return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
||||
}
|
||||
|
||||
// ── API TMDB (uniquement pour les critiques) ──
|
||||
function fetchTMDBFull($title, $year, $apiKey, $pdo) {
|
||||
if (empty($apiKey) || empty($title)) return null;
|
||||
$cleanTitle = cleanTitle($title);
|
||||
$searchUrl = "https://api.themoviedb.org/3/search/movie?api_key={$apiKey}&query=" . urlencode($cleanTitle) . "&year={$year}&language=fr-FR";
|
||||
$searchRes = httpGet($searchUrl, 5);
|
||||
$searchData = $searchRes ? json_decode($searchRes, true) : [];
|
||||
if (empty($searchData['results'])) {
|
||||
$searchUrl = "https://api.themoviedb.org/3/search/movie?api_key={$apiKey}&query=" . urlencode($cleanTitle) . "&language=fr-FR";
|
||||
$searchRes = httpGet($searchUrl, 5);
|
||||
$searchData = $searchRes ? json_decode($searchRes, true) : [];
|
||||
}
|
||||
if (empty($searchData['results'])) return null;
|
||||
$movieId = $searchData['results'][0]['id'];
|
||||
$detailsUrl = "https://api.themoviedb.org/3/movie/{$movieId}?api_key={$apiKey}&append_to_response=credits,watch/providers,translations&language=fr-FR";
|
||||
$detailsRes = httpGet($detailsUrl, 5);
|
||||
if (!$detailsRes) return null;
|
||||
$details = json_decode($detailsRes, true);
|
||||
$frenchTitle = $details['title'] ?? '';
|
||||
if (!empty($details['translations']['translations'])) {
|
||||
foreach ($details['translations']['translations'] as $translation) {
|
||||
if ($translation['iso_3166_1'] === 'FR' && !empty($translation['data']['title'])) {
|
||||
$frenchTitle = $translation['data']['title'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$director = '';
|
||||
if (!empty($details['credits']['crew'])) {
|
||||
$directorsList = [];
|
||||
foreach ($details['credits']['crew'] as $crew) {
|
||||
if ($crew['job'] === 'Director') $directorsList[] = $crew['name'];
|
||||
}
|
||||
$director = implode(', ', $directorsList);
|
||||
}
|
||||
$cast = [];
|
||||
if (!empty($details['credits']['cast'])) {
|
||||
$topCast = array_slice($details['credits']['cast'], 0, 4);
|
||||
foreach ($topCast as $actor) $cast[] = $actor['name'];
|
||||
}
|
||||
$streaming = '';
|
||||
$frProviders = $details['watch/providers']['results']['FR'] ?? [];
|
||||
$platforms = [];
|
||||
if (!empty($frProviders['flatrate'])) { foreach ($frProviders['flatrate'] as $p) $platforms[] = $p['provider_name']; }
|
||||
if (empty($platforms)) {
|
||||
if (!empty($frProviders['rent'])) { foreach ($frProviders['rent'] as $p) $platforms[] = $p['provider_name'] . ' (loc.)'; }
|
||||
if (!empty($frProviders['buy'])) { foreach ($frProviders['buy'] as $p) $platforms[] = $p['provider_name'] . ' (achat)'; }
|
||||
}
|
||||
if (!empty($platforms)) $streaming = implode(', ', array_unique($platforms));
|
||||
return [
|
||||
'title' => $frenchTitle,
|
||||
'year' => !empty($details['release_date']) ? substr($details['release_date'], 0, 4) : '',
|
||||
'director' => $director,
|
||||
'poster' => !empty($details['poster_path']) ? "https://image.tmdb.org/t/p/w500" . $details['poster_path'] : '',
|
||||
'length' => !empty($details['runtime']) ? $details['runtime'] . ' min' : '',
|
||||
'streaming' => $streaming,
|
||||
'overview' => $details['overview'] ?? '',
|
||||
'cast' => $cast
|
||||
];
|
||||
}
|
||||
|
||||
// ── ROUTEUR PRINCIPAL ──
|
||||
$action = $_GET['action'] ?? '';
|
||||
$data = json_decode(file_get_contents('php://input'), true) ?? [];
|
||||
|
||||
Reference in New Issue
Block a user