Code Monkey home page Code Monkey logo

music-metadata-browser's Introduction

Build Status NPM version npm downloads dependencies Status Known Vulnerabilities Codacy Badge Coverage Status Minified size Chat

music-metadata-browser

music-metadata release for the browser.

Featured

  • Supports metadata of the following audio and tag types:

Support for audio file types

Audio format Description Wiki
AIFF / AIFF-C Audio Interchange File Format ๐Ÿ”— Apple rainbow logo
APE Monkey's Audio ๐Ÿ”— Monkey's Audio logo
ASF Advanced Systems Format ๐Ÿ”—
FLAC Free Lossless Audio Codec ๐Ÿ”— FLAC logo
MP2 MPEG-1 Audio Layer II ๐Ÿ”—
MP3 MPEG-1 / MPEG-2 Audio Layer III ๐Ÿ”— MP3 logo
MPC Musepack SV7 ๐Ÿ”— musepack logo
MPEG 4 mp4, m4a, m4v, aac ๐Ÿ”— AAC logo
Ogg / Opus ๐Ÿ”— Opus logo
Ogg / Speex ๐Ÿ”— Speex logo
Ogg / Vorbis ๐Ÿ”— Vorbis logo
WAV ๐Ÿ”— WAV logo
WV WavPack ๐Ÿ”— WavPack logo
WMA Windows Media Audio ๐Ÿ”— Windows Media logo

Support for tags

Support for MusicBrainz tags as written by Picard.

Audio format & encoding details

Support for encoding / format details:

Online demo's

Donation

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

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

There are currently three ways to parse (read) audio tracks:

  1. parsing a Web API blob or file with the parseBlob function.
  2. Using ReadableStream using the parseReadableStream function.
  3. Using Node.js streams using the parseNodeStream function.
  4. Provide a URL to fetch the audio track from.

parseBlob function

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

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

/**
* @param blob Blob (e.g. Web API File)
*/
function readFromBlob(blob) {
  
  // blob is a Web API Blob or File
  mm.parseBlob(blob).then(metadata => {
    // metadata has all the metadata found in the blob or file
  });
}

parseReadableStream function

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

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

Parse from a Web API ReadableStream.

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';

const readableStream = result.node;

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

parseNodeStream function

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

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

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.

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

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

fetchUrl function

If you wish to stream your audio track over HTTP you need can use fetchFromUrl which is using the Fetch API to retrieve the audio track:

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

/**
* Stream over HTTP from URL
*/
return mm.fetchFromUrl(audioTrackUrl, options)

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

The following (optional) configurations can be passed:

  • duration: default: false, if set to true, it will parse the whole media file if required to determine the duration.
  • fileSize: provide this if parsing from a stream.
  • 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.

Automated testing

Automated unit tests are planned to be tested with different browsers. This service has been made available by:

Windows Media logo

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.

music-metadata-browser's People

Contributors

borewit avatar acklan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.