Actualiser api.php
This commit is contained in:
@@ -448,7 +448,7 @@ switch ($action) {
|
||||
$actors = implode(', ', array_slice($actorsArray, 0, 4));
|
||||
}
|
||||
|
||||
// 1. UPCitemDB
|
||||
// 1. UPCitemDB (enrichissement optionnel, ne bloque pas l'import)
|
||||
if (!empty($ean)) {
|
||||
$upcData = fetchUPCitemdb($ean, $pdo);
|
||||
if ($upcData) {
|
||||
@@ -457,74 +457,49 @@ switch ($action) {
|
||||
if (empty($publisher)) $publisher = $upcData['publisher'];
|
||||
if (empty($format) || $format === 'Blu-ray') $format = $upcData['format'];
|
||||
}
|
||||
|
||||
// 🔥 1.5 DVDFr (Récupère uniquement la vraie jaquette FR)
|
||||
// 1.5 DVDFr (Récupère uniquement la vraie jaquette FR)
|
||||
$dvdfrCover = fetchDVDFr($ean, $pdo);
|
||||
if (!empty($dvdfrCover)) {
|
||||
$poster = $dvdfrCover;
|
||||
if (!empty($dvdfrCover)) $poster = $dvdfrCover;
|
||||
}
|
||||
|
||||
// 2. TMDB (Données Officielles & Synopsis)
|
||||
// 2. TMDB (Données Officielles & Synopsis) — fonctionne avec ou sans EAN
|
||||
if ($tmdbApiKey && !empty($title)) {
|
||||
// Premier essai classique
|
||||
$tmdbData = fetchTMDBFull($title, $year, $tmdbApiKey, $pdo);
|
||||
|
||||
// 🔥 NOUVEAU : Si TMDB ne trouve rien (cas des Coffrets ou titres multiples)
|
||||
// Si TMDB ne trouve rien (cas des Coffrets ou titres multiples)
|
||||
if (!$tmdbData || empty($tmdbData['overview'])) {
|
||||
$cleanTitle = $title;
|
||||
|
||||
// A. Supprime les mots parasites
|
||||
$cleanTitle = preg_ireplace(['coffret ', 'l\'intégrale ', 'intégrale ', 'trilogie ', 'quadrilogie ', 'collection '], '', $cleanTitle);
|
||||
|
||||
// B. Sépare les listes de films (ex: "Alien / Aliens" ou "Batman + Batman Le Défi")
|
||||
$cleanTitle = preg_split('/(\/|\+)/', $cleanTitle)[0];
|
||||
|
||||
// C. Sépare les tirets longs (ex: "Le Parrain - L'intégrale")
|
||||
$cleanTitle = preg_split('/(\\/|\+)/', $cleanTitle)[0];
|
||||
$cleanTitle = explode(' - ', $cleanTitle)[0];
|
||||
|
||||
$cleanTitle = trim($cleanTitle);
|
||||
|
||||
// Si le titre a été nettoyé, on relance TMDB avec le titre du 1er film
|
||||
if (!empty($cleanTitle) && $cleanTitle !== $title) {
|
||||
// On omet volontairement l'année, car l'année du coffret n'est pas celle du 1er film
|
||||
$tmdbFallback = fetchTMDBFull($cleanTitle, '', $tmdbApiKey, $pdo);
|
||||
if ($tmdbFallback && !empty($tmdbFallback['overview'])) {
|
||||
$tmdbData = $tmdbFallback;
|
||||
if ($tmdbFallback && !empty($tmdbFallback['overview'])) $tmdbData = $tmdbFallback;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($tmdbData) {
|
||||
if (!empty($tmdbData['title'])) $title = $tmdbData['title'];
|
||||
|
||||
if (empty($director)) {
|
||||
$director = $tmdbData['director'] ?? '';
|
||||
} elseif (!empty($tmdbData['director']) && strpos($director, ',') === false && strpos($tmdbData['director'], ',') !== false) {
|
||||
$director = $tmdbData['director'];
|
||||
}
|
||||
|
||||
if (empty($year) && !empty($tmdbData['year'])) $year = $tmdbData['year'];
|
||||
if (empty($length) && !empty($tmdbData['length'])) $length = $tmdbData['length'];
|
||||
|
||||
// LIGNE DÉSACTIVÉE : TMDB ne touche jamais à l'affiche de la vidéothèque
|
||||
// if (empty($poster) && !empty($tmdbData['poster'])) $poster = $tmdbData['poster'];
|
||||
|
||||
// 🔥 Récupération du Synopsis via TMDB (Même pour le 1er film d'un coffret)
|
||||
if (!empty($tmdbData['overview'])) {
|
||||
$description = $tmdbData['overview'];
|
||||
if (!empty($tmdbData['overview'])) $description = $tmdbData['overview'];
|
||||
if (!empty($tmdbData['cast'])) $actors = implode(', ', $tmdbData['cast']);
|
||||
}
|
||||
}
|
||||
|
||||
// Récupération des Acteurs officiels (Top 4)
|
||||
if (!empty($tmdbData['cast'])) {
|
||||
$actors = implode(', ', $tmdbData['cast']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 🔥 L'INSERT SQL DOIT ÊTRE ICI (EN DEHORS DU IF TMDB)
|
||||
// INSERT toujours exécuté, EAN présent ou non
|
||||
try {
|
||||
$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->execute([$id, $title, $year, $director, $poster, $format, $length, $publisher, $ean, $discs, $aspect, $description, $actors]);
|
||||
} catch (\Exception $e) {
|
||||
error_log("import_batch videotheque error on title '{$title}': " . $e->getMessage());
|
||||
continue;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Pour les critiques
|
||||
|
||||
Reference in New Issue
Block a user