Actualiser api.php

This commit is contained in:
2026-06-24 11:08:30 +02:00
parent d3734532e4
commit 6c11a4ad31
+22 -68
View File
@@ -122,81 +122,35 @@ function extractYear($dateStr) {
function fetchDVDFr($ean, $pdo) {
if (empty($ean) || strlen($ean) < 8) return null;
$cacheKey = 'dvdfr_' . md5($ean);
if (empty($ean)) return null;
$cacheKey = 'dvdfr_full_' . md5($ean);
$cached = getCache($pdo, $cacheKey);
if ($cached) return $cached;
// DVDFr exige un User-Agent propre à l'application (sinon INVALID_UA)
$ua = 'MonCinema/1.0 (collection privée; contact@moncineapp.fr)';
// Étape 1 : recherche par gencode → récupère l'id DVDFr
$searchUrl = "https://www.dvdfr.com/api/search.php?gencode=" . urlencode($ean);
$ch = curl_init($searchUrl);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 5,
CURLOPT_CONNECTTIMEOUT => 3,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_USERAGENT => $ua,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTPHEADER => ['Accept: application/xml, text/xml, */*'],
]);
$res = curl_exec($ch);
curl_close($ch);
// Récupération de la page
$url = "https://www.dvdfr.com/api/search.php?gencode=" . urlencode($ean);
$res = httpGet($url, 10);
if (!$res) return null;
libxml_use_internal_errors(true);
$xml = simplexml_load_string($res);
libxml_clear_errors();
if (!$xml || !isset($xml->dvd[0]->id)) return null;
try {
$xml = @simplexml_load_string($res);
if ($xml && isset($xml->dvd[0])) {
$dvd = $xml->dvd[0];
$dvdId = (string)$xml->dvd[0]->id;
if (empty($dvdId)) return null;
// Extraction des données
$data = [
'poster' => (string)$dvd->cover,
'title' => (string)$dvd->title,
'director' => (string)$dvd->directors->director->name,
'actors' => '', // DVDFr API est limitée sur les acteurs, souvent vide
'year' => (string)$dvd->year
];
// Étape 2 : fiche complète via dvd.php?id= (quota 200/semaine, utilise le cache)
$ficheUrl = "https://www.dvdfr.com/api/dvd.php?id=" . urlencode($dvdId);
$ch2 = curl_init($ficheUrl);
curl_setopt_array($ch2, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 5,
CURLOPT_CONNECTTIMEOUT => 3,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_USERAGENT => $ua,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTPHEADER => ['Accept: application/xml, text/xml, */*'],
]);
$res2 = curl_exec($ch2);
curl_close($ch2);
if (!$res2) return null;
libxml_use_internal_errors(true);
$fiche = simplexml_load_string($res2);
libxml_clear_errors();
if (!$fiche || !isset($fiche->dvd[0])) return null;
$dvd = $fiche->dvd[0];
// Extraction de la jaquette (nouvelle structure après refonte)
$poster = '';
if (isset($dvd->cover)) $poster = (string)$dvd->cover;
if (empty($poster) && isset($dvd->covers->cover[0])) $poster = (string)$dvd->covers->cover[0];
// Extraction des métadonnées techniques
$result = [
'poster' => $poster,
'publisher' => isset($dvd->editeur) ? (string)$dvd->editeur : '',
'format' => isset($dvd->type) ? (string)$dvd->type : '',
'length' => isset($dvd->duree) ? (string)$dvd->duree : '',
'aspect' => isset($dvd->formatimage) ? (string)$dvd->formatimage : '',
'discs' => isset($dvd->nbdisques) ? (string)$dvd->nbdisques : '',
];
// Ne met en cache que si on a au moins une affiche ou un éditeur
if (!empty($result['poster']) || !empty($result['publisher'])) {
setCache($pdo, $cacheKey, $result, 'dvdfr');
}
return !empty($result['poster']) || !empty($result['publisher']) ? $result : null;
setCache($pdo, $cacheKey, $data, 'dvdfr');
return $data;
}
} catch (\Exception $e) { return null; }
return null;
}
// ── 2. API TMDB (Full Extract avec Synopsis et Acteurs) ──