Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Started work on vorbis support, improved tests. Bumped to v0.0.4.

  • Loading branch information...
commit 7c78c4881c04e1f0a2db1d5eaee72d0b6ba40812 1 parent d0bd580
@leetreveil authored
View
2  TODO
@@ -3,4 +3,6 @@ Update the index so it converts all metadata to a 'standard' e.g. any text field
e.g. 'Artist/Artist2/Artist3' should be converted to ['Artist','Artist2','Artist3']. track / disk no's should be
standardised too
+Should be able to parse PRIV frames
+
Allow users calling code from a utf-8 / 16 encoded .js file to watch for events with a symbol in the name.
View
24 lib/common.js
@@ -75,6 +75,30 @@ var decodeString = exports.decodeString = function decodeString(b, charset, star
}
};
+exports.PICTURE_TYPE = [
+ "Other",
+ "32x32 pixels 'file icon' (PNG only)",
+ "Other file icon",
+ "Cover (front)",
+ "Cover (back)",
+ "Leaflet page",
+ "Media (e.g. lable side of CD)",
+ "Lead artist/lead performer/soloist",
+ "Artist/performer",
+ "Conductor",
+ "Band/Orchestra",
+ "Composer",
+ "Lyricist/text writer",
+ "Recording Location",
+ "During recording",
+ "During performance",
+ "Movie/video screen capture",
+ "A bright coloured fish",
+ "Illustration",
+ "Band/artist logotype",
+ "Publisher/Studio logotype"
+];
+
exports.GENRES = ['Blues','Classic Rock','Country','Dance','Disco','Funk','Grunge','Hip-Hop',
'Jazz','Metal','New Age','Oldies','Other','Pop','R&B','Rap','Reggae','Rock',
'Techno','Industrial','Alternative','Ska','Death Metal','Pranks','Soundtrack',
View
81 lib/id3v1.js
@@ -1,49 +1,48 @@
var common = require('./common'),
findZero = common.findZero;
-var id3v1 = function(buffer){
- this.buffer = buffer;
+var id3v1 = function(stream){
+ this.stream = stream;
};
module.exports = id3v1;
-id3v1.prototype.parse = function(){
- var buffer = this.buffer,
- offset = buffer.length - 128,
- header = buffer.toString('binary', offset, offset + 3),
- tags = {};
-
- if ('TAG' !== header){
- return tags;
- }
-
- // Skip header
- offset += 3;
-
- // Title
- tags.title = buffer.toString('ascii', offset, findZero(buffer, offset, offset + 30));
- offset += 30;
-
- // Artist
- tags.artist = buffer.toString('ascii', offset, findZero(buffer, offset, offset + 30));
- offset += 30;
-
- // Album
- tags.album = buffer.toString('ascii', offset, findZero(buffer, offset, offset + 30));
- offset += 30;
+id3v1.prototype = new process.EventEmitter();
- // Year
- tags.year = buffer.toString('ascii', offset, findZero(buffer, offset, offset + 4));
- offset += 4;
-
- // Comment
- tags.comment = buffer.toString('ascii', offset, findZero(buffer, offset, offset + 28));
-
- // Track
- tags.track = buffer[buffer.length - 2];
-
- //Genre
- tags.genre = common.GENRES[buffer[buffer.length - 1]];
-
- return tags;
-};
+id3v1.prototype.parse = function(){
+ var self = this;
+
+ self.stream.on('data', function(data){
+ self.stream.on('end', function(){
+ if(self.stream.bufferSize >= 128){
+ var offset = data.length - 128;
+ var header = data.toString('utf8', offset, offset += 3);
+
+ if(header === 'TAG'){
+ var title = data.toString('ascii', offset, findZero(data, offset, offset += 30));
+ self.emit('title', title);
+
+ var artist = data.toString('ascii', offset, findZero(data, offset, offset += 30));
+ self.emit('artist', artist);
+
+ var album = data.toString('ascii', offset, findZero(data, offset, offset += 30));
+ self.emit('album', album);
+
+ var year = data.toString('ascii', offset, findZero(data, offset, offset += 4));
+ self.emit('year', year);
+
+ var comment = data.toString('ascii', offset, findZero(data, offset, offset + 28));
+ self.emit('comment', comment);
+
+ var track = data[data.length - 2];
+ self.emit('track', track);
+
+ var genre = common.GENRES[data[data.length - 1]];
+ self.emit('genre', genre);
+
+ self.emit('done');
+ }
+ }
+ });
+ });
+}
View
4 lib/id3v2.js
@@ -38,8 +38,8 @@ id3v2.prototype.parse = function(){
unsync: strtok.BITSET.get(v, 2, 7),
xheader: strtok.BITSET.get(v, 2, 6),
xindicator: strtok.BITSET.get(v, 2, 5),
- footer: isBitSetAt(v, 2 , 4),
- size: strtok.INT32SYNCSAFE.get(v,3)
+ footer: strtok.BITSET.get(v, 2, 4),
+ size: strtok.INT32SYNCSAFE.get(v, 3)
};
cb.major = id3.major;
View
28 lib/id3v2_frames.js
@@ -37,7 +37,7 @@ exports.readData = function readData (b, type, encoding, flags, major) {
break;
}
- pic.type = PICTURE_TYPE[b[offset]];
+ pic.type = common.PICTURE_TYPE[b[offset]];
offset += 1;
pic.description = decodeString(b, encoding, offset, findZero(b, offset, length));
@@ -115,28 +115,4 @@ exports.readData = function readData (b, type, encoding, flags, major) {
lyrics.text = lyrics.text.text;
return lyrics;
}
-};
-
-var PICTURE_TYPE = exports.PICTURE_TYPE = [
- "Other",
- "32x32 pixels 'file icon' (PNG only)",
- "Other file icon",
- "Cover (front)",
- "Cover (back)",
- "Leaflet page",
- "Media (e.g. lable side of CD)",
- "Lead artist/lead performer/soloist",
- "Artist/performer",
- "Conductor",
- "Band/Orchestra",
- "Composer",
- "Lyricist/text writer",
- "Recording Location",
- "During recording",
- "During performance",
- "Movie/video screen capture",
- "A bright coloured fish",
- "Illustration",
- "Band/artist logotype",
- "Publisher/Studio logotype"
-];
+};
View
6 lib/id4.js
@@ -13,7 +13,7 @@ id4.prototype = new process.EventEmitter();
id4.prototype.parse = function() {
var self = this,
- metaAtomsTotal = 0;
+ metaAtomsTotal = 0;
strtok.parse(self.stream, function(v,cb){
//the very first thing we expect to see is the first atom's length
@@ -47,16 +47,14 @@ id4.prototype.parse = function() {
//only process atoms that fall under the ilst atom (metadata)
if (typeof v === 'object' && cb.atomContainer ==='ilst'){
var result = processMetaAtom(v, cb.atomName);
-
metaAtomsTotal += cb.atomLength;
-
self.emit(cb.atomName, result);
}
//expect the atom name next
if (!cb.atomLength || cb.atomLength === -1){
cb.atomLength = v;
- return new strtok.StringType(4, 'ascii');
+ return new strtok.StringType(4, 'binary');
}
cb.atomLength = -1;
View
48 lib/index.js
@@ -10,7 +10,8 @@ ID3File.prototype.parse = function() {
metadata = STANDARDMETADATA;
this.stream.once('data', function(result){
- var version = 'id3v1';
+ var version = 'id3v1'; //default to id3v1.1 if we cannot detect any other tags
+
if ('ID3' === result.toString('binary', 0, 3)) {
version = 'id3v2';
} else if ('ftypM4A' === result.toString('binary', 4, 11)) {
@@ -24,13 +25,24 @@ ID3File.prototype.parse = function() {
var event = arguments[0];
var value = arguments[1];
- //emit original event
- self.emit(event, value);
-
+ if(event == 'done'){
+ self.emit('metadata', metadata);
+ self.emit('done');
+ return;
+ }
+
+ self.emit(event, value); //emit original event
+
+ //before using the lookup table check to see if the event can be
+ //mapped directly to the stdmetadata
+ if(STANDARDMETADATA.hasOwnProperty(event)){
+ metadata[event] = value;
+ }
+
//rewrite to new alias
var mappedTo;
for(var i in MAPPINGS){
- if (MAPPINGS.hasOwnProperty(i)) {
+ if(MAPPINGS.hasOwnProperty(i)) {
var current = MAPPINGS[i];
if(current.from.indexOf(event) > -1){
mappedTo = current.to;
@@ -38,39 +50,29 @@ ID3File.prototype.parse = function() {
}
}
}
-
- self.emit(mappedTo, value);
-
+
+ //don't emit events that have already been emitted
+ if(mappedTo !== event){
+ self.emit(mappedTo, value);
+ }
+
if(metadata[mappedTo] !== undefined){
metadata[mappedTo] = value;
}
};
+
processor.parse();
//re-emitting the same data event so the correct id3 processor picks up the stream from the start
//is it possible that the id3 processor could pick up the NEXT event before the first one is re-emitted?
self.stream.emit('data', result);
});
-
- var done = false;
-
- self.on('done', function(){
- self.emit('metadata', metadata);
- done = true;
- });
-
- //for legacy reasons, this should be removed once all processors emit done events themselves
- self.stream.on('end', function(){
- if(!done){
- self.emit('metadata', metadata);
- }
- });
};
var STANDARDMETADATA = {title : '', artist : '', albumartist : '', album : '',
year : '', track : '', disk : '', genre : ''};
-//mappings for common metadata types(id3v2.3,id3v2.2,id4)
+//mappings for common metadata types(id3v2.3, id3v2.2, id4)
var MAPPINGS = [
{'to' : 'title', 'from' : ["TIT2", "TT2", "©nam"] },
{'to' : 'artist', 'from' : ["TPE1", "TP1", "©ART"] },
View
169 lib/vorbis.js
@@ -0,0 +1,169 @@
+var strtok = require('strtok'),
+ fs = require('fs'),
+ sys = require('sys'),
+ common = require('./common'),
+ isBitSetAt = common.isBitSetAt;
+
+var vorbis = function(stream){
+ this.stream = stream;
+};
+
+module.exports = vorbis;
+
+vorbis.prototype = new process.EventEmitter();
+
+vorbis.prototype.parse = function() {
+ var self = this;
+
+ strtok.parse(self.stream, function(v,cb){
+ if(v === undefined){
+ //read vorbis header
+ return new strtok.BufferType(27);
+ }
+
+ if (cb.readSegments){
+ cb.readSegments = false;
+ //ignore the segments and read header id '1vorbis' etc
+ return new strtok.BufferType(7);
+ }
+
+ if (cb.idHeader){
+ cb.idHeader = false;
+ //now read metadata frame
+ return new strtok.BufferType(27);
+ }
+
+ if (cb.vendorLen){
+ cb.vendorLen = false;
+
+ cb.vendorString = true;
+ return new strtok.StringType(v);
+ }
+
+ if (cb.vendorString){
+ cb.vendorString = false;
+
+ cb.commentCount = true;
+ return strtok.UINT32_LE;
+ }
+
+ if (cb.commentCount){
+ cb.commentCount = false;
+ cb.commentsRead = 0;
+
+ //now read the length of the first comment
+ cb.commentLength = true;
+ return strtok.UINT32_LE;
+ }
+
+ if (cb.commentLength){
+ cb.commentLength = false;
+ cb.comment = true;
+ return new strtok.StringType(v);
+ }
+
+ if(cb.comment){
+ cb.comment = false;
+ cb.commentsRead++;
+
+ if(cb.commentsRead === cb.commentCount){
+ return strtok.DONE;
+ }
+
+ var split = v.split('=');
+
+ console.log(split);
+
+ if(split[0] === 'METADATA_BLOCK_PICTURE'){
+
+ console.log(cb.commentLength);
+ var picture = {},
+ decoded = new Buffer(split[1], 'base64'),
+ offset = 0;
+
+ picture.format = common.PICTURE_TYPE[strtok.UINT32_BE.get(decoded, 0)];
+ offset += 4;
+ var mimeLen = strtok.UINT32_BE.get(decoded, offset);
+ offset += 4;
+ picture.type = decoded.toString('utf-8', offset, offset + mimeLen);
+ offset += mimeLen;
+ var descLen = strtok.UINT32_BE.get(decoded, offset);
+ offset += 4;
+ picture.description = decoded.toString('utf-8', offset, offset + descLen);
+ offset += descLen;
+ picture.width = strtok.UINT32_BE.get(decoded, offset);
+ offset += 4;
+ picture.height = strtok.UINT32_BE.get(decoded, offset);
+ offset += 4;
+ picture.colour_depth = strtok.UINT32_BE.get(decoded, offset);
+ offset += 4;
+ picture.indexed_color = strtok.UINT32_BE.get(decoded, offset);
+ offset += 4;
+ var picDataLen = strtok.UINT32_BE.get(decoded, offset);
+ offset += 4;
+
+ console.log(picDataLen);
+ console.log(offset + picDataLen);
+ console.log(decoded.length);
+ console.log(decoded.length - picDataLen);
+ picture.data = decoded.slice(offset);
+
+
+ split[1] = picture;
+
+ console.log(picture.data.length);
+ }
+
+
+ self.emit(split[0].toUpperCase(), split[1]);
+ cb.commentLength = true;
+ return strtok.UINT32_LE;
+ }
+
+ //header id
+ if (typeof v === 'object' && v.length === 7){
+ //identification header (skip);
+ if(v[0] === 1){
+ cb.idHeader = true;
+ return new strtok.BufferType(23);
+ }
+ //metadata header
+ if(v[0] === 3){
+ //read vendor length
+ cb.vendorLen = true;
+ return strtok.UINT32_LE;
+ }
+ }
+
+ //parse vorbis header
+ if (typeof v === 'object' && v.length === 27){
+ var header = {
+ type: v.toString('utf-8',0,4),
+ version: v[4],
+ packet_flag: readHeaderPacketFlag(v,5),
+ pcm_sample_pos: 'not_implemented',
+ stream_serial_num: strtok.UINT32_LE.get(v,14),
+ page_number: strtok.UINT32_LE.get(v,18),
+ check_sum: strtok.UINT32_LE.get(v,22),
+ segments: v[26]
+ };
+
+ //read segment table
+ cb.readSegments = true;
+ return new strtok.BufferType(header.segments);
+ }
+ });
+};
+
+var readHeaderPacketFlag = function(buffer, offset){
+ if(isBitSetAt(buffer,offset,0)){
+ return 'continued';
+ }
+ if(isBitSetAt(buffer,offset,1)){
+ return 'first';
+ }
+ if(isBitSetAt(buffer,offset,2)){
+ return 'last';
+ }
+ return '';
+}
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "musicmetadata",
"description": "Music metadata library for node, using pure Javascript.",
- "version": "0.0.3",
+ "version": "0.0.4",
"author": "Lee Treveil",
"engine": [ "node >=0.3.1" ],
"dependencies": {
View
BIN  test/samples/vorbis.ogg
Binary file not shown
View
54 test/test-id3v1.1.js
@@ -0,0 +1,54 @@
+var id3 = require('../lib/index'),
+ fs = require('fs');
+
+exports['id3v1.1'] = function(test) {
+ test.numAssertions = 13;
+ var parser = new id3(fs.createReadStream('samples/id3v1.mp3'));
+
+ parser.on('title', function(result) {
+ test.equal(result, 'Blood Sugar', 'title is not correct')
+ });
+
+ parser.on('artist', function(result) {
+ test.equal(result, 'Pendulum', 'artist is not correct');
+ });
+
+ parser.on('album', function(result) {
+ test.equal(result, 'Blood Sugar (Single)', 'album is not correct');
+ });
+
+ parser.on('year', function(result) {
+ test.equal(result,'2007', 'year is not correct');
+ });
+
+ parser.on('comment', function(result) {
+ test.equal(result, 'abcdefg', 'comment is not correct');
+ });
+
+ parser.on('track', function(result) {
+ test.equal(result, 1, 'track is not correct');
+ });
+
+ parser.on('genre', function(result) {
+ test.equal(result,'Electronic', 'genre is not correct');
+ });
+
+ parser.on('done', function(){
+ test.finish();
+ });
+
+ parser.on('metadata', function(result) {
+ test.equal(result.title, 'Blood Sugar');
+ test.equal(result.artist, 'Pendulum');
+ test.equal(result.album, 'Blood Sugar (Single)');
+ test.equal(result.year, 2007);
+ test.equal(result.track, 1);
+ test.equal(result.genre, 'Electronic');
+ });
+
+ parser.parse();
+};
+
+if (module == require.main) {
+ require('async_testing').run(__filename, process.ARGV);
+}
View
21 test/test-id3v1.js
@@ -1,21 +0,0 @@
-var id3 = require('../lib/id3v1'),
- fs = require('fs');
-
-exports['id3v1'] = function(test) {
- test.numAssertions = 6;
- var id3v1 = new id3(fs.readFileSync('samples/id3v1.mp3'));
- var tags = id3v1.parse();
-
- test.equal(tags.title, 'Blood Sugar', 'title is not correct');
- test.equal(tags.artist, 'Pendulum', 'artist is not correct');
- test.equal(tags.album, 'Blood Sugar (Single)', 'album is not correct');
- test.equal(tags.comment, 'abcdefg', 'comment is not correct');
- test.equal(tags.genre,'Electronic', 'genre is not correct');
- test.equal(tags.year,'2007', 'year is not correct');
-
- test.finish();
-};
-
-if (module == require.main) {
- require('async_testing').run(__filename, process.ARGV);
-}
View
13 test/test-id3v2.2.js
@@ -1,11 +1,20 @@
-var id3v2 = require('../lib/id3v2'),
+var id3v2 = require('../lib/index'),
fs = require('fs');
exports['id3v2.2'] = function(test){
- test.numAssertions = 26;
+ test.numAssertions = 32;
var id3 = new id3v2(fs.createReadStream('samples/id3v2.2.mp3'));
+ id3.on('metadata', function(result){
+ test.equal(result.title, 'You Are The One');
+ test.equal(result.artist, 'Shiny Toy Guns');
+ test.equal(result.album, 'We Are Pilots');
+ test.equal(result.year, 2006);
+ test.equal(result.track, '1/11');
+ test.equal(result.genre, 'Alternative');
+ });
+
id3.on('TP1', function(result){
test.equal(result, 'Shiny Toy Guns', 'TP1 failed');
});
View
15 test/test-id3v2.3.js
@@ -1,11 +1,22 @@
-var id3v2 = require('../lib/id3v2'),
+var id3v2 = require('../lib/index'),
fs = require('fs');
exports['id3v2.3'] = function(test) {
- test.numAssertions = 13;
+ test.numAssertions = 21;
var id3 = new id3v2(fs.createReadStream('samples/id3v2.3.mp3'));
+ id3.on('metadata', function(result){
+ test.equal(result.title, 'Home');
+ test.equal(result.artist, 'Explosions In The Sky/Another/And Another');
+ test.equal(result.albumartist, 'Soundtrack');
+ test.equal(result.album, 'Friday Night Lights [Original Movie Soundtrack]');
+ test.equal(result.year, 2004);
+ test.equal(result.track, 5);
+ test.equal(result.disk, '1/1');
+ test.equal(result.genre, 'Soundtrack');
+ });
+
id3.on('TALB', function(result){
test.equal(result, 'Friday Night Lights [Original Movie Soundtrack]', 'TALB failed');
});
View
43 test/test-id4.js
@@ -1,11 +1,22 @@
-var id4 = require('../lib/id4'),
+var id4 = require('../lib/index'),
fs = require('fs');
exports['id4'] = function(test) {
- test.numAssertions = 15;
+ test.numAssertions = 23;
var id3 = new id4(fs.createReadStream('samples/id4.m4a'));
+ id3.on('metadata', function(result){
+ test.equal(result.title, 'Voodoo People (Pendulum Remix)');
+ test.equal(result.artist, 'The Prodigy');
+ test.equal(result.albumartist, 'Pendulum');
+ test.equal(result.album, 'Voodoo People');
+ test.equal(result.year, 2005);
+ test.deepEqual(result.track, [1,0]);
+ test.deepEqual(result.disk, [1,1]);
+ test.equal(result.genre, 'Electronic');
+ });
+
id3.on('trkn', function(result){
test.deepEqual(result, [1,0], 'trkn failed');
});
@@ -26,36 +37,36 @@ exports['id4'] = function(test) {
test.equal(result, 256, 'stik failed');
});
- id3.on('©alb', function(result){
- test.equal(result, 'Voodoo People', '©alb failed');
+ id3.on('©alb', function(result){
+ test.equal(result, 'Voodoo People', '©alb failed');
});
- id3.on('©ART', function(result){
- test.equal(result, 'The Prodigy', '©ART failed');
+ id3.on('©ART', function(result){
+ test.equal(result, 'The Prodigy', '©ART failed');
});
id3.on('aART', function(result){
test.equal(result, 'Pendulum', 'aART failed');
});
- id3.on('©cmt', function(result){
- test.equal(result, '(Pendulum Remix)', '©cmt failed');
+ id3.on('©cmt', function(result){
+ test.equal(result, '(Pendulum Remix)', '©cmt failed');
});
- id3.on('©wrt', function(result){
- test.equal(result, 'Liam Howlett', '©wrt failed');
+ id3.on('©wrt', function(result){
+ test.equal(result, 'Liam Howlett', '©wrt failed');
});
- id3.on('©nam', function(result){
- test.equal(result, 'Voodoo People (Pendulum Remix)', '©nam failed');
+ id3.on('©nam', function(result){
+ test.equal(result, 'Voodoo People (Pendulum Remix)', '©nam failed');
});
- id3.on('©too', function(result){
- test.equal(result, 'Lavf52.36.0', '©too failed');
+ id3.on('©too', function(result){
+ test.equal(result, 'Lavf52.36.0', '©too failed');
});
- id3.on('©day', function(result){
- test.equal(result, 2005, '©day failed');
+ id3.on('©day', function(result){
+ test.equal(result, 2005, '©day failed');
});
id3.on('covr', function(result){
View
79 test/test-index.js
@@ -1,79 +0,0 @@
-var index = require('../lib/index'),
- fs = require('fs');
-
-var id3 = new index(fs.createReadStream('samples/id3v2.3.mp3'));
-
-exports['index'] = function(test) {
- test.numAssertions = 22;
-
- id3.on('album', function(result){
- test.equal(result, 'Friday Night Lights [Original Movie Soundtrack]', 'album failed');
- });
-
- id3.on('artist', function(result){
- test.equal(result, 'Explosions In The Sky/Another/And Another', 'artist failed');
- });
-
- id3.on('albumartist', function(result){
- test.equal(result, 'Soundtrack', 'albumartist failed');
- });
-
- id3.on('composer', function(result){
- test.equal(result, 'Explosions in the Sky', 'composer failed');
- });
-
- id3.on('disk', function(result){
- test.equal(result, '1/1', 'composer failed');
- });
-
- id3.on('genre', function(result){
- test.equal(result, 'Soundtrack', 'genre failed');
- });
-
- id3.on('title', function(result){
- test.equal(result, 'Home', 'title failed');
- });
-
- id3.on('track', function(result){
- test.equal(result, 5, 'track failed');
- });
-
- id3.on('year', function(result){
- test.equal(result, 2004, 'year failed');
- });
-
- id3.on('picture', function(result){
- test.equal(result.format, 'image/jpg', 'picture format failed');
- test.equal(result.type, 'Cover (front)', 'picture type failed');
- test.equal(result.description, '', 'picture description failed');
- test.equal(result.data.length, 80938, 'picture length failed');
- });
-
- id3.on('metadata', function(result){
- test.equal(result.title, 'Home', 'metadata title failed');
- test.equal(result.albumartist, 'Soundtrack', 'metadata albumartist failed');
- test.equal(result.artist, 'Explosions In The Sky/Another/And Another', 'metadata artist failed');
- test.equal(result.album, 'Friday Night Lights [Original Movie Soundtrack]', 'metadata album failed');
- test.equal(result.disk, '1/1', 'metdata disk failed');
- test.equal(result.genre, 'Soundtrack', 'metadata genre failed');
- test.equal(result.track, 5, 'metadata track failed');
- test.equal(result.year, 2004, 'metadata year failed');
- });
-
- id3.on('done', function(result){
- test.ok(true);
- });
-
- //TODO: implement id3.on('done') everywhere so we don't have to wait a long time for the test
- //can't use stream.on('end') because this could occur before the test has chance to capture
- //all tests
- setTimeout(function() {
- test.finish();
- },1000);
-
- id3.parse();
-};
-
-if (module == require.main) {
- require('async_testing').run(__filename, process.ARGV);
-}
View
87 test/test-vorbis.js
@@ -0,0 +1,87 @@
+var vb = require('../lib/vorbis'),
+ fs = require('fs');
+
+exports['vorbis'] = function(test) {
+ test.numAssertions = 13;
+
+ var vorbis = new vb(fs.createReadStream('samples/vorbis.ogg'));
+
+ vorbis.on('TRACKTOTAL', function(result){
+ test.equal(result, 12, 'TRACKTOTAL failed');
+ });
+
+ vorbis.on('ALBUM', function(result){
+ test.equal(result, 'Nevermind', 'ALBUM failed');
+ });
+
+ vorbis.on('ARTIST', function(result){
+ test.equal(result, 'Nirvana', 'ARTIST failed');
+ });
+
+ var comCounter = 0;
+ vorbis.on('COMMENT', function(result){
+ switch(comCounter){
+ case 0:
+ test.equal(result, 'Nirvana\'s Greatest Album', 'COMMENT 1 failed');
+ break;
+ case 1:
+ test.equal(result, 'And their greatest song', 'COMMENT 2 failed');
+ break;
+ }
+ comCounter++;
+ });
+
+ var genCounter = 0;
+ vorbis.on('GENRE', function(result){
+ switch(genCounter){
+ case 0:
+ test.equal(result, 'Grunge', 'GENRE 1 failed');
+ break;
+ case 1:
+ test.equal(result, 'Alternative', 'GENRE 2 failed');
+ break;
+ }
+ genCounter++;
+ });
+
+ vorbis.on('TITLE', function(result){
+ test.equal(result, 'In Bloom', 'TITLE failed');
+ });
+
+ vorbis.on('ALBUMARTIST', function(result){
+ test.equal(result, 'Nirvana', 'ALBUMARTIST failed');
+ });
+
+ vorbis.on('DISCNUMBER', function(result){
+ test.equal(result, '1', 'DISCNUMBER failed');
+ });
+
+ vorbis.on('DATE', function(result){
+ test.equal(result, '1991', 'DATE failed');
+ });
+
+ vorbis.on('TRACKNUMBER', function(result){
+ test.equal(result, '1', 'DISCNUMBER failed');
+ });
+
+ vorbis.on('METADATA_BLOCK_PICTURE', function(result){
+ test.equal(result.format, 'Cover (front)', 'METADATA_BLOCK_PICTURE format failed');
+ test.equal(result.type, 'image/jpeg', 'METADATA_BLOCK_PICTURE type failed');
+
+ fs.writeFileSync('test.jpg', result.data);
+
+ test.equal(result.data.length, 30966);
+
+
+
+ test.finish();
+ });
+
+
+
+ vorbis.parse();
+}
+
+if (module == require.main) {
+ require('async_testing').run(__filename, process.ARGV);
+}

0 comments on commit 7c78c48

Please sign in to comment.
Something went wrong with that request. Please try again.