Actualiser api.php

This commit is contained in:
2026-06-25 13:51:48 +02:00
parent b9c98c7534
commit b153499f84
+40 -15
View File
@@ -646,23 +646,48 @@ switch ($action) {
case 'test_dvdfr':
$title = urlencode($_GET['title'] ?? 'Matrix');
$urls = [
"https://www.dvdfr.com/api/search.php?title={$title}",
"https://www.dvdfr.com/recherche/films.php?title={$title}",
"https://www.dvdfr.com/dvd/search.php?title={$title}",
"https://dvdfr.com/api/search.php?title={$title}",
"https://www.dvdfr.com/recherche/?q={$title}",
];
$results = [];
foreach ($urls as $url) {
$url = "https://www.dvdfr.com/recherche/?q={$title}";
$html = httpGet($url, 5);
$results[] = [
'url' => $url,
'length' => $html ? strlen($html) : 0,
'code' => $html ? substr(strip_tags($html), 0, 150) : 'ERREUR'
];
if (!$html) { echo json_encode(['error' => 'ERREUR réseau']); break; }
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
// Cherche tous les liens qui ressemblent à des fiches produit
$allLinks = $xpath->query('//a[contains(@href,"/dvd/") or contains(@href,"/film/") or contains(@href,"/bluray/")]');
$links = [];
foreach ($allLinks as $a) {
$href = $a->getAttribute('href');
$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;
}
// 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;
}
?>