Actualiser api.php
This commit is contained in:
@@ -115,19 +115,33 @@ function extractYear($dateStr) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── NOUVEAU SCRAPER : DVDFr (Refonte 2026) ──
|
// ── NOUVEAU SCRAPER : DVDFr (Version corrigée avec débogage) ──
|
||||||
function fetchDVDFrCover($title, $year = '', $format = 'bluray') {
|
function fetchDVDFrCover($title, $year = '', $format = 'bluray') {
|
||||||
if (empty($title)) return null;
|
if (empty($title)) return null;
|
||||||
|
|
||||||
$ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
|
$ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
|
||||||
$cleanTitle = cleanTitle($title);
|
$cleanTitle = cleanTitle($title);
|
||||||
|
|
||||||
// 1. Simuler une recherche sur le nouveau site DVDFr
|
// Essayer différentes URLs de recherche
|
||||||
$searchUrl = "https://www.dvdfr.com/search/search.php?titre=" . urlencode($cleanTitle);
|
$searchUrls = [
|
||||||
|
"https://www.dvdfr.com/search?q=" . urlencode($cleanTitle),
|
||||||
|
"https://www.dvdfr.com/dvd/recherche.html?search=" . urlencode($cleanTitle),
|
||||||
|
"https://www.dvdfr.com/catalogue/recherche?query=" . urlencode($cleanTitle),
|
||||||
|
];
|
||||||
|
|
||||||
|
$html = null;
|
||||||
|
$usedUrl = '';
|
||||||
|
|
||||||
|
foreach ($searchUrls as $url) {
|
||||||
|
$html = httpGet($url, 10, $ua);
|
||||||
|
if ($html && strlen($html) > 1000) {
|
||||||
|
$usedUrl = $url;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$html = httpGet($searchUrl, 8, $ua);
|
|
||||||
if (!$html) {
|
if (!$html) {
|
||||||
error_log("DVDFr Scraper: Échec de connexion pour '$title'");
|
error_log("DVDFr: Impossible de récupérer la page de recherche pour '$title'");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,66 +149,104 @@ function fetchDVDFrCover($title, $year = '', $format = 'bluray') {
|
|||||||
'poster' => '',
|
'poster' => '',
|
||||||
'title' => '',
|
'title' => '',
|
||||||
'format' => $format,
|
'format' => $format,
|
||||||
|
'debug_url' => $usedUrl,
|
||||||
];
|
];
|
||||||
|
|
||||||
// 2. Parser le HTML de la recherche
|
// Méthode 1 : Chercher les liens vers les fiches produits (pattern /dvd/f ou /dvd/ suivi de chiffres)
|
||||||
$dom = new DOMDocument();
|
|
||||||
@$dom->loadHTML($html);
|
|
||||||
$xpath = new DOMXPath($dom);
|
|
||||||
|
|
||||||
// 3. Chercher le lien vers la fiche de l'édition (les liens DVDFr commencent souvent par /dvd/f)
|
|
||||||
$links = $xpath->query('//a[contains(@href, "/dvd/f")]');
|
|
||||||
$ficheUrl = '';
|
$ficheUrl = '';
|
||||||
|
if (preg_match('/href=["\']([^"\']*\/dvd\/f?\d+[^"\']*\.html)["\']/i', $html, $matches)) {
|
||||||
if ($links->length > 0) {
|
$ficheUrl = $matches[1];
|
||||||
foreach ($links as $link) {
|
if (strpos($ficheUrl, 'http') !== 0) {
|
||||||
$href = $link->getAttribute('href');
|
$ficheUrl = 'https://www.dvdfr.com' . $ficheUrl;
|
||||||
$ficheUrl = strpos($href, 'http') === 0 ? $href : "https://www.dvdfr.com" . (strpos($href, '/') === 0 ? '' : '/') . ltrim($href, '/');
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si la recherche nous a redirigé directement sur la fiche du film (1 seul résultat)
|
// Méthode 2 : Chercher dans les données JSON-LD ou scripts
|
||||||
if (empty($ficheUrl) && stripos($html, 'jaquette') !== false) {
|
if (empty($ficheUrl) && preg_match('/"url"\s*:\s*"([^"]*\/dvd\/[^"]+)"/i', $html, $matches)) {
|
||||||
$ficheHtml = $html;
|
$ficheUrl = $matches[1];
|
||||||
} elseif (!empty($ficheUrl)) {
|
if (strpos($ficheUrl, 'http') !== 0) {
|
||||||
// Sinon on charge la page de la fiche
|
$ficheUrl = 'https://www.dvdfr.com' . $ficheUrl;
|
||||||
$ficheHtml = httpGet($ficheUrl, 8, $ua);
|
}
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Extraire la jaquette de la fiche produit
|
if (!empty($ficheUrl)) {
|
||||||
if (!empty($ficheHtml)) {
|
error_log("DVDFr: Fiche trouvée - $ficheUrl");
|
||||||
$domFiche = new DOMDocument();
|
$ficheHtml = httpGet($ficheUrl, 10, $ua);
|
||||||
@$domFiche->loadHTML($ficheHtml);
|
|
||||||
$xpathFiche = new DOMXPath($domFiche);
|
|
||||||
|
|
||||||
// Récupération du titre exact de l'édition
|
if ($ficheHtml) {
|
||||||
$titles = $xpathFiche->query('//h1');
|
// Extraire le titre
|
||||||
if ($titles->length > 0) {
|
if (preg_match('/<h1[^>]*>([^<]+)<\/h1>/i', $ficheHtml, $titleMatch)) {
|
||||||
$result['title'] = trim(strip_tags($titles->item(0)->nodeValue));
|
$result['title'] = trim(strip_tags($titleMatch[1]));
|
||||||
|
} elseif (preg_match('/<title[^>]*>([^<]+)<\/title>/i', $ficheHtml, $titleMatch)) {
|
||||||
|
$result['title'] = trim(strip_tags($titleMatch[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// On cherche une image qui contient cover, jaquette, ou dans le répertoire des éditions
|
// Chercher les images de jaquettes
|
||||||
$images = $xpathFiche->query('//img');
|
// Pattern 1 : Images dans /images/dvd/ ou /covers/
|
||||||
foreach ($images as $img) {
|
if (preg_match_all('/src=["\']([^"\']*(?:\/images\/dvd\/|\/covers\/|cover|jaquette)[^"\']*\.(?:jpg|jpeg|png|webp))["\']/i', $ficheHtml, $imgMatches)) {
|
||||||
$src = $img->getAttribute('src');
|
foreach ($imgMatches[1] as $img) {
|
||||||
if (preg_match('/cover|jaquette|front|\/images\/dvd\//i', $src)) {
|
if (strpos($img, 'logo') === false &&
|
||||||
// On exclut les miniatures techniques ou de design
|
strpos($img, 'icon') === false &&
|
||||||
if (strpos($src, 'logo') === false && strpos($src, 'icon') === false && strpos($src, 'stars') === false) {
|
strpos($img, 'stars') === false &&
|
||||||
|
strpos($img, 'bg-') === false) {
|
||||||
|
|
||||||
$imgUrl = strpos($src, 'http') === 0 ? $src : "https://www.dvdfr.com" . (strpos($src, '/') === 0 ? '' : '/') . ltrim($src, '/');
|
$imgUrl = strpos($img, 'http') === 0 ? $img : 'https://www.dvdfr.com' . (strpos($img, '/') === 0 ? '' : '/') . ltrim($img, '/');
|
||||||
|
|
||||||
// Transformation de l'URL pour choper la haute résolution (retirer le "small" ou "medium")
|
// Supprimer les suffixes de taille pour avoir la HD
|
||||||
$imgUrl = preg_replace('/_s\./i', '.', $imgUrl);
|
$imgUrl = preg_replace('/[_-](?:small|medium|thumb|mini|s|m|t)\./i', '.', $imgUrl);
|
||||||
$imgUrl = preg_replace('/_m\./i', '.', $imgUrl);
|
|
||||||
|
|
||||||
$result['poster'] = $imgUrl;
|
$result['poster'] = $imgUrl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pattern 2 : Meta Open Graph
|
||||||
|
if (empty($result['poster']) && preg_match('/<meta[^>]+property=["\']og:image["\'][^>]+content=["\']([^"\']+)["\']/i', $ficheHtml, $ogMatch)) {
|
||||||
|
$result['poster'] = $ogMatch[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pattern 3 : Chercher toutes les images et filtrer
|
||||||
|
if (empty($result['poster'])) {
|
||||||
|
preg_match_all('/<img[^>]+src=["\']([^"\']+\.(?:jpg|jpeg|png|webp))["\'][^>]*>/i', $ficheHtml, $allImages);
|
||||||
|
foreach ($allImages[1] as $img) {
|
||||||
|
$imgLower = strtolower($img);
|
||||||
|
if (strpos($imgLower, 'dvdfr.com') !== false &&
|
||||||
|
strpos($imgLower, 'logo') === false &&
|
||||||
|
strpos($imgLower, 'icon') === false &&
|
||||||
|
strpos($imgLower, 'banner') === false &&
|
||||||
|
strpos($imgLower, 'bg') === false &&
|
||||||
|
strpos($imgLower, 'button') === false &&
|
||||||
|
strpos($imgLower, 'social') === false) {
|
||||||
|
|
||||||
|
$imgUrl = strpos($img, 'http') === 0 ? $img : 'https://www.dvdfr.com' . (strpos($img, '/') === 0 ? '' : '/') . ltrim($img, '/');
|
||||||
|
$imgUrl = preg_replace('/[_-](?:small|medium|thumb|mini|s|m|t)\./i', '.', $imgUrl);
|
||||||
|
|
||||||
|
$result['poster'] = $imgUrl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback : chercher directement dans la page de recherche
|
||||||
|
if (empty($result['poster'])) {
|
||||||
|
preg_match_all('/src=["\']([^"\']+\.(?:jpg|jpeg|png|webp))["\']/i', $html, $searchImages);
|
||||||
|
foreach ($searchImages[1] as $img) {
|
||||||
|
$imgLower = strtolower($img);
|
||||||
|
if (strpos($imgLower, 'dvdfr.com') !== false &&
|
||||||
|
(strpos($imgLower, 'dvd') !== false || strpos($imgLower, 'cover') !== false) &&
|
||||||
|
strpos($imgLower, 'logo') === false &&
|
||||||
|
strpos($imgLower, 'icon') === false) {
|
||||||
|
|
||||||
|
$imgUrl = strpos($img, 'http') === 0 ? $img : 'https://www.dvdfr.com' . (strpos($img, '/') === 0 ? '' : '/') . ltrim($img, '/');
|
||||||
|
$imgUrl = preg_replace('/[_-](?:small|medium|thumb|mini|s|m|t)\./i', '.', $imgUrl);
|
||||||
|
|
||||||
|
$result['poster'] = $imgUrl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (!empty($result['poster'])) ? $result : null;
|
return (!empty($result['poster'])) ? $result : null;
|
||||||
|
|||||||
Reference in New Issue
Block a user