Actualiser api.php

This commit is contained in:
2026-06-22 08:28:50 +02:00
parent 1f23550150
commit e28bd8cefb
+38 -11
View File
@@ -315,14 +315,31 @@ switch ($action) {
echo json_encode(["success" => true]);
break;
case 'get_config_keys':
checkAuth($pdo);
$keys = ['tmdb_api_key', 'ean_search_key', 'barcode_lookup_key'];
$result = [];
foreach ($keys as $k) {
$val = getConfigValue($pdo, $k);
$result[$k] = $val ? '••••••••' : ''; // Masqué pour sécurité
}
echo json_encode($result);
break;
case 'save_config':
checkAuth($pdo);
$keyName = $data['key_name'] ?? ''; $keyValue = $data['key_value'] ?? '';
if ($keyName === 'tmdb_api_key' && !empty($keyValue)) {
$keyName = $data['key_name'] ?? '';
$keyValue = $data['key_value'] ?? '';
$allowedKeys = ['tmdb_api_key', 'ean_search_key', 'barcode_lookup_key'];
if (in_array($keyName, $allowedKeys) && !empty($keyValue)) {
$stmt = $pdo->prepare("REPLACE INTO config (key_name, key_value) VALUES (?, ?)");
$stmt->execute([$keyName, encryptData($keyValue)]);
echo json_encode(["success" => true]);
} else { http_response_code(400); echo json_encode(["error" => "Données invalides."]); }
} else {
http_response_code(400);
echo json_encode(["error" => "Données invalides."]);
}
break;
case 'get_films':
@@ -407,16 +424,27 @@ switch ($action) {
$poster = $rowData['poster'] ?? $rowData['Poster'] ?? $rowData['image'] ?? '';
// 1. UPCitemdb (par code-barres) - le plus fiable pour DVD/Blu-ray
// ── RECHERCHE D'AFFICHE ADAPTÉE SELON LE TYPE ──
if ($type === 'videotheque') {
// 1. Recherche prioritaire par EAN/UPC (UPCitemDB, EAN-Search, Barcode Lookup)
if (empty($poster) && !empty($ean)) {
$upcData = fetchUPCitemdb($ean, $pdo);
if ($upcData && !empty($upcData['poster'])) {
$poster = $upcData['poster'];
$eanPoster = fetchPosterByEAN($ean, $pdo);
if ($eanPoster) {
$poster = $eanPoster;
$stats['upc_hits']++;
}
}
// 2. MoviePosterDB (par titre) - spécialisé jaquettes physiques
// 2. Fallback MoviePosterDB (par titre)
if (empty($poster)) {
$mpdbData = fetchMoviePosterDB($title, $year, $pdo);
if ($mpdbData && !empty($mpdbData['poster'])) {
$poster = $mpdbData['poster'];
$stats['mpdb_hits']++;
}
}
// ❌ TMDB SUPPRIMÉ POUR LA VIDÉOTHÈQUE (Conformément à la demande)
} else {
// Pour les CRITIQUES, on garde l'ancien comportement (TMDB pour réalisateur/streaming/affiche)
if (empty($poster)) {
$mpdbData = fetchMoviePosterDB($title, $year, $pdo);
if ($mpdbData && !empty($mpdbData['poster'])) {
@@ -424,8 +452,6 @@ switch ($action) {
$stats['mpdb_hits']++;
}
}
// 3. TMDB (fallback) - affiches de films
if (empty($poster) && $tmdbApiKey) {
$tmdbData = fetchTMDB($title, $year, $tmdbApiKey, $pdo);
if ($tmdbData) {
@@ -436,6 +462,7 @@ switch ($action) {
}
}
}
}
if (empty($poster)) $stats['no_image']++;