diff --git a/api.php b/api.php
index 9a78c85..ecc54dc 100644
--- a/api.php
+++ b/api.php
@@ -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('/
]*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('/
Format<\/b>[:\s]*<\/td>\s*]*>([^<]+)/i', $productRes, $m)) {
- $formatRaw = trim($m[1]);
+ if (preg_match('/Format<\/b>.*? | ]*>(.*?)<\/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('/(?:Discs?|Disques?)<\/b>[:\s]*<\/td>\s* | ]*>(\d+)/i', $productRes, $m)) {
- $result['number_of_discs'] = (int)$m[1];
+ if (preg_match('/(?:Discs?|Disques?)<\/b>.*? | ]*>(.*?)<\/td>/is', $detailsHtml, $m)) {
+ if (preg_match('/(\d+)/', $m[1], $num)) {
+ $result['number_of_discs'] = (int)$num[1];
+ }
}
// Aspect ratio
- if (preg_match('/Aspect\s*ratio<\/b>[:\s]*<\/td>\s* | ]*>([^<]+)/i', $productRes, $m)) {
- $result['aspect_ratio'] = trim($m[1]);
+ if (preg_match('/Aspect\s*ratio<\/b>.*? | ]*>(.*?)<\/td>/is', $detailsHtml, $m)) {
+ $result['aspect_ratio'] = trim(strip_tags($m[1]));
}
// Durée (runtime)
- if (preg_match('/(?:Runtime|Durée|Length)<\/b>[:\s]*<\/td>\s* | ]*>(\d+)/i', $productRes, $m)) {
- $result['length'] = trim($m[1]) . ' min';
+ if (preg_match('/(?:Runtime|Durée|Length)<\/b>.*? | ]*>(.*?)<\/td>/is', $detailsHtml, $m)) {
+ if (preg_match('/(\d+)/', $m[1], $num)) {
+ $result['length'] = $num[1] . ' min';
+ }
}
- // Studio / Éditeur
- if (preg_match('/(?:Studio|Label|Distributor)<\/b>[:\s]*<\/td>\s* | ]*>([^<]+)/i', $productRes, $m)) {
- $result['publisher'] = trim($m[1]);
+ // Studio / Éditeur (Corrigé, ne crashe plus sur la balise )
+ if (preg_match('/(?:Studio|Label|Distributor)<\/b>.*? | ]*>(.*?)<\/td>/is', $detailsHtml, $m)) {
+ $result['publisher'] = trim(strip_tags($m[1]));
}
// Année de sortie
- if (preg_match('/(?:Release\s*Date|Country\s*&\s*Date)<\/b>[:\s]*<\/td>\s* | ]*>[^<]*?(\d{4})/i', $productRes, $m)) {
- $result['year'] = $m[1];
+ if (preg_match('/(?:Release\s*Date|Country\s*&\s*Date)<\/b>.*? | ]*>(.*?)<\/td>/is', $detailsHtml, $m)) {
+ if (preg_match('/(\d{4})/', $m[1], $num)) {
+ $result['year'] = $num[1];
+ }
}
// Synopsis
@@ -566,7 +571,7 @@ switch ($action) {
director = VALUES(director),
year = VALUES(year)");
- foreach ($items as $item) {
+ foreach ($items as $item) {
$title = $item['title'] ?? '';
if (empty($title)) continue;
@@ -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')
|