Actualiser api.php

This commit is contained in:
2026-06-25 14:04:03 +02:00
parent 757d50dd28
commit fafe3c1d25
+36 -19
View File
@@ -690,28 +690,45 @@ switch ($action) {
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); ], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
break; break;
case 'test_covercentury': case 'test_covercentury':
$title = $_GET['title'] ?? 'Matrix'; $title = $_GET['title'] ?? 'Matrix';
$year = $_GET['year'] ?? ''; $url = "https://www.covercentury.com/index.php?p=recherche&recherche=" . urlencode($title);
// 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),
];
$results = [];
foreach ($urls as $url) {
$html = httpGet($url, 8); $html = httpGet($url, 8);
$results[] = [ if (!$html) { echo json_encode(['error' => 'ERREUR réseau']); break; }
'url' => $url,
'length' => $html ? strlen($html) : 0, $dom = new DOMDocument();
'snippet' => $html ? substr(strip_tags($html), 0, 200) : 'ERREUR' @$dom->loadHTML($html);
]; $xpath = new DOMXPath($dom);
// 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];
} }
echo json_encode($results, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); if (count($links) >= 20) break;
}
// 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; break;
} }
?> ?>