mirror of
https://github.com/xtrll/MusicMetaFinder.git
synced 2026-04-17 15:53:29 +02:00
refactor: link processing results with file paths inside objects
This commit is contained in:
@@ -7,17 +7,18 @@ import recognizeAudio from '../../api/recognition/acoustidApi.js';
|
||||
* @return {Promise<Object[]>} A promise that resolves to an array of recognition results.
|
||||
*/
|
||||
export default async function recognizeAudioFiles(audioFiles) {
|
||||
const recognitionPromises = audioFiles.map((filePath) => recognizeAudio(filePath)
|
||||
.catch((error) => {
|
||||
// Log the error and return null
|
||||
// This prevents one failed recognition from stopping the whole process
|
||||
const recognitionPromises = audioFiles.map(async (filePath) => {
|
||||
try {
|
||||
// Attempt to recognize the audio and return an object with filePath and id
|
||||
const id = await recognizeAudio(filePath);
|
||||
return { filePath, id };
|
||||
} catch (error) {
|
||||
// Log the error, return an object with filePath and null id
|
||||
console.error(`Recognition failed for file ${filePath}:`, error);
|
||||
return null;
|
||||
}));
|
||||
return { filePath, id: null };
|
||||
}
|
||||
});
|
||||
|
||||
// Wait for all recognitions to resolve. This will be an array of results or null values
|
||||
const recognizedAudioFiles = await Promise.all(recognitionPromises);
|
||||
// Filter out unsuccessful recognitions
|
||||
console.log(recognizedAudioFiles); // undefined
|
||||
return recognizedAudioFiles.filter((result) => result !== null);
|
||||
// This will be an array of objects with filePaths and ids or null values for ids
|
||||
return Promise.all(recognitionPromises);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user