Actualiser api.php
This commit is contained in:
@@ -131,55 +131,94 @@ function fetchNotreCinema($title, $year = '', $ean = '', $pdo = null) {
|
||||
$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';
|
||||
|
||||
// ÉTAPE 1 : Recherche sur notrecinema.com
|
||||
$searchUrl = "https://www.notrecinema.com/communaute/stubs.php?stub=" . urlencode($cleanTitle);
|
||||
// ÉTAPE 1 : Recherche via l'URL de recherche de notrecinema.com
|
||||
$searchUrl = "https://www.notrecinema.com/communaute/recherche.php3?recherche=" . urlencode($cleanTitle);
|
||||
if (!empty($year)) {
|
||||
$searchUrl .= "&annee=" . $year;
|
||||
}
|
||||
|
||||
$searchRes = httpGet($searchUrl, 10, $userAgent);
|
||||
|
||||
if ($searchRes) {
|
||||
// Extraire l'ID du film et le slug
|
||||
if (preg_match('/v1_detail_film\.php3\?lefilm=(\d+)/', $searchRes, $matches)) {
|
||||
// Extraire l'ID du film depuis les liens vers les fiches
|
||||
// Format : /communaute/v1_detail_film.php3?lefilm=123
|
||||
if (preg_match('/v1_detail_film\.php3\?lefilm=(\d+)/i', $searchRes, $matches)) {
|
||||
$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;
|
||||
$jaquettesRes = httpGet($jaquettesUrl, 10, $userAgent);
|
||||
|
||||
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 (!empty($imgMatches[1])) {
|
||||
// Prendre la première jaquette disponible
|
||||
$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
|
||||
if (preg_match_all('/<noscript>.*?<img[^>]*src=[\'"]([^\'"]+\.jpg)[\'"][^>]*>/is', $jaquettesRes, $noscriptMatches)) {
|
||||
if (!empty($noscriptMatches[1])) {
|
||||
$posterUrl = $noscriptMatches[1][0];
|
||||
if (strpos($posterUrl, 'http') !== 0) {
|
||||
$posterUrl = 'https://www.notrecinema.com' . $posterUrl;
|
||||
// Méthode 2 : Fallback sur les images dans <noscript>
|
||||
if (empty($posterUrl)) {
|
||||
if (preg_match_all('/<noscript>.*?<img[^>]*src=[\'"]([^\'"]+\.jpg)[\'"][^>]*>/is', $jaquettesRes, $noscriptMatches)) {
|
||||
if (!empty($noscriptMatches[1])) {
|
||||
$posterUrl = $noscriptMatches[1][0];
|
||||
}
|
||||
|
||||
return [
|
||||
'poster' => $posterUrl,
|
||||
'title' => $cleanTitle,
|
||||
'format' => 'Blu-ray'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
$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 [
|
||||
'poster' => $posterUrl,
|
||||
'title' => $cleanTitle,
|
||||
'format' => 'Blu-ray'
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// É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'
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user