Actualiser api.php

This commit is contained in:
2026-06-23 16:24:56 +02:00
parent 0e648c2e25
commit 5b2fd5685e
+15 -10
View File
@@ -137,27 +137,32 @@ function fetchUPCitemdb($ean, $pdo) {
return null; return null;
} }
// ── 1.5 API DVDFr (Spécial Jaquettes Physiques FR) ── // ── 1.5 API DVDFr (Spécial Jaquettes & Synopsis FR) ──
function fetchDVDFr($ean, $pdo) { function fetchDVDFr($ean, $pdo) {
if (empty($ean) || strlen($ean) < 8) return null; if (empty($ean) || strlen($ean) < 8) return null;
$cacheKey = 'dvdfr_' . md5($ean); $cacheKey = 'dvdfr_data_' . md5($ean); // Nouvelle clé de cache
$cached = getCache($pdo, $cacheKey); $cached = getCache($pdo, $cacheKey);
if ($cached) return $cached; if ($cached) return json_decode($cached, true);
$url = "https://www.dvdfr.com/api/search.php?gencode=" . urlencode($ean); $url = "https://www.dvdfr.com/api/search.php?gencode=" . urlencode($ean);
$res = httpGet($url, 5); $res = httpGet($url, 5);
if (!$res) return null; if (!$res) return null;
try { try {
// DVDFr renvoie du XML, on le parse silencieusement (@)
$xml = @simplexml_load_string($res); $xml = @simplexml_load_string($res);
if ($xml && isset($xml->dvd) && isset($xml->dvd[0]->cover)) { if ($xml && isset($xml->dvd) && isset($xml->dvd[0])) {
$poster = (string)$xml->dvd[0]->cover; $dvd = $xml->dvd[0];
if (!empty($poster)) { $poster = isset($dvd->cover) ? (string)$dvd->cover : '';
setCache($pdo, $cacheKey, $poster, 'dvdfr');
return $poster; // Le synopsis chez DVDFr se trouve dans la balise <resume>
} // strip_tags permet d'enlever les balises HTML ou paragraphes parasites
$synopsis = isset($dvd->resume) ? trim(strip_tags((string)$dvd->resume)) : '';
$data = ['poster' => $poster, 'synopsis' => $synopsis];
setCache($pdo, $cacheKey, json_encode($data), 'dvdfr');
return $data;
} }
} catch (\Exception $e) { } catch (\Exception $e) {
return null; return null;