Actualiser api.php
This commit is contained in:
@@ -133,35 +133,26 @@ function fetchNotreCinema($title, $year = '', $ean = '', $pdo = null) {
|
||||
|
||||
// ÉTAPE 1 : Recherche sur notrecinema.com
|
||||
$searchUrl = "https://www.notrecinema.com/communaute/stubs.php?stub=" . urlencode($cleanTitle);
|
||||
if (!empty($year)) {
|
||||
$searchUrl .= "&annee=" . $year;
|
||||
}
|
||||
|
||||
$searchRes = httpGet($searchUrl, 10, $userAgent);
|
||||
|
||||
if ($searchRes) {
|
||||
// Extraire le lien vers la page du film
|
||||
if (preg_match('/<a href="\/communaute\/stubs\.php\?stub=([^"]+)"[^>]*>/i', $searchRes, $matches)) {
|
||||
$filmSlug = $matches[1];
|
||||
$filmUrl = "https://www.notrecinema.com/communaute/stubs.php?stub=" . $filmSlug;
|
||||
// Extraire l'ID du film et le slug
|
||||
if (preg_match('/v1_detail_film\.php3\?lefilm=(\d+)/', $searchRes, $matches)) {
|
||||
$filmId = $matches[1];
|
||||
|
||||
$filmRes = httpGet($filmUrl, 10, $userAgent);
|
||||
// Récupérer la page des jaquettes
|
||||
$jaquettesUrl = "https://www.notrecinema.com/communaute/pdf/complete.php3?lefilm=" . $filmId;
|
||||
$jaquettesRes = httpGet($jaquettesUrl, 10, $userAgent);
|
||||
|
||||
if ($filmRes) {
|
||||
// Extraire l'image d'affiche
|
||||
$posterUrl = null;
|
||||
if ($jaquettesRes) {
|
||||
// Extraire les images de jaquettes (data-src des img.poster)
|
||||
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];
|
||||
|
||||
// Chercher l'image principale du film
|
||||
if (preg_match('/<img[^>]*class="[^"]*affiche[^"]*"[^>]*src="([^"]+)"/i', $filmRes, $imgMatches)) {
|
||||
$posterUrl = $imgMatches[1];
|
||||
} elseif (preg_match('/<div[^>]*class="[^"]*film_affiche[^"]*"[^>]*>.*?<img[^>]*src="([^"]+)"/is', $filmRes, $imgMatches)) {
|
||||
$posterUrl = $imgMatches[1];
|
||||
} elseif (preg_match('/<img[^>]*src="(https:\/\/www\.notrecinema\.com\/images\/films\/[^"]+)"/i', $filmRes, $imgMatches)) {
|
||||
$posterUrl = $imgMatches[1];
|
||||
}
|
||||
|
||||
if (!empty($posterUrl)) {
|
||||
// S'assurer que l'URL est absolue
|
||||
// Convertir en URL absolue si nécessaire
|
||||
if (strpos($posterUrl, 'http') !== 0) {
|
||||
$posterUrl = 'https://www.notrecinema.com' . $posterUrl;
|
||||
}
|
||||
@@ -173,31 +164,25 @@ function fetchNotreCinema($title, $year = '', $ean = '', $pdo = null) {
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// ÉTAPE 2 : Recherche alternative par EAN si disponible
|
||||
if (!empty($ean)) {
|
||||
$cleanEan = preg_replace('/[^0-9]/', '', $ean);
|
||||
$searchUrl = "https://www.notrecinema.com/communaute/recherche.php?recherche=" . urlencode($cleanEan);
|
||||
|
||||
$searchRes = httpGet($searchUrl, 10, $userAgent);
|
||||
|
||||
if ($searchRes && preg_match('/<a href="\/communaute\/stubs\.php\?stub=([^"]+)"[^>]*>/i', $searchRes, $matches)) {
|
||||
$filmSlug = $matches[1];
|
||||
$filmUrl = "https://www.notrecinema.com/communaute/stubs.php?stub=" . $filmSlug;
|
||||
|
||||
$filmRes = httpGet($filmUrl, 10, $userAgent);
|
||||
|
||||
if ($filmRes && preg_match('/<img[^>]*src="(https:\/\/www\.notrecinema\.com\/images\/films\/[^"]+)"/i', $filmRes, $imgMatches)) {
|
||||
return [
|
||||
'poster' => $imgMatches[1],
|
||||
'poster' => $posterUrl,
|
||||
'title' => $cleanTitle,
|
||||
'format' => 'Blu-ray'
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
||||
}
|
||||
@@ -573,5 +558,14 @@ case 'get_config_keys':
|
||||
$pdo->commit();
|
||||
echo json_encode(["success" => true, "imported" => $imported]);
|
||||
break;
|
||||
|
||||
case 'debug_notrecinema':
|
||||
$title = $_GET['title'] ?? '';
|
||||
$year = $_GET['year'] ?? '';
|
||||
|
||||
$result = fetchNotreCinema($title, $year, '', $pdo);
|
||||
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
break;
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user