Actualiser api.php

This commit is contained in:
2026-06-26 12:05:36 +02:00
parent 88ef24780a
commit b20ded263e
+52 -43
View File
@@ -120,43 +120,55 @@ function extractYear($dateStr) {
return '';
}
// ── FONCTION POUR RÉCUPÉRER LES IMAGES DEPUIS BLU-RAY.COM ──
function fetchBluRayCom($ean, $title = '', $year = '', $pdo = null) {
// ── FONCTION POUR RÉCUPÉRER LES IMAGES DEPUIS NOTRECINEMA.COM ──
function fetchNotreCinema($title, $year = '', $ean = '', $pdo = null) {
$defaultPoster = 'assets/img/default_physical_media.jpg';
if (empty($ean) && empty($title)) {
return ['poster' => $defaultPoster, 'title' => $title, 'format' => 'Blu-ray'];
}
// Nettoyer l'EAN
$cleanEan = '';
if (!empty($ean)) {
$cleanEan = preg_replace('/[^0-9]/', '', $ean);
if (empty($title)) {
return ['poster' => $defaultPoster, 'title' => '', 'format' => 'Blu-ray'];
}
$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';
// Recherche par EAN/UPC d'abord
if (!empty($cleanEan)) {
$searchUrl = "https://www.blu-ray.com/search/?quicksearch=1&searchtype=products&q=" . urlencode($cleanEan);
$searchRes = httpGet($searchUrl, 5, $userAgent);
// ÉTAPE 1 : Recherche sur notrecinema.com
$searchUrl = "https://www.notrecinema.com/communaute/stubs.php?stub=" . urlencode($cleanTitle);
if (!empty($year)) {
$searchUrl .= "&annee=" . $year;
}
if ($searchRes && preg_match('/<a href="\/products\/\?id=(\d+)"[^>]*>/i', $searchRes, $matches)) {
$productId = $matches[1];
$productUrl = "https://www.blu-ray.com/products/?id=" . $productId;
$searchRes = httpGet($searchUrl, 10, $userAgent);
$productRes = httpGet($productUrl, 5, $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;
if ($productRes) {
// Extraire l'image principale
if (preg_match('/<img[^>]*id="home_release_img"[^>]*src="([^"]+)"/i', $productRes, $imgMatches)) {
$filmRes = httpGet($filmUrl, 10, $userAgent);
if ($filmRes) {
// Extraire l'image d'affiche
$posterUrl = null;
// Chercher l'image principale du film
if (preg_match('/<img[^>]*class="[^"]*affiche[^"]*"[^>]*src="([^"]+)"/i', $filmRes, $imgMatches)) {
$posterUrl = $imgMatches[1];
// Convertir en haute résolution
$posterUrl = str_replace('/resized/', '/', $posterUrl);
} 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
if (strpos($posterUrl, 'http') !== 0) {
$posterUrl = 'https://www.notrecinema.com' . $posterUrl;
}
return [
'poster' => $posterUrl,
'title' => $title,
'title' => $cleanTitle,
'format' => 'Blu-ray'
];
}
@@ -164,33 +176,30 @@ function fetchBluRayCom($ean, $title = '', $year = '', $pdo = null) {
}
}
// Fallback : recherche par titre
if (!empty($title)) {
$cleanTitle = cleanTitle($title);
$searchUrl = "https://www.blu-ray.com/search/?quicksearch=1&searchtype=movies&q=" . urlencode($cleanTitle);
// É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, 5, $userAgent);
$searchRes = httpGet($searchUrl, 10, $userAgent);
if ($searchRes && preg_match('/<a href="\/movies\/\?id=(\d+)"[^>]*>/i', $searchRes, $matches)) {
$movieId = $matches[1];
$movieUrl = "https://www.blu-ray.com/movies/?id=" . $movieId;
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;
$movieRes = httpGet($movieUrl, 5, $userAgent);
if ($movieRes && preg_match('/<img[^>]*id="home_release_img"[^>]*src="([^"]+)"/i', $movieRes, $imgMatches)) {
$posterUrl = $imgMatches[1];
$posterUrl = str_replace('/resized/', '/', $posterUrl);
$filmRes = httpGet($filmUrl, 10, $userAgent);
if ($filmRes && preg_match('/<img[^>]*src="(https:\/\/www\.notrecinema\.com\/images\/films\/[^"]+)"/i', $filmRes, $imgMatches)) {
return [
'poster' => $posterUrl,
'title' => $title,
'poster' => $imgMatches[1],
'title' => $cleanTitle,
'format' => 'Blu-ray'
];
}
}
}
return ['poster' => $defaultPoster, 'title' => $title, 'format' => 'Blu-ray'];
return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
}
// ── ROUTEUR PRINCIPAL ──
@@ -522,9 +531,9 @@ case 'get_config_keys':
$id = makeStableId('videotheque', $title, $year);
// Utiliser blu-ray.com pour récupérer l'image
$bluRayData = fetchBluRayCom($ean, $title, $year, $pdo);
$poster = $bluRayData['poster'];
// Utiliser notrecinema.com pour récupérer l'image
$notreCinemaData = fetchNotreCinema($title, $year, $ean, $pdo);
$poster = $notreCinemaData['poster'];
// Déterminer le format
$format = 'Blu-ray';