diff --git a/api.php b/api.php index b96d6f1..fe4e63d 100644 --- a/api.php +++ b/api.php @@ -63,13 +63,20 @@ function getTmdbApiKey($pdo) { 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')) { $ctx = stream_context_create(['http' => ['timeout' => $timeout, 'user_agent' => 'MonCinema/5.0']]); return @file_get_contents($url, false, $ctx); } $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); curl_close($ch); return $res ?: null; @@ -137,20 +144,21 @@ function fetchUPCitemdb($ean, $pdo) { return null; } -// ── 1.5 API DVDFr (Uniquement Jaquettes FR) ── -function fetchDVDFr($ean, $pdo) { - if (empty($ean) || strlen($ean) < 8) return null; - $cacheKey = 'dvdfr_' . md5($ean); // On revient au cache simple - - $cached = getCache($pdo, $cacheKey); - if ($cached) return $cached; - - $url = "https://www.dvdfr.com/api/search.php?gencode=" . urlencode($ean); - $res = httpGet($url, 5); - if (!$res) return null; - - try { - $xml = @simplexml_load_string($res); + function fetchDVDFr($ean, $pdo) { + if (empty($ean) || strlen($ean) < 8) return null; + $cacheKey = 'dvdfr_' . md5($ean); + $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 + if (!$res) return null; + + // 🔥 SÉCURISATION : Empêche le crash fatal si DVDfr renvoie du HTML ou une erreur + libxml_use_internal_errors(true); + $xml = simplexml_load_string($res); + libxml_clear_errors(); + if ($xml && isset($xml->dvd) && isset($xml->dvd[0]->cover)) { $poster = (string)$xml->dvd[0]->cover; if (!empty($poster)) { @@ -158,11 +166,8 @@ function fetchDVDFr($ean, $pdo) { return $poster; } } - } catch (\Exception $e) { return null; } - return null; -} // ── 2. API TMDB (Full Extract avec Synopsis et Acteurs) ── function fetchTMDBFull($title, $year, $apiKey, $pdo) { @@ -392,6 +397,7 @@ switch ($action) { // ── IMPORT PAR LOTS CSV (CROISEMENT UPC + TMDB) ── case 'import_batch': checkAuth($pdo); + set_time_limit(0); // 🔥 EMPÊCHE PHP DE TUER LE SCRIPT APRÈS 30 SECONDES $items = $data['items'] ?? []; $type = $data['type'] ?? 'videotheque'; $tmdbApiKey = getTmdbApiKey($pdo);