diff --git a/api.php b/api.php index aa61d56..30b2735 100644 --- a/api.php +++ b/api.php @@ -560,19 +560,40 @@ switch ($action) { } break; - case 'debug_dvdcover': + case 'debug_dvdcover': $title = $_GET['title'] ?? ''; - $year = $_GET['year'] ?? ''; + $year = $_GET['year'] ?? ''; $format = $_GET['format'] ?? 'Blu-ray'; - if (!$title) { echo json_encode(['error' => 'Titre manquant']); exit; } + + $ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'; + $searchUrl = "https://www.dvdcover.com/?s=" . urlencode(cleanTitle($title)); - $result = ['title' => $title, 'year' => $year, 'format' => $format]; - $data = fetchDVDCover($title, $year, $format); - $result['data'] = $data; - $result['status'] = $data ? 'OK' : 'AUCUN_RÉSULTAT'; + $html = httpGet($searchUrl, 10, $ua); - echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); + $diag = [ + 'url' => $searchUrl, + 'html_length' => $html ? strlen($html) : 0, + 'html_snippet' => $html ? substr(strip_tags($html), 0, 500) : 'VIDE/ERREUR', + 'cloudflare' => ($html && strpos($html, 'cloudflare') !== false) ? true : false, + 'captcha' => ($html && strpos($html, 'captcha') !== false) ? true : false, + ]; + + // Cherche les articles si HTML reçu + if ($html) { + $dom = new DOMDocument(); + @$dom->loadHTML($html); + $xpath = new DOMXPath($dom); + $links = $xpath->query('//article[contains(@class,"post")]//a/@href'); + $diag['articles_found'] = $links->length; + + // Essai avec d'autres sélecteurs courants + $diag['alt1_h2_links'] = $xpath->query('//h2//a/@href')->length; + $diag['alt2_figure_imgs'] = $xpath->query('//figure//img/@src')->length; + $diag['alt3_any_article'] = $xpath->query('//article')->length; + } + + echo json_encode($diag, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); exit; break; }