Actualiser api.php
This commit is contained in:
@@ -646,23 +646,48 @@ switch ($action) {
|
|||||||
|
|
||||||
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}",
|
|
||||||
"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);
|
$html = httpGet($url, 5);
|
||||||
$results[] = [
|
if (!$html) { echo json_encode(['error' => 'ERREUR réseau']); break; }
|
||||||
'url' => $url,
|
|
||||||
'length' => $html ? strlen($html) : 0,
|
$dom = new DOMDocument();
|
||||||
'code' => $html ? substr(strip_tags($html), 0, 150) : 'ERREUR'
|
@$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;
|
break;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user