1
0
mirror of synced 2026-05-22 14:43:19 +00:00

Removed utf-8 BOM

This commit is contained in:
Lee Treveil
2010-11-10 22:16:21 +00:00
parent 692cb5994d
commit 07d5d52c0e
15 changed files with 135 additions and 46 deletions
+1 -1
View File
@@ -1 +1 @@
test
test
+1 -1
View File
@@ -1,4 +1,4 @@
exports.findZero = function (buffer, start, end) {
exports.findZero = function (buffer, start, end) {
var i = start;
while (buffer[i] !== 0) {
if (i >= end) {
+1 -1
View File
@@ -1,4 +1,4 @@
var common = require('./common'),
var common = require('./common'),
findZero = common.findZero;
var id3v1 = function(buffer){
+1 -1
View File
@@ -1,4 +1,4 @@
var strtok = require('strtok'),
var strtok = require('strtok'),
fs = require('fs'),
parser = require('./id3v2_frames'),
common = require('./common'),
+1 -1
View File
@@ -1,4 +1,4 @@
var Buffer = require('buffer').Buffer,
var Buffer = require('buffer').Buffer,
strtok = require('strtok'),
common = require('./common'),
findZero = common.findZero,
+1 -1
View File
@@ -1,4 +1,4 @@
var strtok = require('strtok'),
var strtok = require('strtok'),
common = require('./common'),
fs = require('fs'),
sys = require('sys');
+48 -33
View File
@@ -1,4 +1,4 @@
var ID3File = function(stream) {
var ID3File = function(stream) {
this.stream = stream;
};
module.exports = ID3File;
@@ -6,7 +6,8 @@ module.exports = ID3File;
ID3File.prototype = new process.EventEmitter();
ID3File.prototype.parse = function() {
var self = this;
var self = this,
metadata = {};
//convert to this.stream.once when updated to nodejs v.0.3.0 >
var callback = function(result){
self.stream.removeListener('data', callback);
@@ -18,44 +19,58 @@ ID3File.prototype.parse = function() {
}
return 'id3v1';
}
var version = version();
var module = require('../lib/' + version);
var processor = new module(self.stream);
var version = version();
var module = require('../lib/' + version);
var processor = new module(self.stream);
processor.emit = function() {
var event = arguments[0];
var value = arguments[1];
//emit original event
self.emit(event, value);
//rewrite to new alias
for(var i in MAPPINGS){
var current = MAPPINGS[i];
if(current.from.indexOf(event) > -1){
self.emit(current.to, value);
processor.emit = function() {
var event = arguments[0];
var value = arguments[1];
//emit original event
self.emit(event, value);
//rewrite to new alias
var mappedTo;
for(var i in MAPPINGS){
var current = MAPPINGS[i];
if(current.from.indexOf(event) > -1){
mappedTo = current.to;
break;
}
}
}
}
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);
self.emit(mappedTo, value);
if(STANDARDMETADATA.indexOf(mappedTo) > -1){
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);
}
this.stream.on('data', callback);
this.stream.on('end', function(){
self.emit('metadata', metadata);
});
}
var STANDARDMETADATA = ['title', 'artist', 'albumartist', 'album',
'year', 'track', 'disk', 'genre', 'picture'];
//mappings for common metadata types(id3v2.3,id3v2.2,id4)
var MAPPINGS = [
{'to' : 'title', 'from' : ["TIT2", "TT2", "©nam"] },
{'to' : 'artist', 'from' : ["TPE1", "TP1", "©ART"] },
{'to' : 'title', 'from' : ["TIT2", "TT2", "©nam"] },
{'to' : 'artist', 'from' : ["TPE1", "TP1", "©ART"] },
{'to' : 'albumartist', 'from' : ["TPE2", "TP2", "aART"] },
{'to' : 'album', 'from' : ["TALB", "TAL", "©alb"] },
{'to' : 'year', 'from' : ["TYER", "TYE", "©day"] },
{'to' : 'comment', 'from' : ["COMM", "COM", "©cmt"] },
{'to' : 'track', 'from' : ["TRCK", "TRK", "trkn"] },
{'to' : 'disk', 'from' : ["TPOS", "TPA", "disk"] },
{'to' : 'genre', 'from' : ["TCON", "TCO", "©gen", "gnre"] },
{'to' : 'picture', 'from' : ["APIC", "PIC", "covr"] },
{'to' : 'composer', 'from' : ["TCOM", "TCM", "©wrt"] },
{'to' : 'album', 'from' : ["TALB", "TAL", "©alb"] },
{'to' : 'year', 'from' : ["TYER", "TYE", "©day"] },
{'to' : 'comment', 'from' : ["COMM", "COM", "©cmt"] },
{'to' : 'track', 'from' : ["TRCK", "TRK", "trkn"] },
{'to' : 'disk', 'from' : ["TPOS", "TPA", "disk"] },
{'to' : 'genre', 'from' : ["TCON", "TCO", "©gen", "gnre"] },
{'to' : 'picture', 'from' : ["APIC", "PIC", "covr"] },
{'to' : 'composer', 'from' : ["TCOM", "TCM", "©wrt"] }
];
+1 -1
View File
@@ -1,4 +1,4 @@
{
{
"name": "id3",
"description": "A ID3 library for node, using pure Javascript.",
"version": "0.0.2",
+13 -1
View File
@@ -1,9 +1,16 @@
var strtok = require('strtok'),
var strtok = require('strtok'),
fs = require('fs'),
id4 = require('../lib/id4'),
id3v2 = require('../lib/id3v2'),
ID3File = require('../lib/index'),
genres = require('../lib/common').GENRES;
var Nodelint = require('Nodelint');
Nodelint('test-id3v1.js', function(e, results){
console.log(results);
})
//var stream = fs.createReadStream('sample4.m4a');
//var testid3 = new id4(stream);
@@ -18,6 +25,11 @@ tst.on('artist', function(result){
tst.on('genre', function(result){
console.log(result);
})
tst.on('metadata', function(result){
console.log(result);
})
tst.parse();
+1 -1
View File
@@ -1,4 +1,4 @@
var id3 = require('../lib/id3v1'),
var id3 = require('../lib/id3v1'),
fs = require('fs');
var id3v1 = new id3(fs.readFileSync('samples/id3v1.mp3'));
+1 -1
View File
@@ -1,4 +1,4 @@
var id3 = require('../lib/id3v2'),
var id3 = require('../lib/id3v2'),
testCase = require('nodeunit').testCase;
module.exports = testCase({
+1 -1
View File
@@ -1,4 +1,4 @@
var id3 = require('../lib/id3v2'),
var id3 = require('../lib/id3v2'),
testCase = require('nodeunit').testCase;
module.exports = testCase({
+1 -1
View File
@@ -1,4 +1,4 @@
var id3 = require('../lib/id3v2'),
var id3 = require('../lib/id3v2'),
testCase = require('nodeunit').testCase;
module.exports = testCase({
+1 -1
View File
@@ -1,4 +1,4 @@
var id4 = require('../lib/id4'),
var id4 = require('../lib/id4'),
testCase = require('nodeunit').testCase;
module.exports = testCase({
+62
View File
@@ -0,0 +1,62 @@
var id3 = require('../lib/index'),
testCase = require('nodeunit').testCase;
module.exports = testCase({
setUp: function(){
this.id3 = new id3(require('fs').createReadStream('samples/id3v2.3.mp3'));
this.executor = function(frameName, expected, test, deep){
test.expect(1);
this.id3.on(frameName, function(result){
(deep) ? test.deepEqual(result, expected) : test.equal(result, expected);
test.done();
});
this.id3.parse();
};
},
'album': function(test){
this.executor('album', 'Friday Night Lights [Original Movie Soundtrack]', test);
},
'artist': function(test){
this.executor('artist', 'Explosions In The Sky/Another/And Another', test);
},
'albumartist': function(test){
this.executor('albumartist', 'Soundtrack', test);
},
'composer': function(test){
this.executor('composer', 'Explosions in the Sky', test);
},
'disk': function(test){
this.executor('disk', '1/1', test);
},
'genre': function(test){
this.executor('genre', 'Soundtrack', test);
},
'title': function(test){
this.executor('title', 'Home', test);
},
'track': function(test){
this.executor('track', 5, test);
},
'year': function(test){
this.executor('year', 2004, test);
},
'picture': function(test){
test.expect(4);
this.id3.on('picture', function(result){
test.equal(result.format, 'image/jpg');
test.equal(result.type, 'Cover (front)');
test.equal(result.description, '');
test.equal(result.data.length, 80938);
test.done();
});
this.id3.parse();
},
'metadata': function(test){
test.expect(2);
this.id3.on('metadata', function(result){
test.equal(result.albumartist, 'Soundtrack');
test.done();
});
this.id3.parse();
}
});