Actualiser api.php
This commit is contained in:
@@ -115,17 +115,17 @@ function extractYear($dateStr) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// ── DVDcover.com (version française) ──
|
||||
// ── DVDcover.com (version corrigée) ──
|
||||
function fetchDVDCover($title, $year = '', $format = 'bluray') {
|
||||
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';
|
||||
$cleanTitle = cleanTitle($title);
|
||||
|
||||
// Mapping des formats pour DVDcover
|
||||
// Mapping des formats
|
||||
$formatMap = [
|
||||
'4k ultra hd' => '4k-ultra-hd',
|
||||
'4k' => '4k-ultra-hd',
|
||||
'4k ultra hd' => '4k',
|
||||
'4k' => '4k',
|
||||
'blu-ray' => 'blu-ray',
|
||||
'bluray' => 'blu-ray',
|
||||
'dvd' => 'dvd',
|
||||
@@ -133,26 +133,16 @@ function fetchDVDCover($title, $year = '', $format = 'bluray') {
|
||||
|
||||
$dcFormat = $formatMap[strtolower($format)] ?? 'blu-ray';
|
||||
|
||||
// Construction de l'URL de recherche
|
||||
// DVDcover utilise des URLs comme : https://www.dvdcover.com/search/TITLE/year/FORMAT
|
||||
// Construction URL de recherche
|
||||
$searchPath = str_replace(' ', '-', strtolower($cleanTitle));
|
||||
$searchPath = preg_replace('/[^a-z0-9-]/', '', $searchPath);
|
||||
|
||||
$searchUrl = "https://www.dvdcover.com/{$dcFormat}/search/{$searchPath}";
|
||||
if (!empty($year)) {
|
||||
$searchUrl .= "/{$year}";
|
||||
}
|
||||
|
||||
$html = httpGet($searchUrl, 8, $ua);
|
||||
|
||||
// Fallback : essayer sans l'année
|
||||
if (!$html) {
|
||||
$searchUrl = "https://www.dvdcover.com/{$dcFormat}/search/{$searchPath}";
|
||||
$html = httpGet($searchUrl, 8, $ua);
|
||||
}
|
||||
|
||||
if (!$html) {
|
||||
error_log("DVDCover: Échec recherche pour '$title' sur $searchUrl");
|
||||
error_log("DVDCover: Échec recherche pour '$title'");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -162,44 +152,59 @@ function fetchDVDCover($title, $year = '', $format = 'bluray') {
|
||||
'format' => $format,
|
||||
];
|
||||
|
||||
// DVDcover structure les covers dans des divs spécifiques
|
||||
// Chercher les liens vers les pages de covers
|
||||
preg_match_all('/href=["\']([^"\']*\/covers?\/[^"\']+)["\']/i', $html, $coverLinks);
|
||||
|
||||
if (!empty($coverLinks[1])) {
|
||||
// Prendre le premier résultat
|
||||
$coverPage = $coverLinks[1][0];
|
||||
// Chercher les liens vers les pages de covers individuelles
|
||||
// DVDcover utilise des URLs comme /covers/title-year-format/
|
||||
if (preg_match_all('/href=["\']([^"\']*\/covers?\/[^"\']+\/[^"\']+)["\']/i', $html, $coverLinks)) {
|
||||
foreach ($coverLinks[1] as $coverPage) {
|
||||
if (strpos($coverPage, 'http') !== 0) {
|
||||
$coverPage = 'https://www.dvdcover.com' . $coverPage;
|
||||
}
|
||||
|
||||
// Récupérer la page du cover
|
||||
$coverHtml = httpGet($coverPage, 8, $ua);
|
||||
if ($coverHtml) {
|
||||
// Chercher l'image principale (cover front)
|
||||
// DVDcover utilise des classes comme "cover-front", "cover-image"
|
||||
if (preg_match('/<img[^>]+src=["\']([^"\']+\.jpg)["\'][^>]*class=["\'][^"\']*cover[^"\']*["\']/i', $coverHtml, $m)) {
|
||||
$result['poster'] = $m[1];
|
||||
} elseif (preg_match('/<meta[^>]+property=["\']og:image["\'][^>]+content=["\']([^"\']+)["\']/i', $coverHtml, $m)) {
|
||||
$result['poster'] = $m[1];
|
||||
} elseif (preg_match('/href=["\']([^"\']*\/images\/covers?\/[^"\']+\.jpg)["\']/i', $coverHtml, $m)) {
|
||||
$result['poster'] = $m[1];
|
||||
// Chercher les images dans /wp-content/uploads/ (vraies jaquettes)
|
||||
// Ignorer les images de thème (/wp-content/themes/)
|
||||
if (preg_match_all('/<img[^>]+src=["\']([^"\']*\/wp-content\/uploads\/[^"\']+\.jpg)["\'][^>]*>/i', $coverHtml, $imgMatches)) {
|
||||
foreach ($imgMatches[1] as $img) {
|
||||
// Filtrer pour ne garder que les images de covers (pas les logos, etc.)
|
||||
if (strpos($img, '/covers/') !== false ||
|
||||
strpos($img, '/bluray/') !== false ||
|
||||
strpos($img, '/dvd/') !== false ||
|
||||
strpos($img, '/4k/') !== false) {
|
||||
$result['poster'] = $img;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback : chercher dans les balises meta og:image
|
||||
if (empty($result['poster']) && preg_match('/<meta[^>]+property=["\']og:image["\'][^>]+content=["\']([^"\']+)["\']/i', $coverHtml, $m)) {
|
||||
$ogImage = $m[1];
|
||||
// Vérifier que ce n'est pas une image de thème
|
||||
if (strpos($ogImage, '/wp-content/uploads/') !== false) {
|
||||
$result['poster'] = $ogImage;
|
||||
}
|
||||
}
|
||||
|
||||
// Extraire le titre
|
||||
if (preg_match('/<title[^>]*>([^<]+) - DVDCover/i', $coverHtml, $titleMatch)) {
|
||||
if (empty($result['title']) && preg_match('/<title[^>]*>([^<]+) - DVDCover/i', $coverHtml, $titleMatch)) {
|
||||
$result['title'] = trim($titleMatch[1]);
|
||||
}
|
||||
|
||||
if (!empty($result['poster'])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback : chercher directement dans la page de résultats
|
||||
// Fallback ultime : chercher directement les images uploads dans la page de recherche
|
||||
if (empty($result['poster'])) {
|
||||
// Chercher les images de covers dans les résultats de recherche
|
||||
preg_match_all('/<img[^>]+src=["\']([^"\']+\.jpg)["\'][^>]*>/i', $html, $imgMatches);
|
||||
if (!empty($imgMatches[1])) {
|
||||
if (preg_match_all('/<img[^>]+src=["\']([^"\']*\/wp-content\/uploads\/[^"\']+\.jpg)["\'][^>]*>/i', $html, $imgMatches)) {
|
||||
foreach ($imgMatches[1] as $img) {
|
||||
if (strpos($img, 'dvdcover') !== false || strpos($img, '/covers/') !== false) {
|
||||
if (strpos($img, '/covers/') !== false ||
|
||||
strpos($img, '/bluray/') !== false ||
|
||||
strpos($img, '/dvd/') !== false) {
|
||||
$result['poster'] = $img;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user