diff --git a/README.md b/README.md index 76f059e..443af35 100644 --- a/README.md +++ b/README.md @@ -1,110 +1,94 @@ -id3.js - Javascript ID3 tag parser -=== +## id3.js - Javascript ID3 tag parser -**id3.js** is a JavaScript library for reading and parsing ID3 tags of MP3 files. **id3.js** can parse both ID3v1 and ID3v2 tags within a browser or Node environment. It also supports reading from local files (Node-only), same-origin URLs (AJAX) and File instances (HTML5 File API). +**id3.js** is a JavaScript library for reading and parsing ID3 tags of MP3 +files. -AJAX -=== +It can parse both ID3v1 and ID3v2 tags within a browser or within Node. -```html - - -``` - -Here the MP3 is being requested by partial AJAX requests, such that only the ID3v1 and ID3v2 tags are read rather than the file as a whole. +Files can be read from the local disk (Node only), same-origin URLs +and `File` instances (HTML5 File API). -Local Files -=== +## Usage -First, install **id3.js** using NPM, the Node package manager. +Install: ``` -npm install id3js +$ npm i -S id3js ``` -Then use it like so: +### AJAX -```javascript -var id3 = require('id3js'); +You may parse ID3 tags of a remote MP3 by URL: -id3({ file: './track.mp3', type: id3.OPEN_LOCAL }, function(err, tags) { - // tags now contains your ID3 tags +```html + ``` -Note that here, the type is set to 'local' directly so that **id3.js** will attempt to read from the local file-system using `fs`. +This works by sending a `HEAD` request for the file and, based on the response, +sending subsequent `Range` requests for the ID3 tags. -This will **only work under NodeJS**. +This is rather efficient as there is no need for the entire file to be +downloaded. -File API (HTML5) -=== +### Local Files -```html - - +You may parse ID3 tags of a local file in Node: + +```ts +import * as id3 from './node_modules/id3js/id3.js'; + +id3.fromPath('./test.mp3').then((tags) => { + // tags now contains v1, v2 and merged tags +}); ``` -This will read the data from the File instance using slices, so the entire file is not loaded into memory but rather only the tags. +### File inputs (HTML5) -Format -=== +You may parse ID3 tags of a file input: -Tags are passed as an object of the following format: +```html + -```json -{ - "artist": "Song artist", - "title": "Song name", - "album": "Song album", - "year": "2013", - "v1": { - "title": "ID3v1 title", - "artist": "ID3v1 artist", - "album": "ID3v1 album", - "year": "ID3v1 year", - "comment": "ID3v1 comment", - "track": "ID3v1 track (e.g. 02)", - "version": 1.0 - }, - "v2": { - "artist": "ID3v2 artist", - "album": "ID3v2 album", - "version": [4, 0] - } -} -```` + +``` -The `v2` object will contain a variable number of fields, depending on what is defined in the file, whereas the `v1` object will always have the same fields (some of which may be null). +This will read the data from the File instance using slices, +so the entire file is not loaded into memory but rather only the tags. -Images -=== +## Images -On occasion, an MP3 may have an image embedded in the ID3v2 tag. If this is the case, it will be available through `v2.image`. This has a structure like so: +An MP3 may have images embedded in the ID3 tags. If this is the case, +they can be accessed through the `tag.images` property and will +look like so: ```json { - "type": "cover-front", - "mime": "image/jpeg", - "description": null, - "data": ArrayBuffer + "type": "cover-front", + "mime": "image/jpeg", + "description": null, + "data": ArrayBuffer } ``` -As you can see, the data is provided as an `ArrayBuffer`. To access it, you may use a `DataView` or typed array such as `Uint8Array`. +As you can see, the data is provided as an `ArrayBuffer`. +To access it, you may use a `DataView` or typed array such +as `Uint8Array`. -License -=== +## License MIT