Actualiser api.php
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user