+
+
\ No newline at end of file
diff --git a/src/adapters/metadata/spotifyAdapter.js b/src/adapters/metadata/spotifyAdapter.js
index 7dadfa0..c171391 100644
--- a/src/adapters/metadata/spotifyAdapter.js
+++ b/src/adapters/metadata/spotifyAdapter.js
@@ -15,7 +15,7 @@ export default async function getMetadata(trackIds) {
const accessToken = await getSpotifyAccessToken();
- const metadataPromises = trackIds.map(trackId => requestMetadata(trackId, accessToken));
+ const metadataPromises = trackIds.map((trackId) => requestMetadata(trackId, accessToken));
// Resolves to an array of metadata objects corresponding to the track IDs.
return await Promise.all(metadataPromises);
@@ -24,4 +24,3 @@ export default async function getMetadata(trackIds) {
throw e; // Rethrowing the error to handle it at a higher level
}
}
-
diff --git a/src/adapters/recognition/acoustidAdapter.js b/src/adapters/recognition/acoustidAdapter.js
index 9c49926..69f8f57 100644
--- a/src/adapters/recognition/acoustidAdapter.js
+++ b/src/adapters/recognition/acoustidAdapter.js
@@ -14,6 +14,7 @@ export default async function recognizeAudioFiles(audioFiles) {
return { filePath, id };
} catch (error) {
// Log the error, return an object with filePath and null id
+ // This prevents one failed recognition from stopping the whole process
console.error(`Recognition failed for file ${filePath}:`, error);
return { filePath, id: null };
}
diff --git a/src/adapters/recognition/auddAdapter.js b/src/adapters/recognition/auddAdapter.js
index 62e9048..054dfe7 100644
--- a/src/adapters/recognition/auddAdapter.js
+++ b/src/adapters/recognition/auddAdapter.js
@@ -7,15 +7,13 @@ import recognizeAudio from '../../api/recognition/auddApi.js';
* @return {Promise<(Object|null)[]>} A promise that resolves to an array of recognition result objects or null values for each file.
*/
export default async function recognizeAudioFiles(audioFiles) {
- const recognitionPromises = audioFiles.map(filePath =>
- recognizeAudio(filePath)
- .catch(error => {
- // Log the error and return null for this file.
- // This prevents one failed recognition from stopping the whole process
- console.error(`Recognition failed for file ${filePath}:`, error);
- return null;
- })
- );
+ const recognitionPromises = audioFiles.map((filePath) => recognizeAudio(filePath)
+ .catch((error) => {
+ // Log the error and return null for this file.
+ // This prevents one failed recognition from stopping the whole process
+ console.error(`Recognition failed for file ${filePath}:`, error);
+ return null;
+ }));
// Wait for all recognitions to resolve. This will be an array of results or null values for each audio file.
return Promise.all(recognitionPromises);
diff --git a/src/services/fileService.js b/src/services/fileService.js
index e49dd2d..768a8d8 100644
--- a/src/services/fileService.js
+++ b/src/services/fileService.js
@@ -1,5 +1,5 @@
-import validateAudioFile from '../utils/validateAudioFiles.js';
import path from 'path';
+import validateAudioFile from '../utils/validateAudioFiles.js';
/**
* Processes an array of file paths and returns an array containing only valid and supported audio file paths.
@@ -31,9 +31,8 @@ export default async function validateAudioFiles(filePaths) {
if (supportedAudioExtensions.has(fileExtension)) {
// Return the file path if the extension is supported
return validFilePath;
- } else {
- console.error(`File ${path.basename(validFilePath)} is an audio file but ${fileExtension} format is not yet supported and so is ignored.`);
}
+ console.error(`File ${path.basename(validFilePath)} is an audio file but ${fileExtension} format is not yet supported and so is ignored.`);
}
return null; // Return null if file is not valid or not supported
});
diff --git a/src/services/saveImageToFile.js b/src/services/saveImageToFile.js
index d1f8178..9fc5bef 100644
--- a/src/services/saveImageToFile.js
+++ b/src/services/saveImageToFile.js
@@ -1,7 +1,6 @@
import path from 'path';
-import fs from 'fs';
import downloadImage from '../utils/downloadImage.js';
-import ensureDirectoryExists from "../utils/ensureDirectoryExists.js";
+import ensureDirectoryExists from '../utils/ensureDirectoryExists.js';
/**
* Saves an image from a specified URL to a given output directory.
diff --git a/src/utils/downloadImage.js b/src/utils/downloadImage.js
index 650d713..7f3d36d 100644
--- a/src/utils/downloadImage.js
+++ b/src/utils/downloadImage.js
@@ -1,5 +1,5 @@
-import axiosRetry from '../utils/retryAxios.js';
import fs from 'fs';
+import axiosRetry from './retryAxios.js';
/**
* Downloads an image from the specified URL and saves it to the provided file path.
@@ -34,4 +34,3 @@ export default async function downloadImage(url, downloadPath) {
throw error;
}
}
-
diff --git a/src/utils/generateUniqueFileName.js b/src/utils/generateUniqueFileName.js
index d0d1cf0..c0161c1 100644
--- a/src/utils/generateUniqueFileName.js
+++ b/src/utils/generateUniqueFileName.js
@@ -16,6 +16,7 @@ const generateUniqueFilename = async (directory, filename) => {
let filePath = path.join(directory, uniqueFilename);
// Check if the file exists and append a counter to make it unique
+ // eslint-disable-next-line no-await-in-loop
while (await fs.stat(filePath).catch(() => false)) {
uniqueFilename = `${basename} (${counter})${extension}`;
filePath = path.join(directory, uniqueFilename);
diff --git a/src/utils/renameAudioFileTitle.js b/src/utils/renameAudioFileTitle.js
index 7325a8b..243cecf 100644
--- a/src/utils/renameAudioFileTitle.js
+++ b/src/utils/renameAudioFileTitle.js
@@ -1,6 +1,6 @@
import path from 'path';
import fs from 'fs/promises';
-import generateUniqueFilename from '../utils/generateUniqueFilename.js';
+import generateUniqueFilename from './generateUniqueFilename.js';
/**
* Renames an audio file by its metadata properties: artist and title.
diff --git a/src/utils/retryAxios.js b/src/utils/retryAxios.js
index 7601959..139afde 100644
--- a/src/utils/retryAxios.js
+++ b/src/utils/retryAxios.js
@@ -5,8 +5,7 @@ const axiosInstance = axios.create();
axiosRetry(axiosInstance, {
retries: 3, // The number of times to retry before failing
- retryCondition: (error) => // Retry on a 429 status code or a 5xx status code
- error.response.status === 429 || error.response.status >= 500,
+ retryCondition: (error) => error.response.status === 429 || error.response.status >= 500,
retryDelay: (retryCount) => retryCount * 2000, // Wait 2 seconds between retries
});
diff --git a/src/utils/validateAudioFiles.js b/src/utils/validateAudioFiles.js
index 1a13aae..a2f4e5d 100644
--- a/src/utils/validateAudioFiles.js
+++ b/src/utils/validateAudioFiles.js
@@ -19,20 +19,19 @@ export default async function validateAudioFile(filePath) {
// MIME type checking
const mimeType = mime.lookup(filePath);
- console.log(`MIME type of ${filePath} is ${mimeType}`); // Log the MIME type
// Set of recognized audio MIME types
const validAudioMimeTypes = new Set([
- 'audio/mpeg', // .mp3
- 'audio/wav', // .wav
- 'audio/x-wav', // .wav
- 'audio/flac', // .flac
- 'audio/x-flac', // .flac
- 'audio/ogg', // .ogg
- 'audio/aac', // .aac
- 'audio/aiff', // .aiff
- 'audio/x-aiff', // .aiff
- 'audio/x-m4a', // .m4a
+ 'audio/mpeg', // .mp3
+ 'audio/wav', // .wav
+ 'audio/x-wav', // .wav
+ 'audio/flac', // .flac
+ 'audio/x-flac', // .flac
+ 'audio/ogg', // .ogg
+ 'audio/aac', // .aac
+ 'audio/aiff', // .aiff
+ 'audio/x-aiff', // .aiff
+ 'audio/x-m4a', // .m4a
]);
// Perform the MIME type validation