From d993260574a5052eac9d059e49293099c1a60042 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sat, 27 Jun 2026 15:28:02 +0200 Subject: [PATCH] Actualiser api.php --- api.php | 130 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 64 insertions(+), 66 deletions(-) diff --git a/api.php b/api.php index abcc534..23323ed 100644 --- a/api.php +++ b/api.php @@ -395,74 +395,72 @@ switch ($action) { break; case 'import_batch': - checkAuth($pdo); - $data = json_decode(file_get_contents("php://input"), true); - $type = $data['type'] ?? 'critique'; - $items = $data['items'] ?? []; + checkAuth($pdo); +$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) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + ON DUPLICATE KEY UPDATE + ean_isbn13 = VALUES(ean_isbn13), + poster = VALUES(poster), + description = VALUES(description), + format = VALUES(format), + length = VALUES(length), + number_of_discs = VALUES(number_of_discs), + aspect_ratio = VALUES(aspect_ratio), + actors = VALUES(actors), + publisher = VALUES(publisher), + director = VALUES(director), + year = VALUES(year)"); - $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) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) - ON DUPLICATE KEY UPDATE - ean_isbn13 = VALUES(ean_isbn13), - poster = VALUES(poster), - description = VALUES(description), - format = VALUES(format), - length = VALUES(length), - number_of_discs = VALUES(number_of_discs), - aspect_ratio = VALUES(aspect_ratio), - actors = VALUES(actors), - publisher = VALUES(publisher), - director = VALUES(director), - year = VALUES(year)"); - - 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) ── - $ean = $item['ean'] ?? ''; - $format = $item['format'] ?? 'Inconnu'; - $publisher = $item['publisher'] ?? ''; - $discs = $item['number_of_discs'] ?? 1; - $aspect = $item['aspect_ratio'] ?? ''; - $length = $item['length'] ?? ''; - $description = $item['description'] ?? ''; - $director = $item['director'] ?? ''; - $actors = $item['actors'] ?? ''; - $poster = 'assets/img/default_physical_media.jpg'; - - // ── SOURCE 2 : API TMDB POUR COMPLÉTER ── - $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']; - } - - if (empty($format)) $format = detectFormat($title, $description); - - $stmtVideo->execute([ - $id, $title, $year, $format, $poster, $ean, $description, - $length, $discs, $aspect, $actors, $publisher, $director - ]); - $imported++; + foreach ($items as $item) { + $title = $item['title'] ?? ''; + if (empty($title)) continue; + $year = $item['year'] ?? ''; + $id = makeStableId('videotheque', $title, $year); + + // ── SOURCE 1 : CSV (Informations physiques uniquement) ── + $ean = $item['ean'] ?? ''; + $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 (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']; } - - } else { // ── IMPORTATION CRITIQUES ── + // É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); + + $stmtVideo->execute([ + $id, $title, $year, $format, $poster, $ean, $description, + $length, $discs, $aspect, $actors, $publisher, $director + ]); + $imported++; + } + } else { // ── IMPORTATION CRITIQUES ── $stmtCritiques = $pdo->prepare("INSERT INTO critiques (id, title, year, director, poster, rating, review, streaming) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE title=VALUES(title), year=VALUES(year), director=VALUES(director),