Actualiser api.php
This commit is contained in:
@@ -131,48 +131,60 @@ 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 sur notrecinema.com
|
// ÉTAPE 1 : Recherche via l'URL de recherche de notrecinema.com
|
||||||
$searchUrl = "https://www.notrecinema.com/communaute/stubs.php?stub=" . urlencode($cleanTitle);
|
$searchUrl = "https://www.notrecinema.com/communaute/recherche.php3?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 et le slug
|
// Extraire l'ID du film depuis les liens vers les fiches
|
||||||
if (preg_match('/v1_detail_film\.php3\?lefilm=(\d+)/', $searchRes, $matches)) {
|
// Format : /communaute/v1_detail_film.php3?lefilm=123
|
||||||
|
if (preg_match('/v1_detail_film\.php3\?lefilm=(\d+)/i', $searchRes, $matches)) {
|
||||||
$filmId = $matches[1];
|
$filmId = $matches[1];
|
||||||
|
|
||||||
// Récupérer la page des jaquettes
|
// ÉTAPE 2 : Récupérer la page des jaquettes
|
||||||
$jaquettesUrl = "https://www.notrecinema.com/communaute/pdf/complete.php3?lefilm=" . $filmId;
|
$jaquettesUrl = "https://www.notrecinema.com/communaute/pdf/complete.php3?lefilm=" . $filmId;
|
||||||
$jaquettesRes = httpGet($jaquettesUrl, 10, $userAgent);
|
$jaquettesRes = httpGet($jaquettesUrl, 10, $userAgent);
|
||||||
|
|
||||||
if ($jaquettesRes) {
|
if ($jaquettesRes) {
|
||||||
// Extraire les images de jaquettes (data-src des img.poster)
|
$posterUrl = null;
|
||||||
|
|
||||||
|
// Méthode 1 : Extraire depuis data-src des img.poster (lazy loading)
|
||||||
if (preg_match_all('/<img[^>]*class=[\'"]poster[\'"][^>]*data-src=[\'"]([^\'"]+)[\'"][^>]*>/i', $jaquettesRes, $imgMatches)) {
|
if (preg_match_all('/<img[^>]*class=[\'"]poster[\'"][^>]*data-src=[\'"]([^\'"]+)[\'"][^>]*>/i', $jaquettesRes, $imgMatches)) {
|
||||||
if (!empty($imgMatches[1])) {
|
if (!empty($imgMatches[1])) {
|
||||||
// Prendre la première jaquette disponible
|
|
||||||
$posterUrl = $imgMatches[1][0];
|
$posterUrl = $imgMatches[1][0];
|
||||||
|
|
||||||
// Convertir en URL absolue si nécessaire
|
|
||||||
if (strpos($posterUrl, 'http') !== 0) {
|
|
||||||
$posterUrl = 'https://www.notrecinema.com' . $posterUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'poster' => $posterUrl,
|
|
||||||
'title' => $cleanTitle,
|
|
||||||
'format' => 'Blu-ray'
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback : chercher dans le noscript
|
// Méthode 2 : Fallback sur les images dans <noscript>
|
||||||
|
if (empty($posterUrl)) {
|
||||||
if (preg_match_all('/<noscript>.*?<img[^>]*src=[\'"]([^\'"]+\.jpg)[\'"][^>]*>/is', $jaquettesRes, $noscriptMatches)) {
|
if (preg_match_all('/<noscript>.*?<img[^>]*src=[\'"]([^\'"]+\.jpg)[\'"][^>]*>/is', $jaquettesRes, $noscriptMatches)) {
|
||||||
if (!empty($noscriptMatches[1])) {
|
if (!empty($noscriptMatches[1])) {
|
||||||
$posterUrl = $noscriptMatches[1][0];
|
$posterUrl = $noscriptMatches[1][0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode 3 : Chercher toute image de jaquette
|
||||||
|
if (empty($posterUrl)) {
|
||||||
|
if (preg_match('/https?:\/\/[ac]\.notrecinema\.com\/[^"\']+\/jaquette[^"\']*\.jpg/i', $jaquettesRes, $imgMatches)) {
|
||||||
|
$posterUrl = $imgMatches[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($posterUrl)) {
|
||||||
|
// 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.notrecinema.com' . $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,
|
||||||
@@ -182,6 +194,33 @@ function fetchNotreCinema($title, $year = '', $ean = '', $pdo = null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ÉTAPE 3 : Recherche alternative par EAN si disponible
|
||||||
|
if (!empty($ean)) {
|
||||||
|
$cleanEan = preg_replace('/[^0-9]/', '', $ean);
|
||||||
|
$searchUrl = "https://www.notrecinema.com/communaute/recherche.php3?recherche=" . urlencode($cleanEan);
|
||||||
|
|
||||||
|
$searchRes = httpGet($searchUrl, 10, $userAgent);
|
||||||
|
|
||||||
|
if ($searchRes && preg_match('/v1_detail_film\.php3\?lefilm=(\d+)/i', $searchRes, $matches)) {
|
||||||
|
$filmId = $matches[1];
|
||||||
|
$jaquettesUrl = "https://www.notrecinema.com/communaute/pdf/complete.php3?lefilm=" . $filmId;
|
||||||
|
$jaquettesRes = httpGet($jaquettesUrl, 10, $userAgent);
|
||||||
|
|
||||||
|
if ($jaquettesRes) {
|
||||||
|
if (preg_match('/https?:\/\/[ac]\.notrecinema\.com\/[^"\']+\/jaquette[^"\']*\.jpg/i', $jaquettesRes, $imgMatches)) {
|
||||||
|
$posterUrl = $imgMatches[0];
|
||||||
|
$posterUrl = str_replace('/vign/', '/', $posterUrl);
|
||||||
|
$posterUrl = str_replace('vign_', '', $posterUrl);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'poster' => $posterUrl,
|
||||||
|
'title' => $cleanTitle,
|
||||||
|
'format' => 'Blu-ray'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
||||||
|
|||||||
Reference in New Issue
Block a user