diff --git a/api.php b/api.php
index 8516fce..a485b5f 100644
--- a/api.php
+++ b/api.php
@@ -25,8 +25,6 @@ try {
$pdo->exec("CREATE TABLE IF NOT EXISTS videotheque (id BIGINT PRIMARY KEY, title VARCHAR(255) NOT NULL, year VARCHAR(10), director VARCHAR(255), poster TEXT, format VARCHAR(50), length VARCHAR(50), publisher VARCHAR(255), ean_isbn13 VARCHAR(50), number_of_discs INT DEFAULT 1, aspect_ratio VARCHAR(50), description TEXT, actors TEXT)");
try { $pdo->exec("ALTER TABLE videotheque ADD COLUMN actors TEXT AFTER description"); } catch (\Exception $e) {}
- try { $pdo->exec("DROP TABLE IF EXISTS cache_api"); } catch (\Exception $e) {}
-
} catch (\PDOException $e) { echo json_encode(["error" => "Erreur BDD : " . $e->getMessage()]); exit; }
// ── FONCTIONS UTILITAIRES ──
@@ -117,33 +115,44 @@ function extractYear($dateStr) {
return '';
}
-// ── CoverCentury.com (jaquettes HD pour vidéothèque) ──
-function fetchCoverCentury($title, $year = '', $format = 'bluray') {
+// ── DVDcover.com (version française) ──
+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 CoverCentury
+ // Mapping des formats pour DVDcover
$formatMap = [
- '4k ultra hd' => '4k',
- '4k' => '4k',
- 'blu-ray' => 'bluray',
- 'bluray' => 'bluray',
+ '4k ultra hd' => '4k-ultra-hd',
+ '4k' => '4k-ultra-hd',
+ 'blu-ray' => 'blu-ray',
+ 'bluray' => 'blu-ray',
'dvd' => 'dvd',
];
- $ccFormat = $formatMap[strtolower($format)] ?? 'bluray';
+ $dcFormat = $formatMap[strtolower($format)] ?? 'blu-ray';
- // URL de recherche CoverCentury
- $searchUrl = "https://www.covercentury.com/search?q=" . urlencode($cleanTitle);
+ // Construction de l'URL de recherche
+ // DVDcover utilise des URLs comme : https://www.dvdcover.com/search/TITLE/year/FORMAT
+ $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 . ")";
+ $searchUrl .= "/{$year}";
}
$html = httpGet($searchUrl, 8, $ua);
+
+ // Fallback : essayer sans l'année
if (!$html) {
- error_log("CoverCentury: Échec recherche pour '$title'");
+ $searchUrl = "https://www.dvdcover.com/{$dcFormat}/search/{$searchPath}";
+ $html = httpGet($searchUrl, 8, $ua);
+ }
+
+ if (!$html) {
+ error_log("DVDCover: Échec recherche pour '$title' sur $searchUrl");
return null;
}
@@ -153,42 +162,44 @@ function fetchCoverCentury($title, $year = '', $format = 'bluray') {
'format' => $format,
];
- // Extraction des liens d'images - CoverCentury utilise des structures spécifiques
+ // DVDcover structure les covers dans des divs spécifiques
// Chercher les liens vers les pages de covers
- preg_match_all('/href=["\']([^"\']*\/cover\/[^"\']+)["\']/i', $html, $coverLinks);
+ preg_match_all('/href=["\']([^"\']*\/covers?\/[^"\']+)["\']/i', $html, $coverLinks);
if (!empty($coverLinks[1])) {
- // Prendre le premier résultat pertinent
+ // Prendre le premier résultat
$coverPage = $coverLinks[1][0];
if (strpos($coverPage, 'http') !== 0) {
- $coverPage = 'https://www.covercentury.com' . $coverPage;
+ $coverPage = 'https://www.dvdcover.com' . $coverPage;
}
- // Récupérer la page du cover pour avoir l'image en haute qualité
+ // Récupérer la page du cover
$coverHtml = httpGet($coverPage, 8, $ua);
if ($coverHtml) {
- // Chercher l'image principale en haute résolution
- if (preg_match('/]+src=["\']([^"\']+\.jpg)["\'][^>]*class=["\'][^"\']*main[^"\']*["\']/i', $coverHtml, $m)) {
+ // 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\/[^"\']+\.jpg)["\']/i', $coverHtml, $m)) {
+ } elseif (preg_match('/href=["\']([^"\']*\/images\/covers?\/[^"\']+\.jpg)["\']/i', $coverHtml, $m)) {
$result['poster'] = $m[1];
}
// Extraire le titre
- if (preg_match('/