Actualiser api.php
This commit is contained in:
@@ -124,40 +124,34 @@ function extractYear($dateStr) {
|
|||||||
function fetchBluRayCom($ean, $title = '', $year = '', $pdo = null) {
|
function fetchBluRayCom($ean, $title = '', $year = '', $pdo = null) {
|
||||||
$defaultPoster = 'assets/img/default_physical_media.jpg';
|
$defaultPoster = 'assets/img/default_physical_media.jpg';
|
||||||
|
|
||||||
if (empty($ean)) {
|
if (empty($ean) && empty($title)) {
|
||||||
return ['poster' => $defaultPoster, 'title' => $title, 'format' => 'Blu-ray'];
|
return ['poster' => $defaultPoster, 'title' => $title, 'format' => 'Blu-ray'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nettoyer l'EAN (supprimer les espaces, tirets, etc.)
|
// Nettoyer l'EAN
|
||||||
|
$cleanEan = '';
|
||||||
|
if (!empty($ean)) {
|
||||||
$cleanEan = preg_replace('/[^0-9]/', '', $ean);
|
$cleanEan = preg_replace('/[^0-9]/', '', $ean);
|
||||||
|
|
||||||
if (empty($cleanEan)) {
|
|
||||||
return ['poster' => $defaultPoster, 'title' => $title, 'format' => 'Blu-ray'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recherche sur blu-ray.com par EAN/UPC
|
$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);
|
$searchUrl = "https://www.blu-ray.com/search/?quicksearch=1&searchtype=products&q=" . urlencode($cleanEan);
|
||||||
|
$searchRes = httpGet($searchUrl, 5, $userAgent);
|
||||||
|
|
||||||
$searchRes = httpGet($searchUrl, 5, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36');
|
if ($searchRes && preg_match('/<a href="\/products\/\?id=(\d+)"[^>]*>/i', $searchRes, $matches)) {
|
||||||
|
|
||||||
if (!$searchRes) {
|
|
||||||
return ['poster' => $defaultPoster, 'title' => $title, 'format' => 'Blu-ray'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extraire le lien vers la page du produit
|
|
||||||
if (preg_match('/<a href="\/products\/\?id=(\d+)"[^>]*>/i', $searchRes, $matches)) {
|
|
||||||
$productId = $matches[1];
|
$productId = $matches[1];
|
||||||
$productUrl = "https://www.blu-ray.com/products/?id=" . $productId;
|
$productUrl = "https://www.blu-ray.com/products/?id=" . $productId;
|
||||||
|
|
||||||
// Récupérer la page du produit
|
$productRes = httpGet($productUrl, 5, $userAgent);
|
||||||
$productRes = httpGet($productUrl, 5, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36');
|
|
||||||
|
|
||||||
if ($productRes) {
|
if ($productRes) {
|
||||||
// Extraire l'image principale
|
// Extraire l'image principale
|
||||||
if (preg_match('/<img[^>]*src="([^"]*\/movies\/pictures\/[^"]*)"/i', $productRes, $imgMatches)) {
|
if (preg_match('/<img[^>]*id="home_release_img"[^>]*src="([^"]+)"/i', $productRes, $imgMatches)) {
|
||||||
$posterUrl = $imgMatches[1];
|
$posterUrl = $imgMatches[1];
|
||||||
|
// Convertir en haute résolution
|
||||||
// Convertir en haute résolution si possible
|
|
||||||
$posterUrl = str_replace('/resized/', '/', $posterUrl);
|
$posterUrl = str_replace('/resized/', '/', $posterUrl);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@@ -168,21 +162,22 @@ function fetchBluRayCom($ean, $title = '', $year = '', $pdo = null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Si pas trouvé par EAN, essayer par titre
|
// Fallback : recherche par titre
|
||||||
if (!empty($title)) {
|
if (!empty($title)) {
|
||||||
$cleanTitle = cleanTitle($title);
|
$cleanTitle = cleanTitle($title);
|
||||||
$searchUrl = "https://www.blu-ray.com/search/?quicksearch=1&searchtype=movies&q=" . urlencode($cleanTitle);
|
$searchUrl = "https://www.blu-ray.com/search/?quicksearch=1&searchtype=movies&q=" . urlencode($cleanTitle);
|
||||||
|
|
||||||
$searchRes = httpGet($searchUrl, 5, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36');
|
$searchRes = httpGet($searchUrl, 5, $userAgent);
|
||||||
|
|
||||||
if ($searchRes && preg_match('/<a href="\/movies\/\?id=(\d+)"[^>]*>/i', $searchRes, $matches)) {
|
if ($searchRes && preg_match('/<a href="\/movies\/\?id=(\d+)"[^>]*>/i', $searchRes, $matches)) {
|
||||||
$movieId = $matches[1];
|
$movieId = $matches[1];
|
||||||
$movieUrl = "https://www.blu-ray.com/movies/?id=" . $movieId;
|
$movieUrl = "https://www.blu-ray.com/movies/?id=" . $movieId;
|
||||||
|
|
||||||
$movieRes = httpGet($movieUrl, 5, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36');
|
$movieRes = httpGet($movieUrl, 5, $userAgent);
|
||||||
|
|
||||||
if ($movieRes && preg_match('/<img[^>]*src="([^"]*\/movies\/pictures\/[^"]*)"/i', $movieRes, $imgMatches)) {
|
if ($movieRes && preg_match('/<img[^>]*id="home_release_img"[^>]*src="([^"]+)"/i', $movieRes, $imgMatches)) {
|
||||||
$posterUrl = $imgMatches[1];
|
$posterUrl = $imgMatches[1];
|
||||||
$posterUrl = str_replace('/resized/', '/', $posterUrl);
|
$posterUrl = str_replace('/resized/', '/', $posterUrl);
|
||||||
|
|
||||||
@@ -198,6 +193,8 @@ function fetchBluRayCom($ean, $title = '', $year = '', $pdo = null) {
|
|||||||
return ['poster' => $defaultPoster, 'title' => $title, 'format' => 'Blu-ray'];
|
return ['poster' => $defaultPoster, 'title' => $title, 'format' => 'Blu-ray'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── ROUTEUR PRINCIPAL ──
|
||||||
|
|
||||||
// Fonction pour vérifier si une URL existe
|
// Fonction pour vérifier si une URL existe
|
||||||
function urlExists($url, $timeout = 3) {
|
function urlExists($url, $timeout = 3) {
|
||||||
if (!function_exists('curl_init')) {
|
if (!function_exists('curl_init')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user