Actualiser api.php
This commit is contained in:
@@ -122,81 +122,35 @@ function extractYear($dateStr) {
|
|||||||
|
|
||||||
|
|
||||||
function fetchDVDFr($ean, $pdo) {
|
function fetchDVDFr($ean, $pdo) {
|
||||||
if (empty($ean) || strlen($ean) < 8) return null;
|
if (empty($ean)) return null;
|
||||||
$cacheKey = 'dvdfr_' . md5($ean);
|
$cacheKey = 'dvdfr_full_' . md5($ean);
|
||||||
$cached = getCache($pdo, $cacheKey);
|
$cached = getCache($pdo, $cacheKey);
|
||||||
if ($cached) return $cached;
|
if ($cached) return $cached;
|
||||||
|
|
||||||
// DVDFr exige un User-Agent propre à l'application (sinon INVALID_UA)
|
// Récupération de la page
|
||||||
$ua = 'MonCinema/1.0 (collection privée; contact@moncineapp.fr)';
|
$url = "https://www.dvdfr.com/api/search.php?gencode=" . urlencode($ean);
|
||||||
|
$res = httpGet($url, 10);
|
||||||
// É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);
|
|
||||||
if (!$res) return null;
|
if (!$res) return null;
|
||||||
|
|
||||||
libxml_use_internal_errors(true);
|
try {
|
||||||
$xml = simplexml_load_string($res);
|
$xml = @simplexml_load_string($res);
|
||||||
libxml_clear_errors();
|
if ($xml && isset($xml->dvd[0])) {
|
||||||
if (!$xml || !isset($xml->dvd[0]->id)) return null;
|
$dvd = $xml->dvd[0];
|
||||||
|
|
||||||
$dvdId = (string)$xml->dvd[0]->id;
|
// Extraction des données
|
||||||
if (empty($dvdId)) return null;
|
$data = [
|
||||||
|
'poster' => (string)$dvd->cover,
|
||||||
// Étape 2 : fiche complète via dvd.php?id= (quota 200/semaine, utilise le cache)
|
'title' => (string)$dvd->title,
|
||||||
$ficheUrl = "https://www.dvdfr.com/api/dvd.php?id=" . urlencode($dvdId);
|
'director' => (string)$dvd->directors->director->name,
|
||||||
$ch2 = curl_init($ficheUrl);
|
'actors' => '', // DVDFr API est limitée sur les acteurs, souvent vide
|
||||||
curl_setopt_array($ch2, [
|
'year' => (string)$dvd->year
|
||||||
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
|
setCache($pdo, $cacheKey, $data, 'dvdfr');
|
||||||
if (!empty($result['poster']) || !empty($result['publisher'])) {
|
return $data;
|
||||||
setCache($pdo, $cacheKey, $result, 'dvdfr');
|
|
||||||
}
|
}
|
||||||
return !empty($result['poster']) || !empty($result['publisher']) ? $result : null;
|
} catch (\Exception $e) { return null; }
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 2. API TMDB (Full Extract avec Synopsis et Acteurs) ──
|
// ── 2. API TMDB (Full Extract avec Synopsis et Acteurs) ──
|
||||||
|
|||||||
Reference in New Issue
Block a user