Actualiser api.php

This commit is contained in:
2026-06-25 14:04:03 +02:00
parent 757d50dd28
commit fafe3c1d25
+35 -18
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);
$html = httpGet($url, 8);
if (!$html) { echo json_encode(['error' => 'ERREUR réseau']); break; }
// URLs possibles à tester $dom = new DOMDocument();
$urls = [ @$dom->loadHTML($html);
"https://www.covercentury.com/index.php?p=recherche&recherche=" . urlencode($title), $xpath = new DOMXPath($dom);
"https://www.covercentury.com/?s=" . urlencode($title),
"https://www.covercentury.com/search/" . urlencode($title),
"https://www.covercentury.com/index.php?recherche=" . urlencode($title),
];
$results = []; // Tous les liens
foreach ($urls as $url) { $allLinks = $xpath->query('//a');
$html = httpGet($url, 8); $links = [];
$results[] = [ foreach ($allLinks as $a) {
'url' => $url, $href = $a->getAttribute('href');
'length' => $html ? strlen($html) : 0, $text = trim($a->textContent);
'snippet' => $html ? substr(strip_tags($html), 0, 200) : 'ERREUR' 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; break;
} }
?> ?>