Actualiser js/admin.js
This commit is contained in:
+38
-57
@@ -351,6 +351,12 @@ async function openConfigModal() {
|
|||||||
fanartInput.value = '';
|
fanartInput.value = '';
|
||||||
fanartInput.placeholder = data.fanart_api_key ? '✅ Clé Fanart.tv configurée (laisser vide pour garder)' : 'Entrez votre clé Fanart.tv';
|
fanartInput.placeholder = data.fanart_api_key ? '✅ Clé Fanart.tv configurée (laisser vide pour garder)' : 'Entrez votre clé Fanart.tv';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const upcmdbInput = document.getElementById('upcmdb-key-input');
|
||||||
|
if (upcmdbInput) {
|
||||||
|
upcmdbInput.value = '';
|
||||||
|
upcmdbInput.placeholder = data.upcmdb_api_key ? '✅ Clé UPCMDB configurée (laisser vide pour garder)' : 'Gratuite sur upcmdb.com — fallback EAN';
|
||||||
|
}
|
||||||
} catch(e) { console.error(e); }
|
} catch(e) { console.error(e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,34 +425,11 @@ async function handleCritiqueUpload(input) {
|
|||||||
loadDashboardData();
|
loadDashboardData();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. Normalisation des colonnes du CSV
|
// Extraction EAN uniquement depuis le CSV vidéothèque
|
||||||
function normalizeVideothequeRow(row) {
|
function normalizeVideothequeRow(row) {
|
||||||
// Récupération stricte de l'EAN sans supprimer les zéros du début
|
let ean = row['ean_isbn13'] || row['EAN'] || row['ean'] || row['Barcode'] || row['UPC'] || row['upc_isbn10'] || '';
|
||||||
let ean = row['ean_isbn13'] || row['EAN'] || row['ean'] || row['Barcode'] || row['UPC'] || '';
|
if (ean !== '') ean = String(ean).replace(/[^0-9]/g, '');
|
||||||
if (ean !== '') ean = String(ean).replace(/[^0-9]/g, ''); // Garde que les chiffres
|
return { ean };
|
||||||
|
|
||||||
let length = row['length'] || row['Length'] || row['Runtime'] || row['runtime'] || '';
|
|
||||||
if (length !== '') length = String(Math.round(parseFloat(length)));
|
|
||||||
|
|
||||||
let discs = row['number_of_discs'] || row['Number_of_discs'] || row['Discs'] || row['discs'] || '';
|
|
||||||
discs = (!discs || isNaN(parseFloat(discs))) ? 1 : Math.round(parseFloat(discs));
|
|
||||||
|
|
||||||
let aspect = row['aspect_ratio'] || row['Aspect_ratio'] || row['AspectRatio'] || row['Aspect Ratio'] || '';
|
|
||||||
let publisher = row['publisher'] || row['Publisher'] || row['Studio'] || row['studio'] || row['Label'] || '';
|
|
||||||
let format = row['format'] || row['Format'] || row['Media'] || row['media'] || '';
|
|
||||||
|
|
||||||
// Certains CSV ont déjà les acteurs, on les garde au cas où
|
|
||||||
let actors = row['creators'] || row['Actors'] || row['actors'] || row['Cast'] || '';
|
|
||||||
|
|
||||||
return Object.assign({}, row, {
|
|
||||||
ean: ean,
|
|
||||||
length: length,
|
|
||||||
number_of_discs: discs,
|
|
||||||
aspect_ratio: aspect,
|
|
||||||
publisher: publisher,
|
|
||||||
format: format,
|
|
||||||
actors: actors
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleVideothequeUpload(input) {
|
function handleVideothequeUpload(input) {
|
||||||
@@ -463,42 +446,27 @@ function handleVideothequeUpload(input) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Construction de l'objet pour l'API
|
|
||||||
const items = parsedData.map(row => {
|
const items = parsedData.map(row => {
|
||||||
const normalizedRow = normalizeVideothequeRow(row);
|
const { ean } = normalizeVideothequeRow(row);
|
||||||
const title = row['title'] || row['Title'] || '';
|
if (!ean || ean.length < 8) return null;
|
||||||
if (!title) return null;
|
return { ean };
|
||||||
|
|
||||||
const publishDate = row['publish_date'] || row['Publish_date'] || row['publishdate'] || '';
|
|
||||||
const year = publishDate ? publishDate.split('-')[0] : (row['year'] || row['Year'] || '');
|
|
||||||
|
|
||||||
return {
|
|
||||||
title: title.trim(),
|
|
||||||
year: year,
|
|
||||||
description: (row['description'] || row['Description'] || '').trim(),
|
|
||||||
ean: normalizedRow['ean'],
|
|
||||||
length: normalizedRow['length'],
|
|
||||||
number_of_discs: normalizedRow['number_of_discs'],
|
|
||||||
aspect_ratio: normalizedRow['aspect_ratio'],
|
|
||||||
publisher: normalizedRow['publisher'],
|
|
||||||
format: normalizedRow['format'],
|
|
||||||
actors: normalizedRow['actors'],
|
|
||||||
director: row['director'] || row['Director'] || ''
|
|
||||||
};
|
|
||||||
}).filter(item => item !== null);
|
}).filter(item => item !== null);
|
||||||
|
|
||||||
if (items.length === 0) {
|
if (items.length === 0) {
|
||||||
alert("❌ Aucun film valide trouvé dans le fichier CSV.");
|
alert("❌ Aucun code EAN valide trouvé dans le fichier CSV.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
showImportModal(items.length, 'videotheque');
|
showImportModal(items.length, 'videotheque');
|
||||||
let processed = 0;
|
let processed = 0;
|
||||||
|
|
||||||
|
let totalImported = 0;
|
||||||
|
let totalSkipped = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Traiter par lots de 3 pour éviter la surcharge (notrecinema.com est plus lent)
|
// Lots de 2 : UPCitemdb impose ~2 s entre chaque requête EAN
|
||||||
for (let i = 0; i < items.length; i += 3) {
|
for (let i = 0; i < items.length; i += 2) {
|
||||||
const batch = items.slice(i, i + 3);
|
const batch = items.slice(i, i + 2);
|
||||||
|
|
||||||
const response = await fetch(`${API_URL}?action=import_batch`, {
|
const response = await fetch(`${API_URL}?action=import_batch`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -518,17 +486,18 @@ function handleVideothequeUpload(input) {
|
|||||||
if (!data.success) {
|
if (!data.success) {
|
||||||
throw new Error(data.error || "Erreur inconnue");
|
throw new Error(data.error || "Erreur inconnue");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
totalImported += data.imported || 0;
|
||||||
|
totalSkipped += data.skipped || 0;
|
||||||
|
|
||||||
processed += batch.length;
|
processed += batch.length;
|
||||||
updateImportModal(processed, items.length);
|
updateImportModal(processed, items.length);
|
||||||
|
|
||||||
// Délai réduit (Les API supportent une cadence plus élevée)
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 300));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
input.value = '';
|
input.value = '';
|
||||||
closeImportModal();
|
closeImportModal();
|
||||||
showSuccessModal(`${items.length} édition(s) physique(s) importée(s) avec succès !`);
|
const skipMsg = totalSkipped > 0 ? ` (${totalSkipped} EAN ignoré(s) — introuvable dans UPCitemdb/UPCMDB)` : '';
|
||||||
|
showSuccessModal(`${totalImported} édition(s) importée(s) (UPCitemdb + UPCMDB + TMDB).${skipMsg}`);
|
||||||
loadDashboardData();
|
loadDashboardData();
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -561,6 +530,7 @@ function closeImportModal() { document.getElementById('import-progress-modal').c
|
|||||||
async function saveConfigKeys() {
|
async function saveConfigKeys() {
|
||||||
const tmdbKeyValue = document.getElementById('tmdb-key-input').value.trim();
|
const tmdbKeyValue = document.getElementById('tmdb-key-input').value.trim();
|
||||||
const fanartKeyValue = document.getElementById('fanart-key-input').value.trim();
|
const fanartKeyValue = document.getElementById('fanart-key-input').value.trim();
|
||||||
|
const upcmdbKeyValue = document.getElementById('upcmdb-key-input').value.trim();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (tmdbKeyValue) {
|
if (tmdbKeyValue) {
|
||||||
@@ -573,6 +543,17 @@ async function saveConfigKeys() {
|
|||||||
body: JSON.stringify({ key_name: 'tmdb_api_key', key_value: tmdbKeyValue })
|
body: JSON.stringify({ key_name: 'tmdb_api_key', key_value: tmdbKeyValue })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (upcmdbKeyValue) {
|
||||||
|
await fetch(`${API_URL}?action=save_config`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': localStorage.getItem('token'),
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ key_name: 'upcmdb_api_key', key_value: upcmdbKeyValue })
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (fanartKeyValue) {
|
if (fanartKeyValue) {
|
||||||
await fetch(`${API_URL}?action=save_config`, {
|
await fetch(`${API_URL}?action=save_config`, {
|
||||||
@@ -613,7 +594,7 @@ function updateImportInterface() {
|
|||||||
desc.textContent = 'Sélectionnez vos fichiers "ratings.csv" et "reviews.csv" (Letterboxd).';
|
desc.textContent = 'Sélectionnez vos fichiers "ratings.csv" et "reviews.csv" (Letterboxd).';
|
||||||
} else {
|
} else {
|
||||||
title.innerHTML = '<strong>Importer ma Vidéothèque</strong>';
|
title.innerHTML = '<strong>Importer ma Vidéothèque</strong>';
|
||||||
desc.textContent = 'Sélectionnez vos listes CSV de supports physiques (Blu-ray, DVD, 4K).';
|
desc.textContent = 'Import CSV (EAN seul) : UPCitemdb puis UPCMDB en secours, TMDB pour affiche/synopsis/réalisateur/acteurs.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user