Actualiser api.php
This commit is contained in:
@@ -63,19 +63,13 @@ function getTmdbApiKey($pdo) {
|
|||||||
return $row ? decryptData($row['key_value']) : null;
|
return $row ? decryptData($row['key_value']) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function httpGet($url, $timeout = 2) { // 🔥 Réduit à 2 secondes par défaut
|
function httpGet($url, $timeout = 5) {
|
||||||
if (!function_exists('curl_init')) {
|
|
||||||
$ctx = stream_context_create(['http' => ['timeout' => $timeout, 'user_agent' => 'MonCinema/5.0']]);
|
|
||||||
return @file_get_contents($url, false, $ctx);
|
|
||||||
}
|
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($url);
|
||||||
curl_setopt_array($ch, [
|
curl_setopt_array($ch, [
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_TIMEOUT => $timeout,
|
CURLOPT_TIMEOUT => $timeout,
|
||||||
CURLOPT_CONNECTTIMEOUT => 2, // 🔥 N'attend pas plus de 2s pour la connexion
|
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
|
||||||
CURLOPT_SSL_VERIFYPEER => false,
|
CURLOPT_SSL_VERIFYPEER => false
|
||||||
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) MonCinema/5.0', // 🔥 User-Agent standard
|
|
||||||
CURLOPT_FOLLOWLOCATION => true
|
|
||||||
]);
|
]);
|
||||||
$res = curl_exec($ch);
|
$res = curl_exec($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
@@ -122,28 +116,29 @@ function extractYear($dateStr) {
|
|||||||
|
|
||||||
|
|
||||||
function fetchDVDFr($ean, $pdo) {
|
function fetchDVDFr($ean, $pdo) {
|
||||||
if (empty($ean)) return null;
|
if (empty($ean) || strlen($ean) < 8) return null;
|
||||||
$cacheKey = 'dvdfr_full_' . md5($ean);
|
$cacheKey = 'dvdfr_full_' . md5($ean);
|
||||||
$cached = getCache($pdo, $cacheKey);
|
$cached = getCache($pdo, $cacheKey);
|
||||||
if ($cached) return $cached;
|
if ($cached) return $cached;
|
||||||
|
|
||||||
// Récupération de la page
|
|
||||||
$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, 10);
|
$res = httpGet($url, 10); // Augmenté à 10s pour éviter les timeouts
|
||||||
if (!$res) return null;
|
if (!$res) {
|
||||||
|
file_put_contents('dvdfr_error.log', "Échec requête pour EAN: $ean");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$xml = @simplexml_load_string($res);
|
$xml = @simplexml_load_string($res);
|
||||||
if ($xml && isset($xml->dvd[0])) {
|
if ($xml && isset($xml->dvd[0])) {
|
||||||
$dvd = $xml->dvd[0];
|
$d = $xml->dvd[0];
|
||||||
|
// On extrait tout ce que DVDfr nous donne
|
||||||
// Extraction des données
|
|
||||||
$data = [
|
$data = [
|
||||||
'poster' => (string)$dvd->cover,
|
'poster' => (string)$d->cover,
|
||||||
'title' => (string)$dvd->title,
|
'format' => (string)$d->media,
|
||||||
'director' => (string)$dvd->directors->director->name,
|
'publisher' => (string)$d->editor,
|
||||||
'actors' => '', // DVDFr API est limitée sur les acteurs, souvent vide
|
'length' => (string)$d->duration,
|
||||||
'year' => (string)$dvd->year
|
'aspect' => (string)$d->ratio
|
||||||
];
|
];
|
||||||
|
|
||||||
setCache($pdo, $cacheKey, $data, 'dvdfr');
|
setCache($pdo, $cacheKey, $data, 'dvdfr');
|
||||||
@@ -449,16 +444,14 @@ case 'import_batch':
|
|||||||
$poster = $rowData['poster'] ?? '';
|
$poster = $rowData['poster'] ?? '';
|
||||||
$director = '';
|
$director = '';
|
||||||
|
|
||||||
// 1.5 DVDFr : récupération complète des métadonnées via EAN
|
// Remplacez votre bloc de gestion DVDFr actuel par ceci :
|
||||||
$dvdfrData = fetchDVDFr($ean, $pdo);
|
$dvdfrData = fetchDVDFr($ean, $pdo);
|
||||||
if (!empty($dvdfrData)) {
|
if (!empty($dvdfrData)) {
|
||||||
// Récupération de TOUS les champs retournés par DVDfr
|
if (empty($poster) && !empty($dvdfrData['poster'])) $poster = $dvdfrData['poster'];
|
||||||
if (!empty($dvdfrData['poster'])) $poster = $dvdfrData['poster'];
|
if (empty($format) && !empty($dvdfrData['format'])) $format = $dvdfrData['format'];
|
||||||
if (!empty($dvdfrData['publisher'])) $publisher = $dvdfrData['publisher'];
|
if (empty($publisher) && !empty($dvdfrData['publisher'])) $publisher = $dvdfrData['publisher'];
|
||||||
if (!empty($dvdfrData['format'])) $format = $dvdfrData['format'];
|
if (empty($length) && !empty($dvdfrData['length'])) $length = $dvdfrData['length'];
|
||||||
if (!empty($dvdfrData['length'])) $length = $dvdfrData['length'];
|
if (empty($aspect) && !empty($dvdfrData['aspect'])) $aspect = $dvdfrData['aspect'];
|
||||||
if (!empty($dvdfrData['aspect'])) $aspect = $dvdfrData['aspect'];
|
|
||||||
if (!empty($dvdfrData['discs'])) $discs = (int)$dvdfrData['discs'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. TMDB (Données Officielles & Synopsis)
|
// 2. TMDB (Données Officielles & Synopsis)
|
||||||
|
|||||||
Reference in New Issue
Block a user