Actualiser api.php

This commit is contained in:
2026-06-27 11:15:30 +02:00
parent dd2d74f644
commit e9abd4034f
+31 -16
View File
@@ -221,8 +221,7 @@ function fetchBluRayPhysicalInfo($ean, $title = '', $pdo = null) {
}
// ── ÉTAPE 4 : Extraire les informations techniques ──
// Format (Blu-ray, 4K Ultra HD, DVD)
// ── ÉTAPE 4 : Extraire les informations techniques ──
if (preg_match('/<div[^>]*class="[^"]*productdetails[^"]*"[^>]*>.*?<\/div>/is', $productRes, $detailsBlock)) {
$detailsHtml = $detailsBlock[0];
} else {
@@ -230,8 +229,8 @@ function fetchBluRayPhysicalInfo($ean, $title = '', $pdo = null) {
}
// Détection du format
if (preg_match('/<b>Format<\/b>[:\s]*<\/td>\s*<td[^>]*>([^<]+)/i', $productRes, $m)) {
$formatRaw = trim($m[1]);
if (preg_match('/<b>Format<\/b>.*?<td[^>]*>(.*?)<\/td>/is', $detailsHtml, $m)) {
$formatRaw = trim(strip_tags($m[1]));
if (stripos($formatRaw, '4K') !== false || stripos($formatRaw, 'UHD') !== false) {
$result['format'] = '4K Ultra HD';
} elseif (stripos($formatRaw, 'DVD') !== false) {
@@ -242,28 +241,34 @@ function fetchBluRayPhysicalInfo($ean, $title = '', $pdo = null) {
}
// Nombre de disques
if (preg_match('/<b>(?:Discs?|Disques?)<\/b>[:\s]*<\/td>\s*<td[^>]*>(\d+)/i', $productRes, $m)) {
$result['number_of_discs'] = (int)$m[1];
if (preg_match('/<b>(?:Discs?|Disques?)<\/b>.*?<td[^>]*>(.*?)<\/td>/is', $detailsHtml, $m)) {
if (preg_match('/(\d+)/', $m[1], $num)) {
$result['number_of_discs'] = (int)$num[1];
}
}
// Aspect ratio
if (preg_match('/<b>Aspect\s*ratio<\/b>[:\s]*<\/td>\s*<td[^>]*>([^<]+)/i', $productRes, $m)) {
$result['aspect_ratio'] = trim($m[1]);
if (preg_match('/<b>Aspect\s*ratio<\/b>.*?<td[^>]*>(.*?)<\/td>/is', $detailsHtml, $m)) {
$result['aspect_ratio'] = trim(strip_tags($m[1]));
}
// Durée (runtime)
if (preg_match('/<b>(?:Runtime|Durée|Length)<\/b>[:\s]*<\/td>\s*<td[^>]*>(\d+)/i', $productRes, $m)) {
$result['length'] = trim($m[1]) . ' min';
if (preg_match('/<b>(?:Runtime|Durée|Length)<\/b>.*?<td[^>]*>(.*?)<\/td>/is', $detailsHtml, $m)) {
if (preg_match('/(\d+)/', $m[1], $num)) {
$result['length'] = $num[1] . ' min';
}
}
// Studio / Éditeur
if (preg_match('/<b>(?:Studio|Label|Distributor)<\/b>[:\s]*<\/td>\s*<td[^>]*>([^<]+)/i', $productRes, $m)) {
$result['publisher'] = trim($m[1]);
// Studio / Éditeur (Corrigé, ne crashe plus sur la balise <a>)
if (preg_match('/<b>(?:Studio|Label|Distributor)<\/b>.*?<td[^>]*>(.*?)<\/td>/is', $detailsHtml, $m)) {
$result['publisher'] = trim(strip_tags($m[1]));
}
// Année de sortie
if (preg_match('/<b>(?:Release\s*Date|Country\s*&\s*Date)<\/b>[:\s]*<\/td>\s*<td[^>]*>[^<]*?(\d{4})/i', $productRes, $m)) {
$result['year'] = $m[1];
if (preg_match('/<b>(?:Release\s*Date|Country\s*&\s*Date)<\/b>.*?<td[^>]*>(.*?)<\/td>/is', $detailsHtml, $m)) {
if (preg_match('/(\d{4})/', $m[1], $num)) {
$result['year'] = $num[1];
}
}
// Synopsis
@@ -579,6 +584,7 @@ switch ($action) {
$actorsCsv = $item['actors'] ?? '';
$publisherCsv = $item['publisher'] ?? '';
$directorCsv = $item['director'] ?? '';
$formatCsv = $item['format'] ?? ''; // 👈 LIGNE À AJOUTER
$id = makeStableId('videotheque', $title, $year);
@@ -588,7 +594,16 @@ switch ($action) {
// ── SOURCE 2 : TMDB (affiche + synopsis + métadonnées) ──
$tmdbData = fetchTmdbPosterAndSynopsis($title, $year, $pdo);
// ── FUSION DES DONNÉES (priorité : CSV > BluRay.com > TMDB) ──
// ── FUSION DES DONNÉES ──
$poster = ($tmdbData['poster'] !== 'assets/img/default_physical_media.jpg')
? $tmdbData['poster']
: $bluRayData['poster'];
// Priorité au CSV, puis BluRay.com, puis détection du titre
$format = !empty($formatCsv)
? $formatCsv
: (!empty($bluRayData['format']) ? $bluRayData['format'] : detectFormat($title, $descCsv));
// Affiche : TMDB en priorité (meilleure qualité)
$poster = ($tmdbData['poster'] !== 'assets/img/default_physical_media.jpg')