Actualiser api.php
This commit is contained in:
@@ -420,7 +420,6 @@ switch ($action) {
|
||||
else { http_response_code(400); echo json_encode(["success" => false, "error" => "Aucun élément sélectionné."]); }
|
||||
break;
|
||||
|
||||
// ── IMPORT PAR LOTS CSV (DVDfr + TMDB, SANS CACHE) ──
|
||||
case 'import_batch':
|
||||
checkAuth($pdo);
|
||||
set_time_limit(0);
|
||||
@@ -430,9 +429,8 @@ switch ($action) {
|
||||
$imported = 0;
|
||||
$debugLog = [];
|
||||
|
||||
$pdo->beginTransaction(); // 🔥 UNE SEULE transaction
|
||||
try {
|
||||
$pdo->beginTransaction(); // 🔥 UNE SEULE TRANSACTION
|
||||
|
||||
foreach ($items as $rowData) {
|
||||
$title = $rowData['title'] ?? $rowData['Name'] ?? $rowData['Title'] ?? 'Sans titre';
|
||||
$publishDate = $rowData['publish_date'] ?? $rowData['Year'] ?? $rowData['year'] ?? $rowData['Date'] ?? '';
|
||||
@@ -473,20 +471,20 @@ switch ($action) {
|
||||
$poster = $rowData['poster'] ?? '';
|
||||
$director = '';
|
||||
|
||||
// 🔥 1. DVDFr (priorité pour les métadonnées physiques)
|
||||
// 1. DVDFr (priorité pour les supports physiques FR)
|
||||
if (!empty($ean)) {
|
||||
$dvdfrData = fetchDVDFr($ean, $pdo);
|
||||
if (!empty($dvdfrData)) {
|
||||
if (!empty($dvdfrData['poster'])) $poster = $dvdfrData['poster'];
|
||||
if (!empty($dvdfrData['publisher'])) $publisher = $dvdfrData['publisher'];
|
||||
if (!empty($dvdfrData['format'])) $format = $dvdfrData['format'];
|
||||
if (!empty($dvdfrData['length'])) $length = $dvdfrData['length'];
|
||||
if (!empty($dvdfrData['aspect'])) $aspect = $dvdfrData['aspect'];
|
||||
if (!empty($dvdfrData['discs'])) $discs = (int)$dvdfrData['discs'];
|
||||
if (!empty($dvdfrData['length']) && empty($length)) $length = $dvdfrData['length'];
|
||||
if (!empty($dvdfrData['aspect']) && empty($aspect)) $aspect = $dvdfrData['aspect'];
|
||||
if (!empty($dvdfrData['discs']) && $discs === 1) $discs = (int)$dvdfrData['discs'];
|
||||
}
|
||||
}
|
||||
|
||||
// 🔥 2. TMDB (réalisateur, acteurs, synopsis)
|
||||
// 2. TMDB (réalisateur, synopsis, acteurs)
|
||||
if ($tmdbApiKey && !empty($title)) {
|
||||
$tmdbTitle = $title;
|
||||
$tmdbTitle = preg_replace('/\s*[\[\(].*?[\]\)]\s*/', '', $tmdbTitle);
|
||||
@@ -497,12 +495,7 @@ switch ($action) {
|
||||
$tmdbTitle = explode(' - ', $tmdbTitle)[0];
|
||||
$tmdbTitle = trim($tmdbTitle);
|
||||
|
||||
if ($tmdbTitle !== $title) {
|
||||
$debugLog[] = "Titre nettoyé: '$title' -> '$tmdbTitle'";
|
||||
}
|
||||
|
||||
$tmdbData = fetchTMDBFull($tmdbTitle, $year, $tmdbApiKey, $pdo);
|
||||
|
||||
if (!$tmdbData && $tmdbTitle !== $title) {
|
||||
$tmdbData = fetchTMDBFull($title, $year, $tmdbApiKey, $pdo);
|
||||
}
|
||||
@@ -514,13 +507,9 @@ switch ($action) {
|
||||
if (empty($length) && !empty($tmdbData['length'])) $length = $tmdbData['length'];
|
||||
if (!empty($tmdbData['overview'])) $description = $tmdbData['overview'];
|
||||
if (!empty($tmdbData['cast'])) $actors = implode(', ', $tmdbData['cast']);
|
||||
} else {
|
||||
$debugLog[] = "TMDB non trouvé pour: '$tmdbTitle'";
|
||||
}
|
||||
}
|
||||
|
||||
$debugLog[] = "Film: '$title' | Réal: '$director' | Durée: '$length' | Éditeur: '$publisher'";
|
||||
|
||||
$sql = "INSERT INTO videotheque (id, title, year, director, poster, format, length, publisher, ean_isbn13, number_of_discs, aspect_ratio, description, actors)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
@@ -539,20 +528,32 @@ switch ($action) {
|
||||
$stmt->execute([$id, $title, $year, $director, $poster, $format, $length, $publisher, $ean, $discs, $aspect, $description, $actors]);
|
||||
|
||||
} else {
|
||||
// Pour les critiques
|
||||
// ── IMPORT DES CRITIQUES ──
|
||||
$ratingRaw = $rowData['Rating'] ?? $rowData['rating'] ?? '';
|
||||
$rating = ($ratingRaw !== '' && $ratingRaw !== null) ? (float)$ratingRaw : null;
|
||||
$review = $rowData['Review'] ?? $rowData['review'] ?? '';
|
||||
$director = ''; $poster = ''; $streaming = '';
|
||||
|
||||
if ($tmdbApiKey && !empty($title)) {
|
||||
// 🔥 Nettoyage du titre pour TMDB
|
||||
$tmdbTitle = preg_replace('/\s*[\[\(].*?[\]\)]\s*/', '', $title);
|
||||
$tmdbTitle = trim($tmdbTitle);
|
||||
|
||||
$tmdbData = fetchTMDBFull($tmdbTitle, $year, $tmdbApiKey, $pdo);
|
||||
if (!$tmdbData && $tmdbTitle !== $title) {
|
||||
$tmdbData = fetchTMDBFull($title, $year, $tmdbApiKey, $pdo);
|
||||
}
|
||||
|
||||
if ($tmdbData) {
|
||||
$director = $tmdbData['director'];
|
||||
$poster = $tmdbData['poster'];
|
||||
$streaming = $tmdbData['streaming'];
|
||||
if(empty($year)) $year = $tmdbData['year'];
|
||||
$director = $tmdbData['director'] ?? '';
|
||||
$poster = $tmdbData['poster'] ?? '';
|
||||
$streaming = $tmdbData['streaming'] ?? '';
|
||||
if (empty($year) && !empty($tmdbData['year'])) $year = $tmdbData['year'];
|
||||
// 🔥 Récupération du titre français
|
||||
if (!empty($tmdbData['title'])) $title = $tmdbData['title'];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($streaming)) $streaming = 'Support physique / Cinéma';
|
||||
|
||||
$sql = "INSERT INTO critiques (id, title, year, director, poster, rating, review, streaming)
|
||||
|
||||
Reference in New Issue
Block a user