Actualiser api.php
This commit is contained in:
@@ -63,13 +63,20 @@ function getTmdbApiKey($pdo) {
|
|||||||
return $row ? decryptData($row['key_value']) : null;
|
return $row ? decryptData($row['key_value']) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function httpGet($url, $timeout = 5) {
|
function httpGet($url, $timeout = 2) { // 🔥 Réduit à 2 secondes par défaut
|
||||||
if (!function_exists('curl_init')) {
|
if (!function_exists('curl_init')) {
|
||||||
$ctx = stream_context_create(['http' => ['timeout' => $timeout, 'user_agent' => 'MonCinema/5.0']]);
|
$ctx = stream_context_create(['http' => ['timeout' => $timeout, 'user_agent' => 'MonCinema/5.0']]);
|
||||||
return @file_get_contents($url, false, $ctx);
|
return @file_get_contents($url, false, $ctx);
|
||||||
}
|
}
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($url);
|
||||||
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => $timeout, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_USERAGENT => 'MonCinema/5.0', CURLOPT_FOLLOWLOCATION => true]);
|
curl_setopt_array($ch, [
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_TIMEOUT => $timeout,
|
||||||
|
CURLOPT_CONNECTTIMEOUT => 2, // 🔥 N'attend pas plus de 2s pour la connexion
|
||||||
|
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);
|
||||||
return $res ?: null;
|
return $res ?: null;
|
||||||
@@ -137,20 +144,21 @@ function fetchUPCitemdb($ean, $pdo) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 1.5 API DVDFr (Uniquement Jaquettes FR) ──
|
function fetchDVDFr($ean, $pdo) {
|
||||||
function fetchDVDFr($ean, $pdo) {
|
if (empty($ean) || strlen($ean) < 8) return null;
|
||||||
if (empty($ean) || strlen($ean) < 8) return null;
|
$cacheKey = 'dvdfr_' . md5($ean);
|
||||||
$cacheKey = 'dvdfr_' . md5($ean); // On revient au cache simple
|
$cached = getCache($pdo, $cacheKey);
|
||||||
|
if ($cached) return $cached;
|
||||||
$cached = getCache($pdo, $cacheKey);
|
|
||||||
if ($cached) return $cached;
|
$url = "https://www.dvdfr.com/api/search.php?gencode=" . urlencode($ean);
|
||||||
|
$res = httpGet($url, 2); // 🔥 Timeout réduit
|
||||||
$url = "https://www.dvdfr.com/api/search.php?gencode=" . urlencode($ean);
|
if (!$res) return null;
|
||||||
$res = httpGet($url, 5);
|
|
||||||
if (!$res) return null;
|
// 🔥 SÉCURISATION : Empêche le crash fatal si DVDfr renvoie du HTML ou une erreur
|
||||||
|
libxml_use_internal_errors(true);
|
||||||
try {
|
$xml = simplexml_load_string($res);
|
||||||
$xml = @simplexml_load_string($res);
|
libxml_clear_errors();
|
||||||
|
|
||||||
if ($xml && isset($xml->dvd) && isset($xml->dvd[0]->cover)) {
|
if ($xml && isset($xml->dvd) && isset($xml->dvd[0]->cover)) {
|
||||||
$poster = (string)$xml->dvd[0]->cover;
|
$poster = (string)$xml->dvd[0]->cover;
|
||||||
if (!empty($poster)) {
|
if (!empty($poster)) {
|
||||||
@@ -158,11 +166,8 @@ function fetchDVDFr($ean, $pdo) {
|
|||||||
return $poster;
|
return $poster;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── 2. API TMDB (Full Extract avec Synopsis et Acteurs) ──
|
// ── 2. API TMDB (Full Extract avec Synopsis et Acteurs) ──
|
||||||
function fetchTMDBFull($title, $year, $apiKey, $pdo) {
|
function fetchTMDBFull($title, $year, $apiKey, $pdo) {
|
||||||
@@ -392,6 +397,7 @@ switch ($action) {
|
|||||||
// ── IMPORT PAR LOTS CSV (CROISEMENT UPC + TMDB) ──
|
// ── IMPORT PAR LOTS CSV (CROISEMENT UPC + TMDB) ──
|
||||||
case 'import_batch':
|
case 'import_batch':
|
||||||
checkAuth($pdo);
|
checkAuth($pdo);
|
||||||
|
set_time_limit(0); // 🔥 EMPÊCHE PHP DE TUER LE SCRIPT APRÈS 30 SECONDES
|
||||||
$items = $data['items'] ?? [];
|
$items = $data['items'] ?? [];
|
||||||
$type = $data['type'] ?? 'videotheque';
|
$type = $data['type'] ?? 'videotheque';
|
||||||
$tmdbApiKey = getTmdbApiKey($pdo);
|
$tmdbApiKey = getTmdbApiKey($pdo);
|
||||||
|
|||||||
Reference in New Issue
Block a user