Actualiser api.php
This commit is contained in:
@@ -598,42 +598,50 @@ case 'import_batch':
|
||||
$pdo->beginTransaction();
|
||||
$imported = 0; $skipped = 0;
|
||||
try {
|
||||
if ($type === 'videotheque') {
|
||||
if ($type === 'videotheque') {
|
||||
$stmt = $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
|
||||
title=VALUES(title), year=VALUES(year), format=VALUES(format), poster=VALUES(poster), ean_isbn13=VALUES(ean_isbn13), description=VALUES(description), length=VALUES(length), number_of_discs=VALUES(number_of_discs), aspect_ratio=VALUES(aspect_ratio), actors=VALUES(actors), publisher=VALUES(publisher), director=VALUES(director)");
|
||||
|
||||
foreach ($items as $item) {
|
||||
$ean = preg_replace('/[^0-9]/', '', (string)($item['ean'] ?? ''));
|
||||
if (strlen($ean) < 8) { $skipped++; continue; }
|
||||
$csvTitle = trim($item['title'] ?? ''); // Titre issu de votre CSV
|
||||
|
||||
// 1. Données physiques via BLU-RAY.COM (prioritaire)
|
||||
$blurayData = fetchFromBlurayCom($ean);
|
||||
|
||||
$title = $blurayData['title'] ?? '';
|
||||
if (empty($title)) { $skipped++; continue; }
|
||||
// Si Blu-ray.com trouve le film, on prend son titre. Sinon, on prend celui du CSV.
|
||||
$title = !empty($blurayData['title']) ? $blurayData['title'] : $csvTitle;
|
||||
|
||||
if (empty($title)) {
|
||||
$skipped++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$year = $blurayData['year'] ?? '';
|
||||
$format = $blurayData['format'] ?: 'Blu-ray';
|
||||
$format = $blurayData['format'] ?: detectFormat($title);
|
||||
$publisher = $blurayData['publisher'] ?? '';
|
||||
$discs = $blurayData['number_of_discs'] ?: 1;
|
||||
$aspect = $blurayData['aspect_ratio'] ?? '';
|
||||
$length = $blurayData['length'] ?? '';
|
||||
$poster = $blurayData['poster'] ?? '';
|
||||
|
||||
// 2. Données cinéma via TMDB (Synopsis, Titre, Réalisateur, Acteurs, Année)
|
||||
// 2. Données cinéma via TMDB (Synopsis, Réalisateur, Acteurs, Année)
|
||||
$tmdb = fetchTmdbPosterAndSynopsis($title, $year, $pdo);
|
||||
|
||||
// Fusion des données : TMDB complète Blu-ray.com
|
||||
if (!empty($tmdb['description'])) $desc = $tmdb['description'];
|
||||
else $desc = '';
|
||||
|
||||
$director = !empty($tmdb['director']) ? $tmdb['director'] : ($blurayData['director'] ?? '');
|
||||
$actors = !empty($tmdb['actors']) ? $tmdb['actors'] : ($blurayData['actors'] ?? '');
|
||||
// Fusion des données : TMDB complète ce qui manque
|
||||
$desc = !empty($tmdb['description']) ? $tmdb['description'] : '';
|
||||
$director = !empty($tmdb['director']) ? $tmdb['director'] : '';
|
||||
$actors = !empty($tmdb['actors']) ? $tmdb['actors'] : '';
|
||||
|
||||
if (empty($year) && !empty($tmdb['year'])) $year = $tmdb['year'];
|
||||
if (empty($length) && !empty($tmdb['length'])) $length = $tmdb['length'];
|
||||
|
||||
// Si Blu-ray.com n'a pas trouvé d'affiche, on prend celle de TMDB
|
||||
if (empty($poster) || $poster === 'assets/img/default_physical_media.jpg') {
|
||||
$poster = $tmdb['poster'];
|
||||
}
|
||||
|
||||
$id = makeStableId('videotheque', $title, $year);
|
||||
$stmt->execute([$id, $title, $year, $format, $poster, $ean, $desc, $length, $discs, $aspect, $actors, $publisher, $director]);
|
||||
$imported++;
|
||||
|
||||
Reference in New Issue
Block a user