Actualiser api.php
This commit is contained in:
@@ -473,7 +473,7 @@ function fetchFromMovieCovers($title, $year = '') {
|
|||||||
return $empty;
|
return $empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── AGGREGATEUR PHYSIQUE (VERSION MODIFIÉE AVEC GO-UPC ET UPCINDEX) ──
|
// Dans la fonction fetchPhysicalByEan - Ligne ~780
|
||||||
function fetchPhysicalByEan($ean, $pdo = null) {
|
function fetchPhysicalByEan($ean, $pdo = null) {
|
||||||
error_log("=== DEBUT fetchPhysicalByEan EAN=$ean ===");
|
error_log("=== DEBUT fetchPhysicalByEan EAN=$ean ===");
|
||||||
|
|
||||||
@@ -532,21 +532,25 @@ function fetchPhysicalByEan($ean, $pdo = null) {
|
|||||||
if (!empty($blurayData['aspect_ratio'])) $res['aspect_ratio'] = $blurayData['aspect_ratio'];
|
if (!empty($blurayData['aspect_ratio'])) $res['aspect_ratio'] = $blurayData['aspect_ratio'];
|
||||||
if (!empty($blurayData['publisher'])) $res['publisher'] = $blurayData['publisher'];
|
if (!empty($blurayData['publisher'])) $res['publisher'] = $blurayData['publisher'];
|
||||||
if (!empty($blurayData['format'])) $res['format'] = $blurayData['format'];
|
if (!empty($blurayData['format'])) $res['format'] = $blurayData['format'];
|
||||||
if (!empty($blurayData['poster'])) $res['poster'] = $blurayData['poster'];
|
// ⚠️ NE PAS ÉCRASER L'IMAGE DE GO-UPC
|
||||||
|
// if (!empty($blurayData['poster'])) $res['poster'] = $blurayData['poster'];
|
||||||
if (!empty($blurayData['year'])) $res['year'] = $blurayData['year'];
|
if (!empty($blurayData['year'])) $res['year'] = $blurayData['year'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. MovieCovers (par titre)
|
// 6. MovieCovers (par titre) - Pour jaquette HD FR
|
||||||
if (!empty($title)) {
|
if (!empty($title)) {
|
||||||
$mc = fetchFromMovieCovers($title, $res['year'] ?? '');
|
$mc = fetchFromMovieCovers($title, $res['year'] ?? '');
|
||||||
error_log("MOVIECOVERS -> poster='" . ($mc['poster'] ?? '') . "'");
|
error_log("MOVIECOVERS -> poster='" . ($mc['poster'] ?? '') . "'");
|
||||||
if (!empty($mc['poster'])) $res['poster'] = $mc['poster'];
|
// ⚠️ PRIORITÉ À L'IMAGE DE GO-UPC, SINON MOVIECOVERS
|
||||||
|
if (empty($res['poster']) && !empty($mc['poster'])) {
|
||||||
|
$res['poster'] = $mc['poster'];
|
||||||
|
}
|
||||||
if (!empty($mc['director'])) $res['director'] = $mc['director'];
|
if (!empty($mc['director'])) $res['director'] = $mc['director'];
|
||||||
if (!empty($mc['actors'])) $res['actors'] = $mc['actors'];
|
if (!empty($mc['actors'])) $res['actors'] = $mc['actors'];
|
||||||
if (!empty($mc['description'])) $res['description'] = $mc['description'];
|
if (!empty($mc['description'])) $res['description'] = $mc['description'];
|
||||||
}
|
}
|
||||||
|
|
||||||
error_log("=== FIN fetchPhysicalByEan -> title FINAL='" . ($res['title'] ?? '') . "' ===");
|
error_log("=== FIN fetchPhysicalByEan -> title FINAL='" . ($res['title'] ?? '') . "' poster='" . ($res['poster'] ?? '') . "' ===");
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -666,7 +670,10 @@ switch ($action) {
|
|||||||
$tmdbData = fetchTmdbPosterAndSynopsis($rawTitle, $physicalData['year'] ?? '', $pdo);
|
$tmdbData = fetchTmdbPosterAndSynopsis($rawTitle, $physicalData['year'] ?? '', $pdo);
|
||||||
|
|
||||||
$finalTitle = !empty($tmdbData['title']) ? $tmdbData['title'] : $rawTitle;
|
$finalTitle = !empty($tmdbData['title']) ? $tmdbData['title'] : $rawTitle;
|
||||||
$poster = ($tmdbData['poster'] !== 'assets/img/default_physical_media.jpg') ? $tmdbData['poster'] : ($physicalData['poster'] ?? '');
|
|
||||||
|
// ✅ PRIORITÉ À L'IMAGE DE GO-UPC/PHYSICAL DATA
|
||||||
|
$poster = !empty($physicalData['poster']) ? $physicalData['poster'] :
|
||||||
|
(($tmdbData['poster'] !== 'assets/img/default_physical_media.jpg') ? $tmdbData['poster'] : 'assets/img/default_physical_media.jpg');
|
||||||
|
|
||||||
$year = $tmdbData['year'] ?? $physicalData['year'] ?? '';
|
$year = $tmdbData['year'] ?? $physicalData['year'] ?? '';
|
||||||
$id = makeStableId('videotheque', $finalTitle, $year);
|
$id = makeStableId('videotheque', $finalTitle, $year);
|
||||||
@@ -681,54 +688,60 @@ switch ($action) {
|
|||||||
$tmdbData['length'] ?: ($physicalData['length'] ?? ''),
|
$tmdbData['length'] ?: ($physicalData['length'] ?? ''),
|
||||||
$physicalData['publisher'] ?? '', $physicalData['number_of_discs'] ?? 1, $physicalData['aspect_ratio'] ?? ''
|
$physicalData['publisher'] ?? '', $physicalData['number_of_discs'] ?? 1, $physicalData['aspect_ratio'] ?? ''
|
||||||
]);
|
]);
|
||||||
|
|
||||||
echo json_encode(["success" => true, "title" => $finalTitle, "director" => $tmdbData['director'] ?: ($physicalData['director'] ?? ''), "year" => $year]);
|
echo json_encode(["success" => true, "title" => $finalTitle, "director" => $tmdbData['director'] ?: ($physicalData['director'] ?? ''), "year" => $year]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'import_batch':
|
case 'import_batch':
|
||||||
checkAuth($pdo);
|
checkAuth($pdo);
|
||||||
$type = $data['type'] ?? '';
|
$type = $data['type'] ?? '';
|
||||||
$items = $data['items'] ?? [];
|
$items = $data['items'] ?? [];
|
||||||
$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) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE title=VALUES(title), year=VALUES(year), format=VALUES(format), poster=IF(VALUES(poster)!='assets/img/default_physical_media.jpg', VALUES(poster), poster), ean_isbn13=IF(VALUES(ean_isbn13)!='', VALUES(ean_isbn13), ean_isbn13), description=IF(VALUES(description)!='', VALUES(description), description), length=IF(VALUES(length)!='', VALUES(length), length), number_of_discs=IF(VALUES(number_of_discs)!=1, VALUES(number_of_discs), number_of_discs), aspect_ratio=IF(VALUES(aspect_ratio)!='', VALUES(aspect_ratio), aspect_ratio), actors=IF(VALUES(actors)!='', VALUES(actors), actors), publisher=IF(VALUES(publisher)!='', VALUES(publisher), publisher), director=IF(VALUES(director)!='', VALUES(director), 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 title=VALUES(title), year=VALUES(year), format=VALUES(format), poster=IF(VALUES(poster)!='assets/img/default_physical_media.jpg', VALUES(poster), poster), ean_isbn13=IF(VALUES(ean_isbn13)!='', VALUES(ean_isbn13), ean_isbn13), description=IF(VALUES(description)!='', VALUES(description), description), length=IF(VALUES(length)!='', VALUES(length), length), number_of_discs=IF(VALUES(number_of_discs)!=1, VALUES(number_of_discs), number_of_discs), aspect_ratio=IF(VALUES(aspect_ratio)!='', VALUES(aspect_ratio), aspect_ratio), actors=IF(VALUES(actors)!='', VALUES(actors), actors), publisher=IF(VALUES(publisher)!='', VALUES(publisher), publisher), director=IF(VALUES(director)!='', VALUES(director), director)");
|
||||||
|
|
||||||
|
foreach ($items as $item) {
|
||||||
|
$ean = preg_replace('/[^0-9]/', '', (string)($item['ean'] ?? ''));
|
||||||
|
if (strlen($ean) < 8) { $skipped++; continue; }
|
||||||
|
|
||||||
|
$physicalData = fetchPhysicalByEan($ean, $pdo);
|
||||||
|
$title = $physicalData['title'] ?? '';
|
||||||
|
$year = $physicalData['year'] ?? '';
|
||||||
|
$format = $physicalData['format'] ?: detectFormat($title);
|
||||||
|
$publisher = $physicalData['publisher'] ?? '';
|
||||||
|
$discs = $physicalData['number_of_discs'] ?: 1;
|
||||||
|
$aspect = $physicalData['aspect_ratio'] ?? '';
|
||||||
|
$length = $physicalData['length'] ?? '';
|
||||||
|
|
||||||
foreach ($items as $item) {
|
// ✅ PRIORITÉ À L'IMAGE DE GO-UPC
|
||||||
$ean = preg_replace('/[^0-9]/', '', (string)($item['ean'] ?? ''));
|
$poster = !empty($physicalData['poster']) ? $physicalData['poster'] : 'assets/img/default_physical_media.jpg';
|
||||||
if (strlen($ean) < 8) { $skipped++; continue; }
|
|
||||||
|
$desc = $physicalData['description'] ?? '';
|
||||||
|
$director = $physicalData['director'] ?? '';
|
||||||
|
$actors = $physicalData['actors'] ?? '';
|
||||||
|
|
||||||
$physicalData = fetchPhysicalByEan($ean, $pdo);
|
if (empty($poster) || empty($director) || empty($actors) || empty($desc) || empty($title)) {
|
||||||
$title = $physicalData['title'] ?? '';
|
$tmdb = fetchTmdbPosterAndSynopsis($title, $year, $pdo);
|
||||||
$year = $physicalData['year'] ?? '';
|
if (empty($title)) $title = $tmdb['title'] ?? "EAN: $ean";
|
||||||
$format = $physicalData['format'] ?: detectFormat($title);
|
// ⚠️ NE PAS ÉCRASER L'IMAGE DE GO-UPC
|
||||||
$publisher = $physicalData['publisher'] ?? '';
|
if (empty($poster) && $tmdb['poster'] !== 'assets/img/default_physical_media.jpg') {
|
||||||
$discs = $physicalData['number_of_discs'] ?: 1;
|
$poster = $tmdb['poster'];
|
||||||
$aspect = $physicalData['aspect_ratio'] ?? '';
|
|
||||||
$length = $physicalData['length'] ?? '';
|
|
||||||
$poster = $physicalData['poster'] ?? '';
|
|
||||||
$desc = $physicalData['description'] ?? '';
|
|
||||||
$director = $physicalData['director'] ?? '';
|
|
||||||
$actors = $physicalData['actors'] ?? '';
|
|
||||||
|
|
||||||
if (empty($poster) || empty($director) || empty($actors) || empty($desc) || empty($title)) {
|
|
||||||
$tmdb = fetchTmdbPosterAndSynopsis($title, $year, $pdo);
|
|
||||||
if (empty($title)) $title = $tmdb['title'] ?? "EAN: $ean";
|
|
||||||
if (empty($poster) || $poster === 'assets/img/default_physical_media.jpg') $poster = $tmdb['poster'];
|
|
||||||
if (empty($director)) $director = $tmdb['director'] ?? '';
|
|
||||||
if (empty($actors)) $actors = $tmdb['actors'] ?? '';
|
|
||||||
if (empty($desc)) $desc = $tmdb['description'] ?? '';
|
|
||||||
if (empty($length) && !empty($tmdb['length'])) $length = $tmdb['length'];
|
|
||||||
if (empty($year) && !empty($tmdb['year'])) $year = $tmdb['year'];
|
|
||||||
}
|
}
|
||||||
|
if (empty($director)) $director = $tmdb['director'] ?? '';
|
||||||
if (empty($title)) { $skipped++; continue; }
|
if (empty($actors)) $actors = $tmdb['actors'] ?? '';
|
||||||
$id = makeStableId('videotheque', $title, $year);
|
if (empty($desc)) $desc = $tmdb['description'] ?? '';
|
||||||
$stmt->execute([$id, $title, $year, $format, $poster, $ean, $desc, $length, $discs, $aspect, $actors, $publisher, $director]);
|
if (empty($length) && !empty($tmdb['length'])) $length = $tmdb['length'];
|
||||||
$imported++;
|
if (empty($year) && !empty($tmdb['year'])) $year = $tmdb['year'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (empty($title)) { $skipped++; continue; }
|
||||||
|
$id = makeStableId('videotheque', $title, $year);
|
||||||
|
$stmt->execute([$id, $title, $year, $format, $poster, $ean, $desc, $length, $discs, $aspect, $actors, $publisher, $director]);
|
||||||
|
$imported++;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$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), poster=VALUES(poster), rating=VALUES(rating), review=VALUES(review), streaming=VALUES(streaming)");
|
$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), poster=VALUES(poster), rating=VALUES(rating), review=VALUES(review), streaming=VALUES(streaming)");
|
||||||
foreach ($items as $rowData) {
|
foreach ($items as $rowData) {
|
||||||
|
|||||||
Reference in New Issue
Block a user