How to use the music-metadata.parseStream function in music-metadata

To help you get started, we’ve selected a few music-metadata examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webtorrent / webtorrent-desktop / src / renderer / webtorrent.js View on Github external
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)
    })
}
github hypermodules / hyperamp / main / lib / artwork-cache / util.js View on Github external
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)
    }
  })
}
github FreeFeed / freefeed-server / app / models / attachment.js View on Github external
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
github jansmolders86 / mediacenterjs / apps / music / metadata-processor.js View on Github external
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;