Actualiser api.php

This commit is contained in:
2026-06-26 12:55:16 +02:00
parent e310a0d608
commit 2098ca04be
+45 -51
View File
@@ -133,68 +133,53 @@ 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];
}
// Convertir en URL absolue si nécessaire
if (strpos($posterUrl, 'http') !== 0) {
$posterUrl = 'https://www.notrecinema.com' . $posterUrl;
}
if (!empty($posterUrl)) {
// S'assurer que l'URL est absolue
if (strpos($posterUrl, 'http') !== 0) {
$posterUrl = 'https://www.notrecinema.com' . $posterUrl;
return [
'poster' => $posterUrl,
'title' => $cleanTitle,
'format' => 'Blu-ray'
];
}
return [
'poster' => $posterUrl,
'title' => $cleanTitle,
'format' => 'Blu-ray'
];
}
}
}
}
// É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);
// 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;
}
$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],
'title' => $cleanTitle,
'format' => 'Blu-ray'
];
return [
'poster' => $posterUrl,
'title' => $cleanTitle,
'format' => 'Blu-ray'
];
}
}
}
}
}
@@ -492,7 +477,7 @@ case 'get_config_keys':
else { http_response_code(400); echo json_encode(["success" => false, "error" => "Aucun élément sélectionné."]); }
break;
case 'import_batch':
case 'import_batch':
checkAuth($pdo);
$data = json_decode(file_get_contents("php://input"), true);
$type = $data['type'] ?? 'critique';
@@ -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;
}
?>