Actualiser api.php
This commit is contained in:
@@ -399,10 +399,8 @@ case 'import_batch':
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
$type = $data['type'] ?? 'critique';
|
||||
$items = $data['items'] ?? [];
|
||||
|
||||
$pdo->beginTransaction();
|
||||
$imported = 0;
|
||||
|
||||
try {
|
||||
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)
|
||||
@@ -423,34 +421,35 @@ case 'import_batch':
|
||||
foreach ($items as $item) {
|
||||
$title = $item['title'] ?? '';
|
||||
if (empty($title)) continue;
|
||||
|
||||
$year = $item['year'] ?? '';
|
||||
$id = makeStableId('videotheque', $title, $year);
|
||||
|
||||
// ── SOURCE 1 : CSV STRICT (Sans Scraping) ──
|
||||
// ── SOURCE 1 : CSV (Informations physiques uniquement) ──
|
||||
$ean = $item['ean'] ?? '';
|
||||
$format = $item['format'] ?? 'Inconnu';
|
||||
$format = $item['format'] ?? '';
|
||||
$publisher = $item['publisher'] ?? '';
|
||||
$discs = $item['number_of_discs'] ?? 1;
|
||||
$aspect = $item['aspect_ratio'] ?? '';
|
||||
$length = $item['length'] ?? '';
|
||||
|
||||
// On initialise avec le CSV, mais l'API TMDB va écraser ces valeurs si elle trouve mieux
|
||||
$description = $item['description'] ?? '';
|
||||
$director = $item['director'] ?? '';
|
||||
$actors = $item['actors'] ?? '';
|
||||
$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);
|
||||
|
||||
if ($tmdbData) {
|
||||
if ($tmdbData['poster'] !== 'assets/img/default_physical_media.jpg') {
|
||||
$poster = $tmdbData['poster'];
|
||||
}
|
||||
if (empty($description)) $description = $tmdbData['description'] ?? '';
|
||||
if (empty($director)) $director = $tmdbData['director'] ?? '';
|
||||
if (empty($actors)) $actors = $tmdbData['actors'] ?? '';
|
||||
if (empty($length) && !empty($tmdbData['length'])) $length = $tmdbData['length'];
|
||||
if (empty($year) && !empty($tmdbData['year'])) $year = $tmdbData['year'];
|
||||
// Écrasement des données CSV par l'API TMDB si disponibles
|
||||
if (!empty($tmdbData['description'])) $description = $tmdbData['description'];
|
||||
if (!empty($tmdbData['director'])) $director = $tmdbData['director'];
|
||||
if (!empty($tmdbData['actors'])) $actors = $tmdbData['actors'];
|
||||
if (!empty($tmdbData['length'])) $length = $tmdbData['length'];
|
||||
if (!empty($tmdbData['year'])) $year = $tmdbData['year'];
|
||||
}
|
||||
|
||||
if (empty($format)) $format = detectFormat($title, $description);
|
||||
@@ -461,7 +460,6 @@ case 'import_batch':
|
||||
]);
|
||||
$imported++;
|
||||
}
|
||||
|
||||
} else { // ── IMPORTATION CRITIQUES ──
|
||||
$stmtCritiques = $pdo->prepare("INSERT INTO critiques (id, title, year, director, poster, rating, review, streaming)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
|
||||
Reference in New Issue
Block a user