diff --git a/api.php b/api.php
index a485b5f..bc5a170 100644
--- a/api.php
+++ b/api.php
@@ -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];
- 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('/]+src=["\']([^"\']+\.jpg)["\'][^>]*class=["\'][^"\']*cover[^"\']*["\']/i', $coverHtml, $m)) {
- $result['poster'] = $m[1];
- } elseif (preg_match('/]+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 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;
}
- // Extraire le titre
- if (preg_match('/