Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

music-metadata-browser

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

music-metadata-browser

Browserifed version of music-metadata

  • 0.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4K
decreased by-17.36%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status NPM version npm downloads dependencies Status

music-metadata-browser

music-metadata release for the browser.

Features

  • Supports metadata of the following audio and tag types:

Support for audio file types:

Audio formatDescriptionWiki
AIFFAudio Interchange File Format:link:
APEMonkey's Audio:link:
ASFAdvanced Systems Format:link:
FLACFree Lossless Audio Codec:link:
MP2MPEG-1 Audio Layer II:link:
MP3MPEG-1 / MEG-2 Audio Layer III:link:
M4AMPEG 4 Audio:link:
Ogg / Opus:link:
Ogg / Speex:link:
Ogg / Vorbis:link:
WAV:link:
WavPack:link:
WMAWindows Media Audio:link:

Support for tags:

Support for MusicBrainz tags as written by Picard.

Audio format & encoding details:

Online demo's

Donation

Not required, but would be extremely motivating. PayPal.me

Usage

Installation

Install via npm:

npm install music-metadata

or yarn

yarn add music-metadata

Import music-metadata:

This is how you can import music-metadata in JavaScript, in you code:

var mm = require('music-metadata-browser');

This is how it's done in TypeScript:

import * as mm from 'music-metadata-browser';

Module Functions:

In the browser there is node direct file access available. Only the parseStream function is available.T

import * as mm from 'music-metadata-browser';

mm.parseStream(readableStream)
  .then( metadata => {
     console.log(util.inspect(metadata, { showHidden: false, depth: null }));
     readableStream.close();
   });

The readable stream is derived from Node's readable stream.

If available, pass the mime-type and file-size. Without the mime-type, the content will be audio type will be automatically detected.

It is recommended to provide the corresponding MIME-type. An extension (e.g.: .mp3), filename or path will also work. If the MIME-type or filename is not provided, or not understood, music-metadata will try to derive the type from the content.

import * as mm from 'music-metadata-browser';

mm.parseStream(someReadStream, 'audio/mpeg', { fileSize: 26838 })
  .then( metadata => {
     console.log(util.inspect(metadata, { showHidden: false, depth: null }));
     someReadStream.close();
   });

The Web API File interface can be converted into a stream.

import fileReaderStream from 'filereader-stream';
import * as mm from 'music-metadata-browser';

/**
* @param file Browser File
*/
function readFromFile(file) {
  const stream = fileReaderStream(file);

  mm.parseStream(stream).then(metadata => {
    // metadata has all the metadata found in file
  });
}

To convert the File into a stream, filereader-stream is used.

If you wish to stream your audio track over HTTP you may want to use stream-http:

import * as mm from 'music-metadata-browser';
import http from "stream-http";

/**
* @param url Ensure the source the URL is pointing to, meets the CORS requirements
*/
function httpToStream(url) {
  return new Promise(resolve => {
    http.get(url, stream => {
      resolve(stream);
    });
  });
}

/**
* Stream over HTTP from URL
*/
httpToStream(url).then(stream => {
  mm.parseStream(stream, stream.headers["content-type"]);
});
orderTags function

Utility to Converts the native tags to a dictionary index on the tag identifier

orderTags(nativeTags: ITag[]): [tagId: string]: any[]
ratingToStars function

Can be used to convert the normalized rating value to the 0..5 stars, where 0 an undefined rating, 1 the star the lowest rating and 5 the highest rating.

ratingToStars(rating: number): number

Options:

  • duration: default: false, if set to true, it will parse the whole media file if required to determine the duration.
  • fileSize: only provide this in combination with parseStream function.
  • loadParser: (moduleName: string) => Promise<ITokenParser>;: default: lazy load using require, allows custom async lazy loading of parser modules. The resolved ITokenParser will not be cached.
  • native: default: false, if set to true, it will return native tags in addition to the common tags.
  • observer: (update: MetadataEvent) => void;: Will be called after each change to common (generic) tag, or format properties.
  • skipCovers: default: false, if set to true, it will not return embedded cover-art (images).
  • skipPostHeaders? boolean default: false, if set to true, it will not search all the entire track for additional headers. Only recommenced to use in combination with streams.

Although in most cases duration is included, in some cases it requires music-metadata parsing the entire file. To enforce parsing the entire file if needed you should set duration to true.

Metadata result:

If the returned promise resolves, the metadata (TypeScript IAudioMetadata interface) contains:

  • format: IFormat Audio format information
  • native: INativeTags List of native (original) tags found in the parsed audio file. If the native option is set to false, this property is not defined.
  • common: ICommonTagsResult Is a generic (abstract) way of reading metadata information.
Format

Audio format information. Defined in the TypeScript IFormat interface:

  • dataformat?: string Audio encoding format. e.g.: 'flac'
  • tagTypes?: TagType[] List of tagging formats found in parsed audio file
  • duration?: number Duration in seconds
  • bitrate?: number Number bits per second of encoded audio file
  • sampleRate?: number Sampling rate in Samples per second (S/s)
  • bitsPerSample?: number Audio bit depth
  • encoder? Encoder name
  • codecProfile?: string Codec profile
  • lossless?: boolean True if lossless, false for lossy encoding
  • numberOfChannels?: number Number of audio channels
  • numberOfSamples?: number Number of samples frames, one sample contains all channels. The duration is: numberOfSamples / sampleRate
Common

Common tag documentation is automatically generated.

Licence

(The MIT License)

Copyright (c) 2017 Borewit

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Package last updated on 19 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc