@catamphetamine/id3js
Version:
A modern ID3 parser written completely in JavaScript, making use of typed arrays and the HTML5 File API
33 lines (32 loc) • 949 B
JavaScript
import fetch from 'node-fetch';
import { parse } from '../reader/id3Tag.js';
import { LocalReader } from '../localReader.js';
import { RemoteReader } from '../remoteReader.js';
export { getImageDataUrl } from '../image/getImageDataUrl.js';
/**
* Parses ID3 tags from a given reader
* @param {Reader} reader Reader to use
* @return {Promise<ID3Tag>}
*/
export async function fromReader(reader) {
await reader.open();
const tags = await parse(reader);
await reader.close();
return tags;
}
/**
* Parses ID3 tags from a local path
* @param {string} path Path to file
* @return {Promise<ID3Tag>}
*/
export async function fromPath(path) {
return fromReader(new LocalReader(path));
}
/**
* Parses ID3 tags from a specified URL
* @param {string} url URL to retrieve data from
* @return {Promise<ID3Tag>}
*/
export function fromUrl(url) {
return fromReader(new RemoteReader(url, fetch));
}