Actualiser api.php

This commit is contained in:
2026-06-24 13:53:18 +02:00
parent c0e2998ffe
commit 6a1a094087
+86 -15
View File
@@ -105,60 +105,129 @@ function extractYear($dateStr) {
return ''; return '';
} }
// ── 1. API DVDFr (SANS CACHE) ──
function fetchDVDFr($ean, $pdo) { function fetchDVDFr($ean, $pdo) {
if (empty($ean) || strlen($ean) < 8) return null; if (empty($ean) || strlen($ean) < 8) {
error_log("DVDFr: EAN invalide ou vide - '$ean'");
return null;
}
$ua = 'MonCinema/1.0 (collection privée; contact@moncineapp.fr)'; $ua = 'MonCinema/1.0 (collection privée; contact@moncineapp.fr)';
// Étape 1 : recherche par gencode
$searchUrl = "https://www.dvdfr.com/api/search.php?gencode=" . urlencode($ean); $searchUrl = "https://www.dvdfr.com/api/search.php?gencode=" . urlencode($ean);
error_log("DVDFr: Appel API search - URL: $searchUrl");
$ch = curl_init($searchUrl); $ch = curl_init($searchUrl);
curl_setopt_array($ch, [ curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true, CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 5, CURLOPT_TIMEOUT => 8,
CURLOPT_CONNECTTIMEOUT => 3, CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_USERAGENT => $ua, CURLOPT_USERAGENT => $ua,
CURLOPT_FOLLOWLOCATION => true, CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTPHEADER => ['Accept: application/xml, text/xml, */*'], CURLOPT_HTTPHEADER => ['Accept: application/xml, text/xml, */*'],
]); ]);
$res = curl_exec($ch); $res = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch); curl_close($ch);
if (!$res) return null;
if (!$res) {
error_log("DVDFr: Échec de la requête search - HTTP $httpCode");
return null;
}
error_log("DVDFr: Réponse search reçue - " . substr($res, 0, 200));
libxml_use_internal_errors(true); libxml_use_internal_errors(true);
$xml = simplexml_load_string($res); $xml = simplexml_load_string($res);
$xmlErrors = libxml_get_errors();
libxml_clear_errors(); libxml_clear_errors();
if (!$xml || !isset($xml->dvd[0]->id)) return null;
$dvdId = (string)$xml->dvd[0]->id; if (!$xml) {
if (empty($dvdId)) return null; error_log("DVDFr: Impossible de parser le XML search - Erreurs: " . json_encode($xmlErrors));
return null;
}
// 🔥 Meilleure détection de la structure XML
$dvdId = null;
if (isset($xml->dvd) && count($xml->dvd) > 0) {
$dvdId = (string)$xml->dvd[0]->id;
} elseif (isset($xml->resultats) && isset($xml->resultats->dvd)) {
$dvdId = (string)$xml->resultats->dvd[0]->id;
} elseif (isset($xml->results) && count($xml->results) > 0) {
$dvdId = (string)$xml->results[0]->id;
}
if (empty($dvdId)) {
error_log("DVDFr: Aucun ID DVD trouvé dans la réponse search");
error_log("DVDFr: Structure XML: " . json_encode($xml));
return null;
}
error_log("DVDFr: ID DVD trouvé - $dvdId");
// Étape 2 : fiche complète
$ficheUrl = "https://www.dvdfr.com/api/dvd.php?id=" . urlencode($dvdId); $ficheUrl = "https://www.dvdfr.com/api/dvd.php?id=" . urlencode($dvdId);
error_log("DVDFr: Appel API fiche - URL: $ficheUrl");
$ch2 = curl_init($ficheUrl); $ch2 = curl_init($ficheUrl);
curl_setopt_array($ch2, [ curl_setopt_array($ch2, [
CURLOPT_RETURNTRANSFER => true, CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 5, CURLOPT_TIMEOUT => 8,
CURLOPT_CONNECTTIMEOUT => 3, CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_USERAGENT => $ua, CURLOPT_USERAGENT => $ua,
CURLOPT_FOLLOWLOCATION => true, CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTPHEADER => ['Accept: application/xml, text/xml, */*'], CURLOPT_HTTPHEADER => ['Accept: application/xml, text/xml, */*'],
]); ]);
$res2 = curl_exec($ch2); $res2 = curl_exec($ch2);
$httpCode2 = curl_getinfo($ch2, CURLINFO_HTTP_CODE);
curl_close($ch2); curl_close($ch2);
if (!$res2) return null;
if (!$res2) {
error_log("DVDFr: Échec de la requête fiche - HTTP $httpCode2");
return null;
}
error_log("DVDFr: Réponse fiche reçue - " . substr($res2, 0, 300));
libxml_use_internal_errors(true); libxml_use_internal_errors(true);
$fiche = simplexml_load_string($res2); $fiche = simplexml_load_string($res2);
$ficheErrors = libxml_get_errors();
libxml_clear_errors(); libxml_clear_errors();
if (!$fiche || !isset($fiche->dvd[0])) return null;
$dvd = $fiche->dvd[0]; if (!$fiche) {
error_log("DVDFr: Impossible de parser le XML fiche - Erreurs: " . json_encode($ficheErrors));
return null;
}
// 🔥 Meilleure détection de la fiche DVD
$dvd = null;
if (isset($fiche->dvd) && count($fiche->dvd) > 0) {
$dvd = $fiche->dvd[0];
} elseif (isset($fiche->fiche)) {
$dvd = $fiche->fiche;
} elseif (isset($fiche->product)) {
$dvd = $fiche->product;
}
if (!$dvd) {
error_log("DVDFr: Structure de fiche non reconnue");
error_log("DVDFr: Structure XML fiche: " . json_encode($fiche));
return null;
}
// Extraction des données avec fallbacks
$poster = ''; $poster = '';
if (isset($dvd->cover)) $poster = (string)$dvd->cover; if (isset($dvd->cover)) {
if (empty($poster) && isset($dvd->covers->cover[0])) $poster = (string)$dvd->covers->cover[0]; $poster = (string)$dvd->cover;
} elseif (isset($dvd->covers) && isset($dvd->covers->cover)) {
$poster = (string)$dvd->covers->cover[0];
} elseif (isset($dvd->image)) {
$poster = (string)$dvd->image;
}
$result = [ $result = [
'poster' => $poster, 'poster' => $poster,
@@ -169,6 +238,8 @@ function fetchDVDFr($ean, $pdo) {
'discs' => isset($dvd->nbdisques) ? (string)$dvd->nbdisques : '', 'discs' => isset($dvd->nbdisques) ? (string)$dvd->nbdisques : '',
]; ];
error_log("DVDFr: Données extraites - " . json_encode($result));
return (!empty($result['poster']) || !empty($result['publisher'])) ? $result : null; return (!empty($result['poster']) || !empty($result['publisher'])) ? $result : null;
} }