const songsObject = async () => {
let songsObjectArray = [];
for (let i = 0; i < names.length; i++) {
try {
const metadata = await mm.parseFile(`${__dirname}\\${names[i]}`);
let picture = metadata.common.picture[0];
let encodedPicture = `data:${picture.format};base64,${picture.data.toString('base64')}`;
let trackDuration = metadata.format.duration;
let trackTitle = metadata.common.title;
let trackArtist = metadata.common.artist;
let id = Date.now();
let trackObj = { id, trackTitle, trackArtist, trackDuration, encodedPicture }
return songsObjectArray.push(trackObj);
} catch (error) {
console.error(error.message);
}
}
}
const songsArray = songsObject().then((result) => {console.log(result);}); // 1 ?
module.exports = songsArray
const getSongsObject = async () => {
for (let i = 0; i < names.length; i++) {
try {
const metadata = await mm.parseFile(`${__dirname}\\${names[i]}`);
let picture = metadata.common.picture[0];
let encodedPicture = `data:${picture.format};base64,${picture.data.toString('base64')}`;
let trackDuration = metadata.format.duration;
let trackTitle = metadata.common.title;
let trackArtist = metadata.common.artist;
let id = Date.now();
let trackObj = { id, trackTitle, trackArtist, trackDuration, encodedPicture }
songsObjectArray.push(trackObj);
} catch (error) {
console.error(error.message);
}
} return songsObjectArray;
}
module.exports = {
getSongsObject
}
const dp = require('../music/dataParser')
dp.getSongsObject().then((result) => {console.log(result)})