Actualiser api.php

This commit is contained in:
2026-06-25 13:51:48 +02:00
parent b9c98c7534
commit b153499f84
+43 -18
View File
@@ -645,24 +645,49 @@ switch ($action) {
break; break;
case 'test_dvdfr': case 'test_dvdfr':
$title = urlencode($_GET['title'] ?? 'Matrix'); $title = urlencode($_GET['title'] ?? 'Matrix');
$urls = [ $url = "https://www.dvdfr.com/recherche/?q={$title}";
"https://www.dvdfr.com/api/search.php?title={$title}", $html = httpGet($url, 5);
"https://www.dvdfr.com/recherche/films.php?title={$title}", if (!$html) { echo json_encode(['error' => 'ERREUR réseau']); break; }
"https://www.dvdfr.com/dvd/search.php?title={$title}",
"https://dvdfr.com/api/search.php?title={$title}", $dom = new DOMDocument();
"https://www.dvdfr.com/recherche/?q={$title}", @$dom->loadHTML($html);
]; $xpath = new DOMXPath($dom);
$results = [];
foreach ($urls as $url) { // Cherche tous les liens qui ressemblent à des fiches produit
$html = httpGet($url, 5); $allLinks = $xpath->query('//a[contains(@href,"/dvd/") or contains(@href,"/film/") or contains(@href,"/bluray/")]');
$results[] = [ $links = [];
'url' => $url, foreach ($allLinks as $a) {
'length' => $html ? strlen($html) : 0, $href = $a->getAttribute('href');
'code' => $html ? substr(strip_tags($html), 0, 150) : 'ERREUR' $text = trim($a->textContent);
]; if (!in_array($href, array_column($links, 'href')) && !empty($text)) {
$links[] = ['text' => substr($text, 0, 80), 'href' => $href];
} }
echo json_encode($results, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); if (count($links) >= 10) break;
break; }
// Cherche les images produit
$imgs = $xpath->query('//img[contains(@src,"cover") or contains(@src,"dvd") or contains(@src,"blu") or contains(@src,"jaquette")]');
$imgList = [];
foreach ($imgs as $img) {
$imgList[] = $img->getAttribute('src');
if (count($imgList) >= 10) break;
}
// Fallback : toutes les images wp-content ou cdn
if (empty($imgList)) {
$imgs2 = $xpath->query('//img/@src');
foreach ($imgs2 as $img) {
$imgList[] = $img->nodeValue;
if (count($imgList) >= 15) break;
}
}
echo json_encode([
'url' => $url,
'links' => $links,
'imgs' => $imgList
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
break;
} }
?> ?>