Actualiser api.php
This commit is contained in:
@@ -133,68 +133,53 @@ function fetchNotreCinema($title, $year = '', $ean = '', $pdo = null) {
|
|||||||
|
|
||||||
// ÉTAPE 1 : Recherche sur notrecinema.com
|
// ÉTAPE 1 : Recherche sur notrecinema.com
|
||||||
$searchUrl = "https://www.notrecinema.com/communaute/stubs.php?stub=" . urlencode($cleanTitle);
|
$searchUrl = "https://www.notrecinema.com/communaute/stubs.php?stub=" . urlencode($cleanTitle);
|
||||||
if (!empty($year)) {
|
|
||||||
$searchUrl .= "&annee=" . $year;
|
|
||||||
}
|
|
||||||
|
|
||||||
$searchRes = httpGet($searchUrl, 10, $userAgent);
|
$searchRes = httpGet($searchUrl, 10, $userAgent);
|
||||||
|
|
||||||
if ($searchRes) {
|
if ($searchRes) {
|
||||||
// Extraire le lien vers la page du film
|
// Extraire l'ID du film et le slug
|
||||||
if (preg_match('/<a href="\/communaute\/stubs\.php\?stub=([^"]+)"[^>]*>/i', $searchRes, $matches)) {
|
if (preg_match('/v1_detail_film\.php3\?lefilm=(\d+)/', $searchRes, $matches)) {
|
||||||
$filmSlug = $matches[1];
|
$filmId = $matches[1];
|
||||||
$filmUrl = "https://www.notrecinema.com/communaute/stubs.php?stub=" . $filmSlug;
|
|
||||||
|
|
||||||
$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) {
|
if ($jaquettesRes) {
|
||||||
// Extraire l'image d'affiche
|
// Extraire les images de jaquettes (data-src des img.poster)
|
||||||
$posterUrl = null;
|
if (preg_match_all('/<img[^>]*class=[\'"]poster[\'"][^>]*data-src=[\'"]([^\'"]+)[\'"][^>]*>/i', $jaquettesRes, $imgMatches)) {
|
||||||
|
if (!empty($imgMatches[1])) {
|
||||||
// Chercher l'image principale du film
|
// Prendre la première jaquette disponible
|
||||||
if (preg_match('/<img[^>]*class="[^"]*affiche[^"]*"[^>]*src="([^"]+)"/i', $filmRes, $imgMatches)) {
|
$posterUrl = $imgMatches[1][0];
|
||||||
$posterUrl = $imgMatches[1];
|
|
||||||
} elseif (preg_match('/<div[^>]*class="[^"]*film_affiche[^"]*"[^>]*>.*?<img[^>]*src="([^"]+)"/is', $filmRes, $imgMatches)) {
|
// Convertir en URL absolue si nécessaire
|
||||||
$posterUrl = $imgMatches[1];
|
if (strpos($posterUrl, 'http') !== 0) {
|
||||||
} elseif (preg_match('/<img[^>]*src="(https:\/\/www\.notrecinema\.com\/images\/films\/[^"]+)"/i', $filmRes, $imgMatches)) {
|
$posterUrl = 'https://www.notrecinema.com' . $posterUrl;
|
||||||
$posterUrl = $imgMatches[1];
|
}
|
||||||
}
|
|
||||||
|
return [
|
||||||
if (!empty($posterUrl)) {
|
'poster' => $posterUrl,
|
||||||
// S'assurer que l'URL est absolue
|
'title' => $cleanTitle,
|
||||||
if (strpos($posterUrl, 'http') !== 0) {
|
'format' => 'Blu-ray'
|
||||||
$posterUrl = 'https://www.notrecinema.com' . $posterUrl;
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
|
||||||
|
|
||||||
$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'
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -492,7 +477,7 @@ case 'get_config_keys':
|
|||||||
else { http_response_code(400); echo json_encode(["success" => false, "error" => "Aucun élément sélectionné."]); }
|
else { http_response_code(400); echo json_encode(["success" => false, "error" => "Aucun élément sélectionné."]); }
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'import_batch':
|
case 'import_batch':
|
||||||
checkAuth($pdo);
|
checkAuth($pdo);
|
||||||
$data = json_decode(file_get_contents("php://input"), true);
|
$data = json_decode(file_get_contents("php://input"), true);
|
||||||
$type = $data['type'] ?? 'critique';
|
$type = $data['type'] ?? 'critique';
|
||||||
@@ -573,5 +558,14 @@ case 'get_config_keys':
|
|||||||
$pdo->commit();
|
$pdo->commit();
|
||||||
echo json_encode(["success" => true, "imported" => $imported]);
|
echo json_encode(["success" => true, "imported" => $imported]);
|
||||||
break;
|
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