diff --git a/api.php b/api.php index eb2cc8b..dfe45e9 100644 --- a/api.php +++ b/api.php @@ -583,7 +583,6 @@ function fetchFromBlurayCom($ean) { return $empty; } -// ── CORRECTION : Utilisation de removeAccentsForUrl pour MovieCovers ── function fetchFromMovieCovers($title, $year = '') { $empty = [ 'title' => '', 'year' => '', 'director' => '', 'actors' => '', @@ -593,7 +592,7 @@ function fetchFromMovieCovers($title, $year = '') { ]; if (empty($title)) return $empty; - // Nettoyage robuste du titre pour l'URL + // ✅ CORRECTION : Utiliser removeAccentsForUrl $cleanTitle = removeAccentsForUrl($title); $urlTitle = strtoupper(str_replace(' ', '+', $cleanTitle)); $url = "https://moviecovers.com/film/titre_{$urlTitle}.html"; @@ -848,7 +847,53 @@ case 'save_config': if (!empty($ids)) { $placeholders = implode(',', array_fill(0, count($ids), '?')); $stmt = $pdo->prepare("DELETE FROM $table WHERE id IN ($placeholders)"); $stmt->execute($ids); echo json_encode(["success" => true]); } else { http_response_code(400); echo json_encode(["success" => false, "error" => "Aucun élément sélectionné."]); } break; - + + // ── NOUVELLE ACTION : Recherche par EAN ── +case 'search_by_ean': + checkAuth($pdo); + $ean = $_GET['ean'] ?? ''; + $ean = preg_replace('/[^0-9]/', '', $ean); + + if (strlen($ean) < 8) { + echo json_encode(["success" => false, "error" => "EAN invalide"]); + break; + } + + // 1. Blu-ray.com + $blurayData = fetchFromBlurayCom($ean); + + // 2. MovieCovers pour l'affiche HD + $mcData = []; + if (!empty($blurayData['title'])) { + $mcData = fetchFromMovieCovers($blurayData['title'], $blurayData['year'] ?? ''); + } + + // 3. Fallback TMDB + $tmdbData = []; + $title = !empty($blurayData['title']) ? $blurayData['title'] : ''; + if ($title) { + $tmdbData = fetchTmdbPosterAndSynopsis($title, $blurayData['year'] ?? '', $pdo); + } + + // Fusion des données + $result = [ + 'success' => true, + 'title' => $blurayData['title'] ?? '', + 'year' => $blurayData['year'] ?? ($tmdbData['year'] ?? ''), + 'director' => $mcData['director'] ?? ($blurayData['director'] ?? ($tmdbData['director'] ?? '')), + 'poster' => $mcData['poster'] ?? ($blurayData['poster'] ?? ($tmdbData['poster'] ?? '')), + 'format' => $blurayData['format'] ?? 'Blu-ray', + 'length' => $blurayData['length'] ?? ($tmdbData['length'] ?? ''), + 'publisher' => $blurayData['publisher'] ?? '', + 'number_of_discs' => $blurayData['number_of_discs'] ?? 1, + 'aspect_ratio' => $blurayData['aspect_ratio'] ?? '', + 'actors' => $mcData['actors'] ?? ($blurayData['actors'] ?? ($tmdbData['actors'] ?? '')), + 'description' => $mcData['description'] ?? ($blurayData['description'] ?? ($tmdbData['description'] ?? '')) + ]; + + echo json_encode($result); + break; + case 'import_batch': checkAuth($pdo); $data = json_decode(file_get_contents("php://input"), true);