music-metadata
Advanced tools
Comparing version 0.8.0 to 0.8.1
@@ -17,2 +17,3 @@ 'use strict'; | ||
var AbstractID3Parser_1 = require("../id3v2/AbstractID3Parser"); | ||
var XingTag_1 = require("./XingTag"); | ||
/** | ||
@@ -68,3 +69,3 @@ * MPEG Audio Layer I/II/III frame header | ||
MpegFrameHeader.prototype.calcDuration = function (numFrames) { | ||
return Math.round(numFrames * (this.calcSamplesPerFrame() / this.samplingRate)); | ||
return numFrames * this.calcSamplesPerFrame() / this.samplingRate; | ||
}; | ||
@@ -159,46 +160,2 @@ MpegFrameHeader.prototype.calcSamplesPerFrame = function () { | ||
}; | ||
/** | ||
* Info Tag: Xing, LAME | ||
*/ | ||
MpegAudioLayer.InfoTagHeaderTag = new Token.StringType(4, 'ascii'); | ||
/** | ||
* LAME TAG value | ||
* Did not find any official documentation for this | ||
* Value e.g.: "3.98.4" | ||
*/ | ||
MpegAudioLayer.LameEncoderVersion = new Token.StringType(6, 'ascii'); | ||
/** | ||
* Info Tag | ||
* Ref: http://gabriel.mp3-tech.org/mp3infotag.html | ||
*/ | ||
MpegAudioLayer.XingInfoTag = { | ||
len: 136, | ||
get: function (buf, off) { | ||
return { | ||
// 4 bytes for HeaderFlags | ||
headerFlags: new Token.BufferType(4).get(buf, off), | ||
// 100 bytes for entry (NUMTOCENTRIES) | ||
// numToCentries: new strtok.BufferType(100).get(buf, off + 8), | ||
// FRAME SIZE | ||
// frameSize: strtok.UINT32_BE.get(buf, off + 108), | ||
numFrames: Token.UINT32_BE.get(buf, off + 4), | ||
numToCentries: new Token.BufferType(100).get(buf, off + 104), | ||
// the number of header APE_HEADER bytes | ||
streamSize: Token.UINT32_BE.get(buf, off + 108), | ||
// the number of header data bytes (from original file) | ||
vbrScale: Token.UINT32_BE.get(buf, off + 112), | ||
/** | ||
* LAME Tag, extends the Xing header format | ||
* First added in LAME 3.12 for VBR | ||
* The modified header is also included in CBR files (effective LAME 3.94), with "Info" instead of "XING" near the beginning. | ||
*/ | ||
// Initial LAME info, e.g.: LAME3.99r | ||
encoder: new Token.StringType(9, 'ascii').get(buf, off + 116), | ||
// Info Tag | ||
infoTag: Token.UINT8.get(buf, off + 125) >> 4, | ||
// VBR method | ||
vbrMethod: Token.UINT8.get(buf, off + 125) & 0xf | ||
}; | ||
} | ||
}; | ||
return MpegAudioLayer; | ||
@@ -229,3 +186,3 @@ }()); | ||
this.readDuration = options.duration; | ||
this.headerSize = tokenizer.offset; | ||
this.headerSize = tokenizer.position; | ||
this.format = { | ||
@@ -286,8 +243,4 @@ dataformat: 'mp3', | ||
} | ||
// mp3 files are only found in MPEG1/2 Layer 3 | ||
if ((header.version !== 1 && header.version !== 2) || header.layer !== 3) { | ||
_this.warnings.push("Parse error: mp3 files are only found in MPEG1/2 Layer 3"); | ||
return _this.sync(); | ||
} | ||
_this.format.dataformat = 'mp3'; | ||
// ToDo: this.format.dataformat = "MPEG-" + header.version + " Audio Layer " + Common.romanize(header.layer); | ||
_this.format.dataformat = "mp" + header.layer; | ||
_this.format.lossless = false; | ||
@@ -363,4 +316,4 @@ _this.format.bitrate = header.bitrate; | ||
var _this = this; | ||
return this.tokenizer.readToken(MpegAudioLayer.InfoTagHeaderTag).then(function (headerTag) { | ||
_this.offset += MpegAudioLayer.InfoTagHeaderTag.len; // 12 | ||
return this.tokenizer.readToken(XingTag_1.InfoTagHeaderTag).then(function (headerTag) { | ||
_this.offset += XingTag_1.InfoTagHeaderTag.len; // 12 | ||
switch (headerTag) { | ||
@@ -379,4 +332,4 @@ case 'Info': | ||
case 'LAME': | ||
return _this.tokenizer.readToken(MpegAudioLayer.LameEncoderVersion).then(function (version) { | ||
_this.offset += MpegAudioLayer.LameEncoderVersion.len; | ||
return _this.tokenizer.readToken(XingTag_1.LameEncoderVersion).then(function (version) { | ||
_this.offset += XingTag_1.LameEncoderVersion.len; | ||
_this.format.encoder = "LAME " + version; | ||
@@ -397,12 +350,18 @@ return _this.skipFrameData(_this.frame_size - _this.offset); | ||
var _this = this; | ||
return this.tokenizer.readToken(MpegAudioLayer.XingInfoTag).then(function (infoTag) { | ||
_this.offset += MpegAudioLayer.XingInfoTag.len; // 12 | ||
return this.tokenizer.readToken(XingTag_1.XingInfoTag).then(function (infoTag) { | ||
_this.offset += XingTag_1.XingInfoTag.len; // 12 | ||
_this.format.encoder = common_1.default.stripNulls(infoTag.encoder); | ||
if ((infoTag.headerFlags[3] & 0x01) === 1) { | ||
_this.format.duration = _this.audioFrameHeader.calcDuration(infoTag.numFrames); | ||
return infoTag; // Done | ||
/* ToDo: jump to end of stream | ||
if (infoTag.streamSize) { | ||
return this.skipFrameData(infoTag.streamSize - (4 + XingInfoTag.len)).then(() => { | ||
return infoTag; | ||
}); | ||
} | ||
*/ | ||
return infoTag; // Done ToDo: will get out-of sync | ||
} | ||
// frames field is not present | ||
var frameDataLeft = _this.frame_size - _this.offset; | ||
// ToDo: promise duration??? | ||
return _this.skipFrameData(frameDataLeft).then(function () { | ||
@@ -409,0 +368,0 @@ return infoTag; |
{ | ||
"name": "music-metadata", | ||
"description": "Streaming music metadata parser for node and the browser.", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"author": { | ||
@@ -59,20 +59,20 @@ "name": "Borewit", | ||
"fs-extra": "^4.0.1", | ||
"strtok3": "^1.1.3", | ||
"then-read-stream": "^0.9.5", | ||
"strtok3": "^1.2.0", | ||
"then-read-stream": "^0.9.6", | ||
"token-types": "^0.9.1" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.0.3", | ||
"@types/chai": "^4.0.4", | ||
"@types/es6-promise": "0.0.32", | ||
"@types/fs-extra": "^4.0.0", | ||
"@types/mocha": "^2.2.41", | ||
"@types/node": "^8.0.24", | ||
"@types/mocha": "^2.2.42", | ||
"@types/node": "^8.0.25", | ||
"chai": "^4.1.1", | ||
"coveralls": "^2.13.1", | ||
"mocha": "^3.5.0", | ||
"npm-run-all": "^4.0.2", | ||
"npm-run-all": "^4.1.0", | ||
"nyc": "^11.1.0", | ||
"source-map": "^0.5.6", | ||
"source-map": "^0.5.7", | ||
"ts-node": "^3.3.0", | ||
"tslint": "^5.6.0", | ||
"tslint": "^5.7.0", | ||
"typescript": "^2.5.1" | ||
@@ -79,0 +79,0 @@ }, |
251966
74
6191
Updatedstrtok3@^1.2.0
Updatedthen-read-stream@^0.9.6