Actualiser api.php

This commit is contained in:
2026-06-25 14:05:14 +02:00
parent fafe3c1d25
commit af9201941b
+20 -24
View File
@@ -692,43 +692,39 @@ switch ($action) {
case 'test_covercentury':
$title = $_GET['title'] ?? 'Matrix';
$url = "https://www.covercentury.com/index.php?p=recherche&recherche=" . urlencode($title);
$urls = [
"https://www.covercentury.com/index.php?p=dvdcovers&recherche=" . urlencode($title),
"https://www.covercentury.com/index.php?p=blu-raycovers&recherche=" . urlencode($title),
"https://www.covercentury.com/index.php?p=dvdcovers&q=" . urlencode($title),
"https://www.covercentury.com/index.php?p=dvdcovers&s=" . urlencode($title),
];
$results = [];
foreach ($urls as $url) {
$html = httpGet($url, 8);
if (!$html) { echo json_encode(['error' => 'ERREUR réseau']); break; }
if (!$html) { $results[] = ['url' => $url, 'length' => 0, 'snippet' => 'ERREUR']; continue; }
$dom = new DOMDocument();
@$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];
}
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;
$src = $img->getAttribute('src');
if (strpos($src, 'logo') === false && strpos($src, 'assets') === false) {
$imgs[] = ['src' => $src, 'alt' => $img->getAttribute('alt')];
}
if (count($imgs) >= 10) break;
}
echo json_encode([
$results[] = [
'url' => $url,
'links' => $links,
'length' => strlen($html),
'imgs' => $imgs
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
];
}
echo json_encode($results, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
break;
}
?>