Actualiser api.php
This commit is contained in:
@@ -166,12 +166,16 @@ function fetchTMDBFull($title, $year, $apiKey, $pdo) {
|
|||||||
if (!$detailsRes) return null;
|
if (!$detailsRes) return null;
|
||||||
$details = json_decode($detailsRes, true);
|
$details = json_decode($detailsRes, true);
|
||||||
|
|
||||||
// Extraction Réalisateur
|
// 🔥 Extraction de TOUS les Réalisateurs (pour les co-réalisations)
|
||||||
$director = '';
|
$director = '';
|
||||||
if (!empty($details['credits']['crew'])) {
|
if (!empty($details['credits']['crew'])) {
|
||||||
|
$directorsList = [];
|
||||||
foreach ($details['credits']['crew'] as $crew) {
|
foreach ($details['credits']['crew'] as $crew) {
|
||||||
if ($crew['job'] === 'Director') { $director = $crew['name']; break; }
|
if ($crew['job'] === 'Director') {
|
||||||
|
$directorsList[] = $crew['name'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
$director = implode(', ', $directorsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🔥 Extraction des 4 premiers Acteurs
|
// 🔥 Extraction des 4 premiers Acteurs
|
||||||
@@ -400,26 +404,24 @@ switch ($action) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. TMDB (Écrase les données CSV avec les données officielles)
|
// 2. TMDB (Écrase les données CSV avec les données officielles)
|
||||||
if ($tmdbApiKey && !empty($title)) {
|
if ($tmdbApiKey && !empty($title)) {
|
||||||
$tmdbData = fetchTMDBFull($title, $year, $tmdbApiKey, $pdo);
|
$tmdbData = fetchTMDBFull($title, $year, $tmdbApiKey, $pdo);
|
||||||
if ($tmdbData) {
|
if ($tmdbData) {
|
||||||
if (!empty($tmdbData['title'])) $title = $tmdbData['title'];
|
if (!empty($tmdbData['title'])) $title = $tmdbData['title'];
|
||||||
if (!empty($tmdbData['director'])) $director = $tmdbData['director']; // Écrase avec le vrai réalisateur
|
|
||||||
if (empty($year) && !empty($tmdbData['year'])) $year = $tmdbData['year'];
|
// 🔥 FIX : Gestion intelligente des réalisateurs (Coffrets / Anthologies)
|
||||||
if (empty($length) && !empty($tmdbData['length'])) $length = $tmdbData['length'];
|
if (empty($director)) {
|
||||||
if (empty($poster) && !empty($tmdbData['poster'])) $poster = $tmdbData['poster'];
|
// Si le CSV n'a pas de réalisateur, on prend celui de TMDB
|
||||||
|
$director = $tmdbData['director'] ?? '';
|
||||||
// 🔥 Récupération du Synopsis officiel
|
} elseif (!empty($tmdbData['director']) && strpos($director, ',') === false && strpos($tmdbData['director'], ',') !== false) {
|
||||||
if (!empty($tmdbData['overview'])) {
|
// Si le CSV a 1 seul réalisateur mais que TMDB en trouve plusieurs, on met à jour
|
||||||
$description = $tmdbData['overview'];
|
$director = $tmdbData['director'];
|
||||||
}
|
|
||||||
// 🔥 Récupération des Acteurs officiels (Top 4)
|
|
||||||
if (!empty($tmdbData['cast'])) {
|
|
||||||
$actors = implode(', ', $tmdbData['cast']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
// 🔥 Sinon, on GARDE les réalisateurs du CSV (indispensable pour les coffrets
|
||||||
|
// où TMDB ne trouve que le réalisateur du 1er film de la compilation)
|
||||||
|
|
||||||
|
if (empty($year) && !empty($tmdbData['year'])) $year = $tmdbData['year'];
|
||||||
|
|
||||||
$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 director=IF(VALUES(director)!='',VALUES(director),director), poster=IF(VALUES(poster)!='',VALUES(poster),poster), format=IF(VALUES(format)!='',VALUES(format),format), length=IF(VALUES(length)!='',VALUES(length),length), publisher=IF(VALUES(publisher)!='',VALUES(publisher),publisher), ean_isbn13=IF(VALUES(ean_isbn13)!='',VALUES(ean_isbn13),ean_isbn13), 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), description=IF(VALUES(description)!='',VALUES(description),description), actors=IF(VALUES(actors)!='',VALUES(actors),actors)";
|
$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 director=IF(VALUES(director)!='',VALUES(director),director), poster=IF(VALUES(poster)!='',VALUES(poster),poster), format=IF(VALUES(format)!='',VALUES(format),format), length=IF(VALUES(length)!='',VALUES(length),length), publisher=IF(VALUES(publisher)!='',VALUES(publisher),publisher), ean_isbn13=IF(VALUES(ean_isbn13)!='',VALUES(ean_isbn13),ean_isbn13), 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), description=IF(VALUES(description)!='',VALUES(description),description), actors=IF(VALUES(actors)!='',VALUES(actors),actors)";
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
|
|||||||
Reference in New Issue
Block a user