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