From b153499f84768ec82621d27d7eccae12811f6045 Mon Sep 17 00:00:00 2001 From: Cedric Date: Thu, 25 Jun 2026 13:51:48 +0200 Subject: [PATCH] Actualiser api.php --- api.php | 61 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/api.php b/api.php index 36ff9a8..a3289bf 100644 --- a/api.php +++ b/api.php @@ -645,24 +645,49 @@ switch ($action) { break; 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) { - $html = httpGet($url, 5); - $results[] = [ - 'url' => $url, - 'length' => $html ? strlen($html) : 0, - 'code' => $html ? substr(strip_tags($html), 0, 150) : 'ERREUR' - ]; + $title = urlencode($_GET['title'] ?? 'Matrix'); + $url = "https://www.dvdfr.com/recherche/?q={$title}"; + $html = httpGet($url, 5); + 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); - break; + 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; } ?> \ No newline at end of file