npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@voltraco/taglib

v0.8.2

Published

Simple bindings to TagLib

Downloads

7

Readme

node-taglib

node-taglib is a simple binding to TagLib in Javascript.

It requires node.js and taglib header files (on Debian systems, install libtag1-dev).

node-taglib offers only an abstract interface without giving access to extended file-specific attributes. It does allow custom resolvers though. Synchronous write support is supported for Tag.

NOTE: Asynchronous API requires use of TagLib from git since certain bugs present in the released v1.7 cause problems.

Example

// load the library
var taglib = require('taglib');

// asynchronous API
taglib.tag(path, function(err, tag) {
    tag.artist; // => "Queen"
    tag.title = "Erm";
    tag.saveSync();
});

// synchronous API
var tag = taglib.tagSync(path);

tag.title; // => "Another one bites the dust"
tag.artist; // => "Kween"
tag.artist = "Queen";

tag.isEmpty(); // => false

tag.saveSync(); // => true

Installation

via npm (Recommended)

npm install taglib

From source

# make sure you have node and taglib installed
git clone git://github.com/nikhilm/node-taglib.git
cd node-taglib
npm install .
node examples/simple.js /path/to/mp3_or_ogg_file
# you can now require('./taglib')

The examples show usage.

API

read(path, callback)

read(buffer, format, callback)

The function you will most likely want to use. callback should have signature callback(err, tag, audioProperties) where tag and audioProperties are plain-old JavaScript objects. For the distinction between these and Tag, see Tag below.

If there was an error reading the file, err will be non-null and tag and audioProperties will be null.

If no tag was found, tag will be an empty object (falsy). tag can have the following fields. node-taglib currently supports only the fields common to all formats:

  • title (string)
  • album (string)
  • comment (string)
  • artist (string)
  • track (string)
  • year (integer)
  • genre (string)

If no audio properties could be read, audioProperties will be an empty object (falsy). The following fields are available in audioProperties, all are integers:

  • length
  • bitrate
  • sampleRate
  • channels

Writing audio properties is not supported.

In the second variant, which can read from a buffer, format should be a string as specified in Formats.

tag(path, callback)

tag(buffer, format, callback)

Read the tag from the file at path asynchronously. The callback should have signature (err, tag). On success, err will be null and tag will be a Tag. If errors occurred, err will contain the error and tag will be null. err will be an object with field code having the integer error code (errno.h) and field message will have a string representation.

In the second variant, which can read from a buffer, format should be a string as specified in Formats.

tagSync(path)

tagSync(buffer, format)

Read the tags from the file at path synchronously. Returns a Tag. If errors occurred, throws an exception.

Read the tags from buffer assuming that it is a format file. See Formats

Tag

NOTE: A Tag object should NOT be created using new. Instead use tag() or tagSync()

A Tag object allows read-write access to all the meta-data fields. For valid field names see read() above.

To get a value, simply access the field -- tag.artist.

To set a value, assign a value to the field -- tag.year = 2012. You will have to call saveSync() to actually save the changes to the file on disc.

Large number of files

Due to TagLib's design, every Tag object in memory has to keep its backing file descriptor open. If you are dealing with a large number of files, you will soon run into problems because operating systems impose limits on how many files a process can have open simultaneously. If you want to only read tags, use read() instead as it will immediately close the file after the tag is read.

Tag.save(callback)

Save any changes in the Tag meta-data to disk asynchronously. callback will be invoked once the save is done, and should have a signature (err). err will be null if the save was successful, otherwise it will be an object with message having the error string and path having the file path.

Tag.saveSync()

Save any changes in the Tag meta-data to disk synchronously. Throws an exception if the save failed.

Tag.isEmpty()

Returns whether the tag is empty or not.

taglib.addResolvers([resolver1[, resolver2[, ...]]])

Adds JavaScript functions that will be called to resolve the filetype of a file. Each resolver will be added to the front of the resolver queue. So the last resolver will be called first. Multiple calls to addResolvers are allowed.

Each resolver must be a JavaScript function which takes a filename parameter and returns a format string. List of formats.

Formats {#formats}

Any place where node-taglib expects a format can be passed one of these (case-insensitive):

"MPEG"
"OGG"      - Ogg Vorbis
"OGG/FLAC" - Ogg FLAC
"FLAC"
"MPC"
"WV"
"SPX"      - Ogg Speex
"TTA"
"MP4"
"ASF"
"AIFF"     - RIFF AIFF
"WAV"      - RIFF WAV
"APE"
"MOD"
"S3M"
"IT"
"XM"

These correspond directly to the filetypes supported by TagLib. If the filetype cannot be determined, return anything other than one of these literals.

Asynchronous resolvers (which indicate the filetype via a callback rather than a return value) are not supported.

taglib.WITH_ASF

A boolean representing whether node-taglib supports ASF files. Depends on feature being enabled in TagLib.

taglib.WITH_MP4

A boolean representing whether node-taglib supports MP4 files. Depends on feature being enabled in TagLib.

Contributors are listed at: https://github.com/nikhilm/node-taglib/contributors