Closed Zero-1729 closed 5 years ago
It seems there is a way to achieve the aforementioned goal without modifying the code base. I am therefore going to close this PR.
The method employs the use of Javascript Promises.
I have outlined the approach in the following JS code snippet below for the sake of providing anyone in the future with a method to still keep track of the audio file's path when handling the resolved tags;
conts jsm = require('jsmediatags')
var filepath = '/path/to/audio.mp3'
new Promise((resolve, reject) => {
new jsm.Reader(filepath).setTagsToRead([
'title', 'artist', 'album', 'genre', 'picture', 'year'
]).read({
onSuccess: (tag) => {
resolve({
tags: tag.tags,
track_path: filepath
})
},
onError: (err) => {
reject({
error: err,
track_path: filepath
})
}
})
}).then(resolved_obj => {
// Here we simply obtain the JS Object containing the scanned tags and filepath
}).catch(error_obj => {
// And we handle error reporting using the JS Object
// ... containing the details of the scan error
// ... aswell as the audio's filepath
})
Any additional questions or requests for clarifications are welcome.
We might want our (
onSuccess
) callback function to also return thepath
of the audio file it read along with itstags
. So that we can properly construct the following track object for example;