Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const metadata = { title: file.name }
ipc.send('wt-audio-metadata', infoHash, index, metadata)
const options = {
native: false,
skipCovers: true,
fileSize: file.length,
observer: event => {
ipc.send('wt-audio-metadata', infoHash, index, event.metadata)
}
}
const onMetaData = file.done
// If completed; use direct file access
? mm.parseFile(path.join(torrent.path, file.path), options)
// otherwise stream
: mm.parseStream(file.createReadStream(), file.name, options)
onMetaData
.then(() => {
console.log(`metadata for file='${file.name}' completed.`)
}).catch(function (err) {
return console.log('error getting audio metadata for ' + infoHash + ':' + index, err)
})
}
function metadata (path, cb) {
var audioStream = fs.createReadStream(path)
var returned = false // TODO clean up racy code
audioStream.on('error', (err) => {
if (!returned) {
returned = true
return cb(err)
}
})
mm.parseStream(audioStream, {native: true}, function (err, metadata) {
// important note, the stream is not closed by default. To prevent leaks, you must close it yourself
audioStream.destroy()
if (!returned) {
returned = true
return cb(err, err ? null : metadata)
}
})
}
this.fileExtension = supportedImageTypes[this.mimeType];
this.noThumbnail = '1'; // this may be overriden below
await this.handleImage(tmpAttachmentFile);
} else if (supportedAudioTypes[this.mimeType]) {
// Set media properties for 'audio' type
this.mediaType = 'audio';
this.fileExtension = supportedAudioTypes[this.mimeType];
this.noThumbnail = '1';
if (this.fileExtension === 'm4a') {
this.mimeType = 'audio/mp4'; // mime-type compatible with music-metadata
}
// Analyze metadata to get Artist & Title
const readStream = createReadStream(tmpAttachmentFile);
const { common: metadata } = await mmParseStream(
readStream,
this.mimeType,
{ mergeTagHeaders: true }
);
debug(`Metadata of ${tmpAttachmentFileName}`, metadata);
this.title = metadata.title;
if (_.isArray(metadata.artist)) {
[this.artist] = metadata.artist;
} else {
this.artist = metadata.artist;
}
} else {
// Set media properties for 'general' type
exports.processFile = function(fileObject, callback) {
logger.info(`Parsing ${fileObject.href}`);
mm.parseStream(fs.createReadStream(fileObject.href, {skipPostHeaders: true})).then(function(metadata) {
var common = metadata.common;
var trackName = 'Unknown Title'
, trackNo = ''
, albumName = 'Unknown Album'
, genre = 'Unknown'
, artistName = 'Unknown Artist'
, year = '';
if (common) {
trackName = (common.title) ? common.title.replace(/\\/g, '') : trackName;
trackNo = (common.track.no) ? common.track.no : trackNo;
albumName = (common.album) ? common.album.replace(/\\/g, '') : albumName;
artistName= (common.artist) ? common.artist.replace(/\\/g, '') : artistName;
year = (common.year) ? new Date(common.year).getFullYear() : year;