UNPKG

3.87 kBMarkdownView Raw
1[![Build Status][travis-image]][travis-url] [![NPM version][npm-image]][npm-url] [![npm downloads][npm-downloads-image]][npm-url]
2
3Streaming music metadata parser for node and the browser.
4
5Installation
6------------
7Install via [npm](http://npmjs.org):
8
9```
10npm install musicmetadata
11```
12
13Or with [bower](http://bower.io) if you're in the browser:
14
15```
16bower install musicmetadata
17```
18
19If you're old'skool you can download the latest tar ball from https://github.com/leetreveil/musicmetadata/releases.
20
21
22Supports
23-----------------
24* mp3 (1.1, 2.2, 2.3, 2.4)
25* m4a (mp4)
26* vorbis (ogg, flac)
27* asf (wma, wmv)
28
29
30API
31-----------------
32```javascript
33var fs = require('fs');
34var mm = require('musicmetadata');
35
36// create a new parser from a node ReadStream
37var parser = mm(fs.createReadStream('sample.mp3'));
38
39// listen for the metadata event
40parser.on('metadata', function (result) {
41 console.log(result);
42});
43```
44
45This will output the standard music metadata:
46
47```javascript
48{ artist : ['Spor'],
49 album : 'Nightlife, Vol 5.',
50 albumartist : [ 'Andy C', 'Spor' ],
51 title : 'Stronger',
52 year : '2010',
53 track : { no : 1, of : 44 },
54 disk : { no : 1, of : 2 },
55 genre : ['Drum & Bass'],
56 picture : [ { format : 'jpg', data : <Buffer> } ],
57 duration : 302 // in seconds
58}
59```
60
61If you just want the artist - listen for the artist event:
62
63```javascript
64parser.on('artist', function (result) {
65 console.log(result);
66});
67```
68
69You can also listen for custom metadata types that are not part of the standard metadata as defined above. For example if you wanted to read the `TLEN` frame from a id3v2.x file you can do this:
70
71```javascript
72parser.on('TLEN', function (result) {
73 console.log(result);
74});
75```
76
77The ```done``` event will be raised when parsing has finished or an error has occurred. This could be
78used to disconnect from the stream as soon as parsing has finished, saving bandwidth.
79
80```javascript
81parser.on('done', function (err) {
82 if (err) throw err;
83 stream.destroy();
84});
85```
86
87You can also read the duration; reading the duration may be slow so only set this if you need to.
88```javascript
89var parser = mm(fs.createReadStream('sample.mp3'), { duration: true });
90```
91
92Note that in order to read the duration for streams that are not file streams, you must also pass the size of the file in bytes.
93```javascript
94var parser = mm(fs.createReadStream('sample.mp3'), { duration: true, fileSize: 26838 });
95```
96
97Licence
98-----------------
99
100(The MIT License)
101
102Copyright (c) 2014 Lee Treveil <leetreveil@gmail.com>
103
104Permission 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:
105
106The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
107
108THE 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.
109
110[npm-url]: https://npmjs.org/package/musicmetadata
111[npm-image]: https://badge.fury.io/js/musicmetadata.svg
112[npm-downloads-image]: http://img.shields.io/npm/dm/musicmetadata.svg
113
114[travis-url]: https://travis-ci.org/leetreveil/musicmetadata
115[travis-image]: https://api.travis-ci.org/leetreveil/musicmetadata.svg?branch=master