How to use the music-metadata.parseFile 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 xiaozhu188 / electron-vue-cloud-music / src / renderer / store / modules / Localsong.js View on Github external
async refresh ({ state, commit, dispatch, rootState }, selectedFolders) {
      let folders = selectedFolders && selectedFolders.length ? selectedFolders : state.exportFolders
      let songs = []
      for (let folder of folders) {
        try {
          const dirs = fs.readdirSync(folder)
          for (let item of dirs) {
            const pathname = path.join(folder, item)
            const stat = fs.statSync(pathname)
            if (stat.isFile()) {
              if (item.endsWith('.mp3')) {
                const metadata = await mm.parseFile(pathname, {
                  duration: true
                })

                let songname = item.substring(0, item.lastIndexOf('.')).trim()
                let artist = [], name = songname, matched = false
                if (songname.split('-')[0] && songname.split('-')[1]) {
                  artist = songname.split('-')[0].split(',').map(item => { return {name: item} })
                  name = songname.split('-')[1].trim()
                  matched = false
                }
                let extraItem = {
                  artist, name, matched
                }

                // console.log(name, artist, metadata)
                const songItem = {
github volumio / Volumio2 / app / plugins / music_service / music_library / lib / metadata.js View on Github external
function _parseCommon(filename) {
	return musicMetadata.parseFile(filename, {native: false})
		.then(function(metadata) {
			// console.log('metadata._parseCommon', JSON.stringify(metadata));
			// console.log('%s - %s\n\tat %s', metadata.common.album, metadata.common.title, filename);
			return mm2custom(filename, metadata);
		});
}
github gavinbenda / platinum-md / src / renderer / components / LandingPage / DirectoryListing.vue View on Github external
fs.readdir(this.dir, (err, dir) => {
        // loop through results
        for (let filePath of dir) {
          // ensure that we're only working with files
          if (fs.statSync(this.dir + filePath).isFile()) {
            let buffer = readChunk.sync(this.dir + filePath, 0, fileType.minimumBytes)
            let fileTypeInfo = fileType(buffer)
            // only interestedin MP3 files at the moment, ignore all others
            if (fileTypeInfo != null) {
              if (fileTypeInfo.ext === 'mp3' || fileTypeInfo.ext === 'wav' || fileTypeInfo.ext === 'flac') {
                // read metadata
                mm.parseFile(this.dir + filePath, {native: true})
                  .then(metadata => {
                    console.log(metadata)
                    // Get data for file object
                    let artist = metadata.common.artist
                    let title = metadata.common.title
                    let album = metadata.common.album
                    let bitrate = metadata.format.bitrate
                    let codec = metadata.format.codec
                    let trackNo = metadata.common.track.no
                    // write the relevent data to the files array
                    this.files.push({
                      fileName: filePath,
                      artist: (artist !== null) ? artist.substring(0, 50).replace('/', '_') : '',
                      title: (title !== null) ? title.substring(0, 50).replace('/', '_') : '',
                      album: (album !== null) ? album : '',
                      trackNo: (trackNo !== null) ? trackNo : 0,
github martpie / museeks / src / ui / utils / utils.ts View on Github external
export const getMetadata = async (trackPath: string): Promise<track> =&gt; {
  const defaultMetadata = getDefaultMetadata();

  const basicMetadata: Track = {
    ...defaultMetadata,
    path: trackPath
  };

  try {
    const stats = await stat(trackPath);
    const data = await mmd.parseFile(trackPath, {
      native: true, skipCovers: true, fileSize: stats.size, duration: true
    });

    // Let's try to define something with what we got so far...
    const parsedData = parseMusicMetadata(data, trackPath);

    const metadata: Track = {
      ...defaultMetadata,
      ...parsedData,
      path: trackPath
    };

    metadata.loweredMetas = getLoweredMeta(metadata);

    // Let's try another wat to retrieve a track duration
    if (!metadata.duration) {
github bhj / karaoke-forever / server / Scanner / FileScanner / FileScanner.js View on Github external
async process (item, pathId) {
    const pathInfo = path.parse(item.file)
    const tags = await musicMeta.parseFile(item.file, {
      duration: true,
      skipCovers: true,
    })

    if (!tags.format.duration) {
      throw new Error('  => could not determine duration')
    }

    log.info('  => duration: %s:%s',
      Math.floor(tags.format.duration / 60),
      Math.round(tags.format.duration % 60, 10).toString().padStart(2, '0')
    )

    // run parser
    const parsed = this.parser({
      dir: pathInfo.dir,
github ififfy / flipflip / src / renderer / components / player / AudioControl.tsx View on Github external
detectBPM() {
    if (this.props.isFirst && this.props.audio.url) {
      mm.parseFile(urlToPath(this.props.audio.url))
        .then((metadata: any) => {
          if (metadata && metadata.common && metadata.common.bpm) {
            this.changeKey('bpm', metadata.common.bpm);
          }
        })
        .catch((err: any) => {
          console.error("Error reading metadata:", err.message);
        });
    }
  }
github akabekobeko / examples-electron / audio-player / src / main / MusicMetadataReader.ts View on Github external
return new Promise((resolve, reject) =&gt; {
    return MetadataParser.parseFile(filePath, { duration: true })
      .then((metadata: IAudioMetadata) =&gt; {
        const imageFilePath = saveImageFile(metadata.common.picture)
        const common = metadata.common
        resolve({
          filePath,
          artist: common.artist || '',
          album: common.album || '',
          title: common.title || '',
          year: common.year ? String(common.year) : '',
          track: common.track &amp;&amp; 0 &lt; common.track.no ? common.track.no : 1,
          disc: common.disk &amp;&amp; 0 &lt; common.disk.no ? common.disk.no : 1,
          genre: common.genre &amp;&amp; 0 &lt; common.genre.length ? common.genre[0] : '',
          duration: metadata.format.duration || 0,
          imageFilePath
        })
      })
github akabekobeko / examples-electron / audio-player / src / js / main / MusicMetadataReader.js View on Github external
_readMetadata (filePath) {
    return MusicMetadata.parseFile(filePath, { duration: true })
      .then(metadata => {
        return { metadata: metadata }
      })
  }
github quantumkv / nighthawk / src / renderer / actions / LibraryActions.ts View on Github external
files.map(async (file, index) => {
                const data: IAudioMetadata = await parseFile(file, {
                    skipCovers: true,
                });

                const filestats: fs.Stats = await fstat(file);

                if (
                    data.common.title === '' ||
                    data.common.title === undefined
                ) {
                    data.common.title = path.basename(file, path.extname(file));
                }

                if (
                    data.common.artist === '' ||
                    data.common.artist === undefined
                ) {