From fcd3d27211283e9320b4c394b222473929dba89d Mon Sep 17 00:00:00 2001 From: Cedric Date: Wed, 1 Jul 2026 13:40:02 +0200 Subject: [PATCH] Actualiser api.php --- api.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/api.php b/api.php index 7a485db..e1cc61b 100644 --- a/api.php +++ b/api.php @@ -889,6 +889,44 @@ case 'search_by_ean': echo json_encode($result); break; +case 'add_item_by_ean': + $data = json_decode(file_get_contents("php://input"), true); + $ean = $data['ean'] ?? ''; + + // Clé API TMDB (Remplacez par la vôtre) + $apiKey = 'VOTRE_CLE_API_TMDB'; + + // 1. Recherche TMDB via EAN + $url = "https://api.themoviedb.org/3/find/" . $ean . "?api_key=$apiKey&external_source=ean_isbn"; + $response = @file_get_contents($url); + $result = json_decode($response, true); + + if (empty($result['movie_results'])) { + echo json_encode(["success" => false, "error" => "EAN non trouvé sur TMDB"]); + exit; + } + + $movie = $result['movie_results'][0]; + $title = $movie['title']; + $year = substr($movie['release_date'], 0, 4); + + // 2. Tenter de récupérer la jaquette physique sur MovieCovers + // (Utilise la fonction que vous avez déjà ajoutée dans api.php) + $poster = fetchAndDownloadMovieCovers($title, $ean); + + // Si MovieCovers échoue, fallback sur TMDB + if (!$poster) { + $poster = "https://image.tmdb.org/t/p/w500" . $movie['poster_path']; + } + + // 3. Insertion + $id = generateStableId('critique', $title, $year); + $stmt = $pdo->prepare("INSERT INTO critiques (id, title, year, poster, streaming) VALUES (?, ?, ?, ?, ?)"); + $stmt->execute([$id, $title, $year, $poster, 'Support physique']); + + echo json_encode(["success" => true]); + break; + case 'import_batch': checkAuth($pdo); $data = json_decode(file_get_contents("php://input"), true);