From fafe3c1d251e43b483a0881527ff553ee63bf29d Mon Sep 17 00:00:00 2001 From: Cedric Date: Thu, 25 Jun 2026 14:04:03 +0200 Subject: [PATCH] Actualiser api.php --- api.php | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/api.php b/api.php index 3721687..543b5a0 100644 --- a/api.php +++ b/api.php @@ -690,28 +690,45 @@ switch ($action) { ], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); break; - case 'test_covercentury': +case 'test_covercentury': $title = $_GET['title'] ?? 'Matrix'; - $year = $_GET['year'] ?? ''; + $url = "https://www.covercentury.com/index.php?p=recherche&recherche=" . urlencode($title); + $html = httpGet($url, 8); + if (!$html) { echo json_encode(['error' => 'ERREUR réseau']); break; } - // URLs possibles à tester - $urls = [ - "https://www.covercentury.com/index.php?p=recherche&recherche=" . urlencode($title), - "https://www.covercentury.com/?s=" . urlencode($title), - "https://www.covercentury.com/search/" . urlencode($title), - "https://www.covercentury.com/index.php?recherche=" . urlencode($title), - ]; + $dom = new DOMDocument(); + @$dom->loadHTML($html); + $xpath = new DOMXPath($dom); - $results = []; - foreach ($urls as $url) { - $html = httpGet($url, 8); - $results[] = [ - 'url' => $url, - 'length' => $html ? strlen($html) : 0, - 'snippet' => $html ? substr(strip_tags($html), 0, 200) : 'ERREUR' - ]; + // Tous les liens + $allLinks = $xpath->query('//a'); + $links = []; + foreach ($allLinks as $a) { + $href = $a->getAttribute('href'); + $text = trim($a->textContent); + if (!empty($href) && !empty($text) && $href !== '#') { + $links[] = ['text' => substr($text, 0, 80), 'href' => $href]; + } + if (count($links) >= 20) break; } - echo json_encode($results, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); + + // Toutes les images + $allImgs = $xpath->query('//img'); + $imgs = []; + foreach ($allImgs as $img) { + $imgs[] = [ + 'src' => $img->getAttribute('src'), + 'alt' => $img->getAttribute('alt'), + 'class' => $img->getAttribute('class'), + ]; + if (count($imgs) >= 20) break; + } + + echo json_encode([ + 'url' => $url, + 'links' => $links, + 'imgs' => $imgs + ], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); break; } ?> \ No newline at end of file