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