Actualiser api.php
This commit is contained in:
@@ -137,27 +137,32 @@ function fetchUPCitemdb($ean, $pdo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// ── 1.5 API DVDFr (Spécial Jaquettes Physiques FR) ──
|
||||
// ── 1.5 API DVDFr (Spécial Jaquettes & Synopsis FR) ──
|
||||
function fetchDVDFr($ean, $pdo) {
|
||||
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);
|
||||
if ($cached) return $cached;
|
||||
if ($cached) return json_decode($cached, true);
|
||||
|
||||
$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;
|
||||
}
|
||||
if ($xml && isset($xml->dvd) && isset($xml->dvd[0])) {
|
||||
$dvd = $xml->dvd[0];
|
||||
$poster = isset($dvd->cover) ? (string)$dvd->cover : '';
|
||||
|
||||
// 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) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user