Actualiser api.php

This commit is contained in:
2026-06-27 15:28:02 +02:00
parent 69c276035f
commit d993260574
+11 -13
View File
@@ -399,10 +399,8 @@ case 'import_batch':
$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';
$items = $data['items'] ?? []; $items = $data['items'] ?? [];
$pdo->beginTransaction(); $pdo->beginTransaction();
$imported = 0; $imported = 0;
try { try {
if ($type === 'videotheque') { if ($type === 'videotheque') {
$stmtVideo = $pdo->prepare("INSERT INTO videotheque (id, title, year, format, poster, ean_isbn13, description, length, number_of_discs, aspect_ratio, actors, publisher, director) $stmtVideo = $pdo->prepare("INSERT INTO videotheque (id, title, year, format, poster, ean_isbn13, description, length, number_of_discs, aspect_ratio, actors, publisher, director)
@@ -423,34 +421,35 @@ case 'import_batch':
foreach ($items as $item) { foreach ($items as $item) {
$title = $item['title'] ?? ''; $title = $item['title'] ?? '';
if (empty($title)) continue; if (empty($title)) continue;
$year = $item['year'] ?? ''; $year = $item['year'] ?? '';
$id = makeStableId('videotheque', $title, $year); $id = makeStableId('videotheque', $title, $year);
// ── SOURCE 1 : CSV STRICT (Sans Scraping) ── // ── SOURCE 1 : CSV (Informations physiques uniquement) ──
$ean = $item['ean'] ?? ''; $ean = $item['ean'] ?? '';
$format = $item['format'] ?? 'Inconnu'; $format = $item['format'] ?? '';
$publisher = $item['publisher'] ?? ''; $publisher = $item['publisher'] ?? '';
$discs = $item['number_of_discs'] ?? 1; $discs = $item['number_of_discs'] ?? 1;
$aspect = $item['aspect_ratio'] ?? ''; $aspect = $item['aspect_ratio'] ?? '';
$length = $item['length'] ?? ''; $length = $item['length'] ?? '';
// On initialise avec le CSV, mais l'API TMDB va écraser ces valeurs si elle trouve mieux
$description = $item['description'] ?? ''; $description = $item['description'] ?? '';
$director = $item['director'] ?? ''; $director = $item['director'] ?? '';
$actors = $item['actors'] ?? ''; $actors = $item['actors'] ?? '';
$poster = 'assets/img/default_physical_media.jpg'; $poster = 'assets/img/default_physical_media.jpg';
// ── SOURCE 2 : API TMDB POUR COMPLÉTER ── // ── SOURCE 2 : API TMDB (Priorité absolue pour les métadonnées) ──
$tmdbData = fetchTmdbPosterAndSynopsis($title, $year, $pdo); $tmdbData = fetchTmdbPosterAndSynopsis($title, $year, $pdo);
if ($tmdbData) { if ($tmdbData) {
if ($tmdbData['poster'] !== 'assets/img/default_physical_media.jpg') { if ($tmdbData['poster'] !== 'assets/img/default_physical_media.jpg') {
$poster = $tmdbData['poster']; $poster = $tmdbData['poster'];
} }
if (empty($description)) $description = $tmdbData['description'] ?? ''; // Écrasement des données CSV par l'API TMDB si disponibles
if (empty($director)) $director = $tmdbData['director'] ?? ''; if (!empty($tmdbData['description'])) $description = $tmdbData['description'];
if (empty($actors)) $actors = $tmdbData['actors'] ?? ''; if (!empty($tmdbData['director'])) $director = $tmdbData['director'];
if (empty($length) && !empty($tmdbData['length'])) $length = $tmdbData['length']; if (!empty($tmdbData['actors'])) $actors = $tmdbData['actors'];
if (empty($year) && !empty($tmdbData['year'])) $year = $tmdbData['year']; if (!empty($tmdbData['length'])) $length = $tmdbData['length'];
if (!empty($tmdbData['year'])) $year = $tmdbData['year'];
} }
if (empty($format)) $format = detectFormat($title, $description); if (empty($format)) $format = detectFormat($title, $description);
@@ -461,7 +460,6 @@ case 'import_batch':
]); ]);
$imported++; $imported++;
} }
} else { // ── IMPORTATION CRITIQUES ── } else { // ── IMPORTATION CRITIQUES ──
$stmtCritiques = $pdo->prepare("INSERT INTO critiques (id, title, year, director, poster, rating, review, streaming) $stmtCritiques = $pdo->prepare("INSERT INTO critiques (id, title, year, director, poster, rating, review, streaming)
VALUES (?, ?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?, ?)