From 87fbb8085cdb2f1d8768ecd808ae2833aa3caf19 Mon Sep 17 00:00:00 2001 From: Cedric Date: Fri, 19 Jun 2026 08:39:41 +0200 Subject: [PATCH] Actualiser js/admin.js --- js/admin.js | 63 ----------------------------------------------------- 1 file changed, 63 deletions(-) diff --git a/js/admin.js b/js/admin.js index a2b7960..4f908ce 100644 --- a/js/admin.js +++ b/js/admin.js @@ -328,67 +328,4 @@ async function saveNewPassword() { loadDashboardData(); } } catch (err) { console.error('Erreur mise à jour mot de passe :', err); } -} - -// ── ENRICHISSEMENT TMDB AUTOMATIQUE ── -async function enrichirTMDB() { - const tmdbKey = localStorage.getItem('tmdb_key'); - if (!tmdbKey) { - alert("Veuillez d'abord sauvegarder votre clé TMDB juste au-dessus !"); - return; - } - - // On cherche les films qui n'ont pas d'affiche - const missingFilms = allItems.filter(f => !f.poster || f.poster.trim() === ''); - - if (missingFilms.length === 0) { - alert("Bonne nouvelle : tous vos films ont déjà une affiche !"); - return; - } - - if (!confirm(`${missingFilms.length} films n'ont pas d'affiche ou de réalisateur. Voulez-vous lancer la récupération TMDB ? (Cela peut prendre un peu de temps)`)) { - return; - } - - const btn = document.getElementById('btn-enrichir'); - if (btn) btn.innerHTML = ' Recherche en cours...'; - - let updatedCount = 0; - - for (let f of missingFilms) { - try { - // 1. Recherche du film par titre et année - const searchRes = await fetch(`https://api.themoviedb.org/3/search/movie?api_key=${tmdbKey}&query=${encodeURIComponent(f.title)}&year=${f.year}&language=fr-FR`); - const searchData = await searchRes.json(); - - if (searchData.results && searchData.results.length > 0) { - const movie = searchData.results[0]; - f.poster = movie.poster_path ? `https://image.tmdb.org/t/p/w500${movie.poster_path}` : f.poster; - - // 2. Recherche du réalisateur - const creditsRes = await fetch(`https://api.themoviedb.org/3/movie/${movie.id}/credits?api_key=${tmdbKey}`); - const creditsData = await creditsRes.json(); - - if (creditsData.crew) { - const director = creditsData.crew.find(c => c.job === 'Director'); - if (director) f.director = director.name; - } - - // 3. Sauvegarde automatique en base de données - await fetch(`${API_URL}?action=save_film`, { - method: 'POST', - headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' }, - body: JSON.stringify(f) - }); - updatedCount++; - } - } catch (e) { - console.error(`Erreur TMDB pour ${f.title}`, e); - } - } - - alert(`Terminé ! ${updatedCount} affiches et réalisateurs ont été récupérés avec succès.`); - if (btn) btn.innerHTML = ' Lancer la récupération'; - closeConfigModal(); - loadDashboardData(); } \ No newline at end of file