From cb500038befdfb51a4ebed1af529e03669c2fb7a Mon Sep 17 00:00:00 2001 From: xtrullor73 Date: Mon, 27 May 2024 16:24:29 -0700 Subject: [PATCH] refactor: apply eslint fixes and minor clean up --- .idea/.name | 1 + .idea/git_toolbox_prj.xml | 10 + .idea/workspace-LifeIsARace.xml | 265 ++++++++++++++++++++ src/adapters/metadata/spotifyAdapter.js | 3 +- src/adapters/recognition/acoustidAdapter.js | 1 + src/adapters/recognition/auddAdapter.js | 16 +- src/services/fileService.js | 5 +- src/services/saveImageToFile.js | 3 +- src/utils/downloadImage.js | 3 +- src/utils/generateUniqueFileName.js | 1 + src/utils/renameAudioFileTitle.js | 2 +- src/utils/retryAxios.js | 3 +- src/utils/validateAudioFiles.js | 21 +- 13 files changed, 302 insertions(+), 32 deletions(-) create mode 100644 .idea/.name create mode 100644 .idea/git_toolbox_prj.xml create mode 100644 .idea/workspace-LifeIsARace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..90a0260 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +metadataNormalizerService.js \ No newline at end of file diff --git a/.idea/git_toolbox_prj.xml b/.idea/git_toolbox_prj.xml new file mode 100644 index 0000000..d1e3d40 --- /dev/null +++ b/.idea/git_toolbox_prj.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace-LifeIsARace.xml b/.idea/workspace-LifeIsARace.xml new file mode 100644 index 0000000..065e0c3 --- /dev/null +++ b/.idea/workspace-LifeIsARace.xml @@ -0,0 +1,265 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + "lastFilter": {} +} + + + + { + "selectedUrlAndAccountId": { + "url": "https://github.com/xtrll/MusicMetaFinder.git", + "accountId": "2dd8b0a6-0bdb-4445-9876-eac917c9314a" + } +} + + + + + + + { + "associatedIndex": 4 +} + + + + + + + { + "keyToString": { + "ASKED_ADD_EXTERNAL_FILES": "true", + "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true", + "Node.js.app.js.executor": "Run", + "Node.js.audioController.js.executor": "Run", + "Node.js.checkChromaprint.js.executor": "Run", + "Node.js.lyricsRetrieval.js.executor": "Run", + "Node.js.test.js.executor": "Run", + "Node.js.truncateAudioStream.js.executor": "Run", + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "git-widget-placeholder": "main", + "ignore.virus.scanning.warn.message": "true", + "javascript.nodejs.core.library.configured.version": "21.6.2", + "javascript.nodejs.core.library.typings.version": "20.12.11", + "last_opened_file_path": "C:/Users/XTRLL/OneDrive/Projects/WebstormProjects/MusicMetaFinder", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.standard": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.standard": "", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "settings.editor.selected.configurable": "settings.javascript.linters.eslint", + "ts.external.directory.path": "C:\\Users\\XTRLL\\AppData\\Local\\Programs\\WebStorm\\plugins\\javascript-plugin\\jsLanguageServicesImpl\\external", + "vue.rearranger.settings.migration": "true" + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1713646863779 + + + + + + + + + + + \ 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