music-metadata
Advanced tools
Comparing version 0.8.1 to 0.8.2
@@ -52,3 +52,3 @@ "use strict"; | ||
.catch(function (err) { | ||
if (err === strtok3.EndOfFile) { | ||
if (err.message === strtok3.endOfFile) { | ||
return _this.metadata; | ||
@@ -55,0 +55,0 @@ } |
@@ -1,2 +0,1 @@ | ||
/// <reference types="node" /> | ||
import { ITokenizer } from "strtok3"; | ||
@@ -25,2 +24,3 @@ import { AbstractID3v2Parser } from "../id3v2/AbstractID3Parser"; | ||
private readDuration; | ||
private syncPeek; | ||
/** | ||
@@ -30,7 +30,9 @@ * Called after ID3 headers have been parsed | ||
_parse(tokenizer: ITokenizer, options: IOptions): Promise<INativeAudioMetadata>; | ||
sync(): Promise<void>; | ||
parseAudioFrameHeader(buf_frame_header: Buffer): Promise<void>; | ||
parseCrc(): Promise<void>; | ||
skipSideInformation(): Promise<void>; | ||
readXtraInfoHeader(): Promise<any>; | ||
private _peekBuffer(); | ||
private _sync(offset, gotFirstSync); | ||
private sync(); | ||
private parseAudioFrameHeader(buf_frame_header); | ||
private parseCrc(); | ||
private skipSideInformation(); | ||
private readXtraInfoHeader(); | ||
/** | ||
@@ -37,0 +39,0 @@ * Ref: http://gabriel.mp3-tech.org/mp3infotag.html |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
@@ -16,5 +16,10 @@ var extendStatics = Object.setPrototypeOf || | ||
var Token = require("token-types"); | ||
var es6_promise_1 = require("es6-promise"); | ||
var AbstractID3Parser_1 = require("../id3v2/AbstractID3Parser"); | ||
var XingTag_1 = require("./XingTag"); | ||
/** | ||
* Cache buffer size used for searching synchronization preabmle | ||
*/ | ||
var maxPeekLen = 1024; | ||
/** | ||
* MPEG Audio Layer I/II/III frame header | ||
@@ -31,3 +36,3 @@ * Ref: https://www.mp3-tech.org/programmer/frame_header.html | ||
if (this.layer === null) | ||
throw new Error('Invalid MPEG layer'); | ||
throw new Error("Invalid MPEG layer"); | ||
// D(16): Protection bit (if true 16-bit CRC follows header) | ||
@@ -55,3 +60,3 @@ this.isProtectedByCRC = !common_1.default.isBitSet(buf, off + 1, 7); | ||
if (this.version === null) | ||
throw new Error('Invalid MPEG Audio version'); | ||
throw new Error("Invalid MPEG Audio version"); | ||
this.channelMode = MpegFrameHeader.ChannelMode[this.channelModeIndex]; | ||
@@ -61,3 +66,3 @@ // Calculate bitrate | ||
if (!bitrateInKbps) { | ||
throw new Error('Cannot determine bit-rate'); | ||
throw new Error("Cannot determine bit-rate"); | ||
} | ||
@@ -68,3 +73,3 @@ this.bitrate = bitrateInKbps === null ? null : bitrateInKbps * 1000; | ||
if (this.samplingRate == null) { | ||
throw new Error('Cannot determine sampling-rate'); | ||
throw new Error("Cannot determine sampling-rate"); | ||
} | ||
@@ -119,3 +124,3 @@ } | ||
MpegFrameHeader.LayerDescription = [null, 3, 2, 1]; | ||
MpegFrameHeader.ChannelMode = ['stereo', 'joint_stereo', 'dual_channel', 'mono']; | ||
MpegFrameHeader.ChannelMode = ["stereo", "joint_stereo", "dual_channel", "mono"]; | ||
MpegFrameHeader.bitrate_index = { | ||
@@ -156,3 +161,3 @@ 0x01: { 11: 32, 12: 32, 13: 32, 21: 32, 22: 8, 23: 8 }, | ||
MpegAudioLayer.getVbrCodecProfile = function (vbrScale) { | ||
return 'V' + (100 - vbrScale) / 10; | ||
return "V" + (100 - vbrScale) / 10; | ||
}; | ||
@@ -178,7 +183,8 @@ MpegAudioLayer.FrameHeader = { | ||
_this.buf_frame_header = new Buffer(4); | ||
_this.syncPeek = { | ||
buf: new Buffer(maxPeekLen), | ||
len: 0 | ||
}; | ||
return _this; | ||
} | ||
/* | ||
public constructor(private tokenizer: ITokenizer, private headerSize: number, private readDuration: boolean) { | ||
}*/ | ||
/** | ||
@@ -193,7 +199,7 @@ * Called after ID3 headers have been parsed | ||
this.format = { | ||
dataformat: 'mp3', | ||
dataformat: "mp3", | ||
lossless: false | ||
}; | ||
return this.sync().catch(function (err) { | ||
if (err === strtok3_1.EndOfFile) { | ||
if (err.message === strtok3_1.endOfFile) { | ||
if (_this.calculateVbrDuration) { | ||
@@ -214,28 +220,56 @@ _this.format.numberOfSamples = _this.frameCount * _this.samplesPerFrame; | ||
}; | ||
MpegParser.prototype.sync = function () { | ||
MpegParser.prototype._peekBuffer = function () { | ||
var _this = this; | ||
return this.tokenizer.readBuffer(this.buf_frame_header, 0, 1).then(function () { | ||
if (_this.buf_frame_header[0] === MpegFrameHeader.SyncByte1) { | ||
return _this.tokenizer.readBuffer(_this.buf_frame_header, 1, 1).then(function () { | ||
if ((_this.buf_frame_header[1] & 0xE0) === 0xE0) { | ||
// Synchronized | ||
_this.warnings.push("synchronized, after " + _this.unsynced + " bytes of unsynced data"); | ||
_this.unsynced = 0; | ||
return _this.parseAudioFrameHeader(_this.buf_frame_header); | ||
} | ||
else { | ||
_this.unsynced += 2; | ||
return _this.sync(); | ||
} | ||
}); | ||
this.unsynced += this.syncPeek.len; | ||
return this.tokenizer.ignore(this.syncPeek.len).then(function () { | ||
return _this.tokenizer.peekBuffer(_this.syncPeek.buf, 0, maxPeekLen).then(function (len) { | ||
_this.syncPeek.len = len; | ||
return len; | ||
}); | ||
}); | ||
}; | ||
MpegParser.prototype._sync = function (offset, gotFirstSync) { | ||
var _this = this; | ||
return (offset === 0 ? this._peekBuffer() : es6_promise_1.Promise.resolve(this.syncPeek.buf.length - offset)) | ||
.then(function (len) { | ||
if (gotFirstSync) { | ||
if (len === 0) | ||
throw new Error(strtok3_1.endOfFile); | ||
if ((_this.syncPeek.buf[offset] & 0xE0) === 0xE0) { | ||
_this.syncPeek.len = 0; | ||
_this.unsynced += offset - 1; | ||
return _this.tokenizer.ignore(offset); // Full sync | ||
} | ||
else { | ||
return _this._sync((offset + 1) % _this.syncPeek.buf.length, false); // partial sync | ||
} | ||
} | ||
else { | ||
++_this.unsynced; | ||
return _this.sync(); | ||
if (len <= 1) | ||
throw new Error(strtok3_1.endOfFile); | ||
var index = _this.syncPeek.buf.indexOf(MpegFrameHeader.SyncByte1, offset); | ||
if (index >= 0) { | ||
return _this._sync((index + 1) % _this.syncPeek.buf.length, true); | ||
} | ||
else { | ||
return _this._sync(0, false); | ||
} | ||
} | ||
}); | ||
}; | ||
MpegParser.prototype.sync = function () { | ||
var _this = this; | ||
return this._sync(0, false) | ||
.then(function () { | ||
if (_this.unsynced > 0) { | ||
_this.warnings.push("synchronized, after " + _this.unsynced + " bytes of unsynced data"); | ||
// debug("synchronized, after " + this.unsynced + " bytes of unsynced data"); | ||
_this.unsynced = 0; | ||
} | ||
return _this.parseAudioFrameHeader(_this.buf_frame_header); | ||
}); | ||
}; | ||
MpegParser.prototype.parseAudioFrameHeader = function (buf_frame_header) { | ||
var _this = this; | ||
return this.tokenizer.readBuffer(buf_frame_header, 2, 2).then(function () { | ||
return this.tokenizer.readBuffer(buf_frame_header, 1, 3).then(function () { | ||
var header; | ||
@@ -254,6 +288,6 @@ try { | ||
_this.format.sampleRate = header.samplingRate; | ||
_this.format.numberOfChannels = header.channelMode === 'mono' ? 1 : 2; | ||
_this.format.numberOfChannels = header.channelMode === "mono" ? 1 : 2; | ||
var slot_size = header.calcSlotSize(); | ||
if (slot_size === null) { | ||
throw new Error('invalid slot_size'); | ||
throw new Error("invalid slot_size"); | ||
} | ||
@@ -325,6 +359,6 @@ var samples_per_frame = header.calcSamplesPerFrame(); | ||
switch (headerTag) { | ||
case 'Info': | ||
_this.format.codecProfile = 'CBR'; | ||
case "Info": | ||
_this.format.codecProfile = "CBR"; | ||
return _this.readXingInfoHeader(); | ||
case 'Xing': | ||
case "Xing": | ||
return _this.readXingInfoHeader().then(function (infoTag) { | ||
@@ -334,6 +368,6 @@ _this.format.codecProfile = MpegAudioLayer.getVbrCodecProfile(infoTag.vbrScale); | ||
}); | ||
case 'Xtra': | ||
case "Xtra": | ||
// ToDo: ??? | ||
break; | ||
case 'LAME': | ||
case "LAME": | ||
return _this.tokenizer.readToken(XingTag_1.LameEncoderVersion).then(function (version) { | ||
@@ -362,8 +396,8 @@ _this.offset += XingTag_1.LameEncoderVersion.len; | ||
/* ToDo: jump to end of stream | ||
if (infoTag.streamSize) { | ||
return this.skipFrameData(infoTag.streamSize - (4 + XingInfoTag.len)).then(() => { | ||
return infoTag; | ||
}); | ||
} | ||
*/ | ||
if (infoTag.streamSize) { | ||
return this.skipFrameData(infoTag.streamSize - (4 + XingInfoTag.len)).then(() => { | ||
return infoTag; | ||
}); | ||
} | ||
*/ | ||
return infoTag; // Done ToDo: will get out-of sync | ||
@@ -370,0 +404,0 @@ } |
@@ -62,3 +62,3 @@ 'use strict'; | ||
.catch(function (err) { | ||
if (err === strtok3.EndOfFile) { | ||
if (err.message === strtok3.endOfFile) { | ||
_this.vorbisStream.append(null); | ||
@@ -65,0 +65,0 @@ } |
@@ -60,3 +60,3 @@ "use strict"; | ||
.catch(function (err) { | ||
if (err === strtok3.EndOfFile) { | ||
if (err.message === strtok3.endOfFile) { | ||
return _this.metadata; | ||
@@ -63,0 +63,0 @@ } |
@@ -44,3 +44,3 @@ 'use strict'; | ||
}).catch(function (err) { | ||
if (err === then_read_stream_1.StreamReader.EndOfStream) { | ||
if (err.message === then_read_stream_1.endOfStream) { | ||
return; | ||
@@ -47,0 +47,0 @@ } |
@@ -87,3 +87,3 @@ "use strict"; | ||
.then(function () { | ||
// The try to parse APEv2 header | ||
// try to parse APEv2 header | ||
return APEv2Parser_1.APEv2Parser.parseFooter(tokenizer, options).then(function (tags) { | ||
@@ -119,3 +119,3 @@ return { | ||
} | ||
var ignoreBytes = header.blockSize - (32 - 8); | ||
var ignoreBytes = header.blockSize - (WavPack.BlockHeaderToken.len - 8); | ||
if (header.blockIndex === 0 && header.blockSamples === 0) { | ||
@@ -131,3 +131,3 @@ // Meta-data block | ||
}).then(function () { | ||
return _this.parseWavPackBlocks(); // recursion: continue with next WavPack-block | ||
return _this.parseWavPackBlocks(); | ||
}); | ||
@@ -134,0 +134,0 @@ } |
{ | ||
"name": "music-metadata", | ||
"description": "Streaming music metadata parser for node and the browser.", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"author": { | ||
@@ -59,4 +59,4 @@ "name": "Borewit", | ||
"fs-extra": "^4.0.1", | ||
"strtok3": "^1.2.0", | ||
"then-read-stream": "^0.9.6", | ||
"strtok3": "^1.3.2", | ||
"then-read-stream": "^1.0.3", | ||
"token-types": "^0.9.1" | ||
@@ -67,9 +67,9 @@ }, | ||
"@types/es6-promise": "0.0.32", | ||
"@types/fs-extra": "^4.0.0", | ||
"@types/fs-extra": "^4.0.1", | ||
"@types/mocha": "^2.2.42", | ||
"@types/node": "^8.0.25", | ||
"chai": "^4.1.1", | ||
"@types/node": "^8.0.26", | ||
"chai": "^4.1.2", | ||
"coveralls": "^2.13.1", | ||
"mocha": "^3.5.0", | ||
"npm-run-all": "^4.1.0", | ||
"npm-run-all": "^4.1.1", | ||
"nyc": "^11.1.0", | ||
@@ -79,3 +79,3 @@ "source-map": "^0.5.7", | ||
"tslint": "^5.7.0", | ||
"typescript": "^2.5.1" | ||
"typescript": "^2.5.2" | ||
}, | ||
@@ -82,0 +82,0 @@ "testling": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
253248
6227
- Removedthen-read-stream@0.9.6(transitive)
Updatedstrtok3@^1.3.2
Updatedthen-read-stream@^1.0.3