Actualiser api.php
This commit is contained in:
@@ -315,14 +315,31 @@ switch ($action) {
|
|||||||
echo json_encode(["success" => true]);
|
echo json_encode(["success" => true]);
|
||||||
break;
|
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':
|
case 'save_config':
|
||||||
checkAuth($pdo);
|
checkAuth($pdo);
|
||||||
$keyName = $data['key_name'] ?? ''; $keyValue = $data['key_value'] ?? '';
|
$keyName = $data['key_name'] ?? '';
|
||||||
if ($keyName === 'tmdb_api_key' && !empty($keyValue)) {
|
$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 = $pdo->prepare("REPLACE INTO config (key_name, key_value) VALUES (?, ?)");
|
||||||
$stmt->execute([$keyName, encryptData($keyValue)]);
|
$stmt->execute([$keyName, encryptData($keyValue)]);
|
||||||
echo json_encode(["success" => true]);
|
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;
|
break;
|
||||||
|
|
||||||
case 'get_films':
|
case 'get_films':
|
||||||
@@ -407,16 +424,27 @@ switch ($action) {
|
|||||||
|
|
||||||
$poster = $rowData['poster'] ?? $rowData['Poster'] ?? $rowData['image'] ?? '';
|
$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)) {
|
if (empty($poster) && !empty($ean)) {
|
||||||
$upcData = fetchUPCitemdb($ean, $pdo);
|
$eanPoster = fetchPosterByEAN($ean, $pdo);
|
||||||
if ($upcData && !empty($upcData['poster'])) {
|
if ($eanPoster) {
|
||||||
$poster = $upcData['poster'];
|
$poster = $eanPoster;
|
||||||
$stats['upc_hits']++;
|
$stats['upc_hits']++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 2. Fallback MoviePosterDB (par titre)
|
||||||
// 2. MoviePosterDB (par titre) - spécialisé jaquettes physiques
|
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)) {
|
if (empty($poster)) {
|
||||||
$mpdbData = fetchMoviePosterDB($title, $year, $pdo);
|
$mpdbData = fetchMoviePosterDB($title, $year, $pdo);
|
||||||
if ($mpdbData && !empty($mpdbData['poster'])) {
|
if ($mpdbData && !empty($mpdbData['poster'])) {
|
||||||
@@ -424,8 +452,6 @@ switch ($action) {
|
|||||||
$stats['mpdb_hits']++;
|
$stats['mpdb_hits']++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. TMDB (fallback) - affiches de films
|
|
||||||
if (empty($poster) && $tmdbApiKey) {
|
if (empty($poster) && $tmdbApiKey) {
|
||||||
$tmdbData = fetchTMDB($title, $year, $tmdbApiKey, $pdo);
|
$tmdbData = fetchTMDB($title, $year, $tmdbApiKey, $pdo);
|
||||||
if ($tmdbData) {
|
if ($tmdbData) {
|
||||||
@@ -436,6 +462,7 @@ switch ($action) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($poster)) $stats['no_image']++;
|
if (empty($poster)) $stats['no_image']++;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user