Actualiser api.php

This commit is contained in:
2026-06-23 15:11:52 +02:00
parent 7871e107e4
commit 52d0eb520c
+42 -2
View File
@@ -137,6 +137,34 @@ function fetchUPCitemdb($ean, $pdo) {
return null;
}
// ── 1.5 API DVDFr (Spécial Jaquettes Physiques FR) ──
function fetchDVDFr($ean, $pdo) {
if (empty($ean) || strlen($ean) < 8) return null;
$cacheKey = 'dvdfr_' . md5($ean);
$cached = getCache($pdo, $cacheKey);
if ($cached) return $cached;
$url = "https://www.dvdfr.com/api/search.php?gencode=" . urlencode($ean);
$res = httpGet($url, 5);
if (!$res) return null;
try {
// DVDFr renvoie du XML, on le parse silencieusement (@)
$xml = @simplexml_load_string($res);
if ($xml && isset($xml->dvd) && isset($xml->dvd[0]->cover)) {
$poster = (string)$xml->dvd[0]->cover;
if (!empty($poster)) {
setCache($pdo, $cacheKey, $poster, 'dvdfr');
return $poster;
}
}
} catch (\Exception $e) {
return null;
}
return null;
}
// ── 2. API TMDB (Full Extract avec Synopsis et Acteurs) ──
function fetchTMDBFull($title, $year, $apiKey, $pdo) {
if (empty($apiKey) || empty($title)) return null;
@@ -279,7 +307,7 @@ switch ($action) {
'poster' => '', 'publisher' => '', 'format' => '',
'length' => '', 'number_of_discs' => 1, 'aspect_ratio' => '', 'actors' => ''
];
$upcData = fetchUPCitemdb($ean, $pdo);
$upcData = fetchUPCitemdb($ean, $pdo);
$tmdbQueryTitle = "";
if ($upcData) {
$tmdbQueryTitle = $upcData['title'];
@@ -288,6 +316,12 @@ switch ($action) {
$result['publisher'] = $upcData['publisher'];
$result['format'] = $upcData['format'];
}
// 🔥 NOUVEAU : DVDFr pour remplacer l'affiche lors d'un ajout manuel
$dvdfrCover = fetchDVDFr($ean, $pdo);
if (!empty($dvdfrCover)) {
$result['poster'] = $dvdfrCover;
}
$tmdbKey = getTmdbApiKey($pdo);
if ($tmdbKey && $tmdbQueryTitle) {
$tmdbData = fetchTMDBFull($tmdbQueryTitle, '', $tmdbKey, $pdo);
@@ -393,7 +427,7 @@ switch ($action) {
$actors = implode(', ', array_slice($actorsArray, 0, 4));
}
// 1. UPCitemDB
// 1. UPCitemDB
if (!empty($ean)) {
$upcData = fetchUPCitemdb($ean, $pdo);
if ($upcData) {
@@ -402,6 +436,12 @@ switch ($action) {
if (empty($publisher)) $publisher = $upcData['publisher'];
if (empty($format) || $format === 'Blu-ray') $format = $upcData['format'];
}
// 🔥 NOUVEAU : 1.5 DVDFr (Écrase l'affiche UPC avec la vraie jaquette FR)
$dvdfrCover = fetchDVDFr($ean, $pdo);
if (!empty($dvdfrCover)) {
$poster = $dvdfrCover;
}
}
// 2. TMDB (Écrase les données CSV avec les données officielles)