ID3 Tag Parser

3.0.0 · active · verified Tue Apr 21

id3-parser is a pure JavaScript library designed for parsing ID3 tags (versions 1 and 2.3) from MP3 audio files. The current stable version, 3.0.0, requires Node.js version 16 or newer. It offers a straightforward API with a primary `parse` function that intelligently detects and extracts metadata, alongside specific functions like `parseV1Tag` and `parseV2Tag` for targeted parsing. The library ships with TypeScript types, ensuring good developer experience in modern TypeScript and JavaScript environments. While primarily used in Node.js for server-side processing, it includes utilities (`convertFileToBuffer`, `fetchFileAsBuffer`) that facilitate its use in browser environments when bundled with tools like Webpack. Its key differentiators include its focus on robust parsing of common ID3v1 and ID3v2.3 frames, providing comprehensive metadata such as artist, album, title, year, comments, lyrics, and embedded cover art from binary data. The release cadence is typically driven by bug fixes, maintenance, and alignment with modern JavaScript ecosystem standards.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to fetch and parse ID3 tags from a remote MP3 URL, applicable to both browser (with utilities) and Node.js environments.

import parse, { fetchFileAsBuffer } from 'id3-parser';

// This example demonstrates parsing a remote MP3 file in a browser-like environment.
// In a Node.js environment, you would typically read a file into a Buffer or Uint8Array directly.

async function processMp3File(url: string) {
  console.log(`Attempting to fetch and parse: ${url}`);
  try {
    // fetchFileAsBuffer handles fetching the URL and converting the response to a buffer
    // that id3-parser can process.
    const buffer = await fetchFileAsBuffer(url);
    const tags = parse(buffer);

    if (tags) {
      console.log('ID3 Tags found:');
      console.log(`  Title: ${tags.title || 'N/A'}`);
      console.log(`  Artist: ${tags.artist || 'N/A'}`);
      console.log(`  Album: ${tags.album || 'N/A'}`);
      console.log(`  Year: ${tags.year || 'N/A'}`);
      if (tags.image) {
        console.log(`  Cover Art: ${tags.image.mime}, size ${tags.image.data.byteLength} bytes`);
      }
      if (tags.comments && tags.comments.length > 0) {
        console.log(`  Comments: ${tags.comments[0].value.substring(0, 50)}...`);
      }
    } else {
      console.log('No ID3 tags found in the file.');
    }
  } catch (error) {
    console.error(`Failed to parse MP3 from ${url}:`, error);
  }
}

// Replace with a publicly accessible, small MP3 file URL for testing.
// Note: CORS policies might prevent fetching from arbitrary domains in browsers.
const exampleMp3Url = 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3';
processMp3File(exampleMp3Url);

// Example of how you might parse a Node.js Buffer (assuming `fs` and `path` are available)
// import * as fs from 'fs';
// import * as path from 'path';
// const localFilePath = path.join(__dirname, 'path/to/your/audio.mp3');
// if (fs.existsSync(localFilePath)) {
//   const buffer = fs.readFileSync(localFilePath);
//   const tags = parse(buffer);
//   console.log('Local file tags:', tags);
// }

view raw JSON →