diff --git a/script.js b/script.js
index ad1c35c..117832b 100644
--- a/script.js
+++ b/script.js
@@ -1520,14 +1520,24 @@ async function handleFileUpload(event) {
progressContainer.innerHTML = '
UPLOADING TRACKS...
';
progressContainer.classList.add('active');
+ const existingFilenames = allSongs.map(s => s.file.split('/').pop().toLowerCase());
+
const uploadPromises = files.map(async (file) => {
const allowedExts = ['.mp3', '.m4a', '.wav', '.flac', '.ogg'];
const ext = file.name.substring(file.name.lastIndexOf('.')).toLowerCase();
+
if (!allowedExts.includes(ext)) {
console.warn(`${file.name} is not a supported audio file`);
return;
}
+ // Check for duplicates
+ if (existingFilenames.includes(file.name.toLowerCase())) {
+ console.log(`[UPLOAD] Skipping duplicate: ${file.name}`);
+ showToast(`Skipped duplicate: ${file.name}`, 'info');
+ return;
+ }
+
const formData = new FormData();
formData.append('file', file);
diff --git a/server.py b/server.py
index b4000da..629b99e 100644
--- a/server.py
+++ b/server.py
@@ -409,6 +409,9 @@ def setup_shared_routes(app, index_file='index.html'):
filepath = os.path.join(MUSIC_FOLDER, filename)
+ if os.path.exists(filepath):
+ return jsonify({"success": False, "error": "File already exists in library"}), 409
+
try:
file.save(filepath)
print(f"UPLOADED: {filename}")
diff --git a/techdj_qt.py b/techdj_qt.py
index 0e1fdf5..5e28f5c 100644
--- a/techdj_qt.py
+++ b/techdj_qt.py
@@ -2110,16 +2110,29 @@ class DJApp(QMainWindow):
return
if self.library_mode == "local":
+ filename = os.path.basename(file_path)
+ # Check for duplicates in local_library
+ if any(Path(track['path']).name.lower() == filename.lower() for track in self.local_library):
+ QMessageBox.information(self, "Import Skipped", f"'{filename}' is already in your local library.")
+ return
+
# Copy to local music folder
- dest = self.lib_path / os.path.basename(file_path)
+ dest = self.lib_path / filename
try:
shutil.copy2(file_path, dest)
- self.status_label.setText(f"Imported: {os.path.basename(file_path)}")
+ self.status_label.setText(f"Imported: {filename}")
self.load_library()
except Exception as e:
QMessageBox.warning(self, "Import Error", f"Failed to import file: {e}")
else:
# Upload to server
+ filename = os.path.basename(file_path)
+ # Check for duplicates in server_library
+ if hasattr(self, 'server_library'):
+ if any(track['file'].split('/')[-1].lower() == filename.lower() for track in self.server_library):
+ QMessageBox.information(self, "Upload Skipped", f"'{filename}' already exists on the server.")
+ return
+
try:
self.status_label.setText("Uploading to server...")
base_url = self.get_server_base_url()