Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
], {}, function(err, output) {
if (err) {
ui.flash("error");
console.log(err);
}
console.log(output.join("\n"));
// Write tags
var tags = {
title: metadata.title,
artist: metadata.artist
};
if (id3.write(tags, filename + ".mp3") == false) {
ui.flash("error");
}
else {
ui.flash("ok");
}
});
};
doneTask(task);
} else {
updateTask(task);
}
},
song.id
);
await writeFile(song.album.cover.replace(/\?.*/, ''), imagefile);
let tags = {
title: song.name,
artist: song.artists.map(e => e.name).join(),
album: song.album.name,
image: imagefile,
};
let success = nodeID3.write(tags, trackfile);
queue.done(task);
if (!success) {
throw Error('Failed to write ID3 tags: \'%s\'', trackfile);
}
} catch (ex) {
error(ex);
if (ex.message === '_aborted') {
// Download task has been canceled
return;
}
queue.done(task);
failTask(task, ex);
module.exports = (filePath, meta) => {
if (!meta.APIC) return NodeID3.write(meta, filePath)
if (!/^http/.test(meta.APIC)) {
delete meta.APIC
return NodeID3.write(meta, filePath)
}
let picPath = filePath.replace(/\.mp3$/, '') + path.extname(meta.APIC).replace(extReg, '$1')
request(meta.APIC)
.on('response', respones => {
if (respones.statusCode !== 200 && respones.statusCode != 206) {
delete meta.APIC
NodeID3.write(meta, filePath)
return
}
respones
.pipe(fs.createWriteStream(picPath))
.on('finish', () => {
if (respones.complete) {
tagMp3() {
const tags = {
title: this.props.title,
artist: this.props.artist,
album: this.props.album,
image: this.verifyImage(this.tmpArt) ? this.tmpArt : false,
trackNumber: `${this.props.trackNum}/${this.props.totalTracks}`,
};
nodeID3.removeTags(this.tmpSong);
nodeID3.write(tags, this.tmpSong);
}
return new Promise((resolve, reject) => {
NodeID3.write(tags, target, function(err: any, buffer: Buffer) {
if (err) return reject(err);
resolve(buffer);
});
});
}
writeMetadata (trackInfo, trackPath = '', coverPath = '') {
if (trackPath.endsWith('mp3')) {
const tags = {
title: trackInfo.title,
album: trackInfo.album,
artist: trackInfo.artist,
year: trackInfo.year,
date: trackInfo.year,
TRCK: trackInfo.albumNo,
MCDI: trackInfo.discNo
}
if (trackInfo.albumImg) tags.APIC = path.resolve(coverPath)
logger.debug('MP3 meatadata', tags)
const result = nodeID3.write(tags, trackPath)
if (result) {
logger.debug('Metadata writed.')
} else {
logger.warn('Write metadata failed.')
}
} else {
const flac = new Metaflac(trackPath)
flac.setTag('TITLE=' + trackInfo.title)
flac.setTag('ALBUM=' + trackInfo.album)
flac.setTag('ARTIST=' + trackInfo.artist)
flac.setTag('DATE=' + trackInfo.year)
flac.setTag('YEAR=' + trackInfo.year)
flac.setTag('TRACKNUMBER=' + trackInfo.albumNo)
flac.setTag('DISCNUMBER=' + trackInfo.discNo)