music-metadata 7.11.6 → 7.11.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +432 -432
- package/lib/ParserFactory.d.ts +49 -49
- package/lib/ParserFactory.js +251 -251
- package/lib/aiff/AiffParser.d.ts +15 -15
- package/lib/aiff/AiffParser.js +85 -85
- package/lib/aiff/AiffToken.d.ts +22 -22
- package/lib/aiff/AiffToken.js +43 -43
- package/lib/apev2/APEv2Parser.d.ts +30 -30
- package/lib/apev2/APEv2Parser.js +162 -162
- package/lib/apev2/APEv2TagMapper.d.ts +4 -4
- package/lib/apev2/APEv2TagMapper.js +86 -86
- package/lib/apev2/APEv2Token.d.ts +100 -100
- package/lib/apev2/APEv2Token.js +126 -126
- package/lib/asf/AsfObject.d.ts +319 -319
- package/lib/asf/AsfObject.js +384 -384
- package/lib/asf/AsfParser.d.ts +17 -17
- package/lib/asf/AsfParser.js +135 -135
- package/lib/asf/AsfTagMapper.d.ts +7 -7
- package/lib/asf/AsfTagMapper.js +95 -95
- package/lib/asf/AsfUtil.d.ts +13 -13
- package/lib/asf/AsfUtil.js +40 -40
- package/lib/asf/GUID.d.ts +86 -86
- package/lib/asf/GUID.js +123 -123
- package/lib/common/BasicParser.d.ts +17 -17
- package/lib/common/BasicParser.js +18 -18
- package/lib/common/CaseInsensitiveTagMap.d.ts +10 -10
- package/lib/common/CaseInsensitiveTagMap.js +21 -21
- package/lib/common/CombinedTagMapper.d.ts +19 -19
- package/lib/common/CombinedTagMapper.js +51 -51
- package/lib/common/FourCC.d.ts +6 -6
- package/lib/common/FourCC.js +28 -28
- package/lib/common/GenericTagMapper.d.ts +51 -51
- package/lib/common/GenericTagMapper.js +55 -55
- package/lib/common/GenericTagTypes.d.ts +33 -33
- package/lib/common/GenericTagTypes.js +131 -131
- package/lib/common/MetadataCollector.d.ts +76 -76
- package/lib/common/MetadataCollector.js +275 -275
- package/lib/common/RandomFileReader.d.ts +20 -20
- package/lib/common/RandomFileReader.js +37 -37
- package/lib/common/RandomUint8ArrayReader.d.ts +18 -18
- package/lib/common/RandomUint8ArrayReader.js +25 -25
- package/lib/common/Util.d.ts +58 -57
- package/lib/common/Util.js +162 -169
- package/lib/core.d.ts +48 -48
- package/lib/core.js +90 -90
- package/lib/dsdiff/DsdiffParser.d.ts +14 -14
- package/lib/dsdiff/DsdiffParser.js +143 -143
- package/lib/dsdiff/DsdiffToken.d.ts +9 -9
- package/lib/dsdiff/DsdiffToken.js +21 -21
- package/lib/dsf/DsfChunk.d.ts +86 -86
- package/lib/dsf/DsfChunk.js +54 -54
- package/lib/dsf/DsfParser.d.ts +9 -9
- package/lib/dsf/DsfParser.js +56 -56
- package/lib/flac/FlacParser.d.ts +28 -28
- package/lib/flac/FlacParser.js +175 -175
- package/lib/id3v1/ID3v1Parser.d.ts +13 -13
- package/lib/id3v1/ID3v1Parser.js +134 -134
- package/lib/id3v1/ID3v1TagMap.d.ts +4 -4
- package/lib/id3v1/ID3v1TagMap.js +22 -22
- package/lib/id3v2/AbstractID3Parser.d.ts +17 -17
- package/lib/id3v2/AbstractID3Parser.js +60 -60
- package/lib/id3v2/FrameParser.d.ts +32 -32
- package/lib/id3v2/FrameParser.js +329 -323
- package/lib/id3v2/ID3v22TagMapper.d.ts +9 -9
- package/lib/id3v2/ID3v22TagMapper.js +55 -55
- package/lib/id3v2/ID3v24TagMapper.d.ts +14 -14
- package/lib/id3v2/ID3v24TagMapper.js +193 -193
- package/lib/id3v2/ID3v2Parser.d.ts +29 -29
- package/lib/id3v2/ID3v2Parser.js +194 -194
- package/lib/id3v2/ID3v2Token.d.ts +73 -73
- package/lib/id3v2/ID3v2Token.js +106 -106
- package/lib/iff/index.d.ts +33 -33
- package/lib/iff/index.js +19 -19
- package/lib/index.d.ts +45 -45
- package/lib/index.js +74 -74
- package/lib/lyrics3/Lyrics3.d.ts +3 -3
- package/lib/lyrics3/Lyrics3.js +17 -17
- package/lib/matroska/MatroskaDtd.d.ts +8 -8
- package/lib/matroska/MatroskaDtd.js +279 -279
- package/lib/matroska/MatroskaParser.d.ts +37 -37
- package/lib/matroska/MatroskaParser.js +235 -235
- package/lib/matroska/MatroskaTagMapper.d.ts +4 -4
- package/lib/matroska/MatroskaTagMapper.js +35 -35
- package/lib/matroska/types.d.ts +175 -175
- package/lib/matroska/types.js +32 -32
- package/lib/mp4/Atom.d.ts +16 -16
- package/lib/mp4/Atom.js +70 -70
- package/lib/mp4/AtomToken.d.ts +395 -395
- package/lib/mp4/AtomToken.js +406 -406
- package/lib/mp4/MP4Parser.d.ts +30 -30
- package/lib/mp4/MP4Parser.js +511 -511
- package/lib/mp4/MP4TagMapper.d.ts +5 -5
- package/lib/mp4/MP4TagMapper.js +115 -115
- package/lib/mpeg/ExtendedLameHeader.d.ts +27 -27
- package/lib/mpeg/ExtendedLameHeader.js +31 -31
- package/lib/mpeg/MpegParser.d.ts +49 -49
- package/lib/mpeg/MpegParser.js +529 -529
- package/lib/mpeg/ReplayGainDataFormat.d.ts +55 -55
- package/lib/mpeg/ReplayGainDataFormat.js +69 -69
- package/lib/mpeg/XingTag.d.ts +45 -45
- package/lib/mpeg/XingTag.js +69 -69
- package/lib/musepack/index.d.ts +5 -5
- package/lib/musepack/index.js +32 -32
- package/lib/musepack/sv7/BitReader.d.ts +13 -13
- package/lib/musepack/sv7/BitReader.js +54 -54
- package/lib/musepack/sv7/MpcSv7Parser.d.ts +8 -8
- package/lib/musepack/sv7/MpcSv7Parser.js +46 -46
- package/lib/musepack/sv7/StreamVersion7.d.ts +28 -28
- package/lib/musepack/sv7/StreamVersion7.js +41 -41
- package/lib/musepack/sv8/MpcSv8Parser.d.ts +6 -6
- package/lib/musepack/sv8/MpcSv8Parser.js +55 -55
- package/lib/musepack/sv8/StreamVersion8.d.ts +40 -40
- package/lib/musepack/sv8/StreamVersion8.js +80 -80
- package/lib/ogg/Ogg.d.ts +72 -72
- package/lib/ogg/Ogg.js +2 -2
- package/lib/ogg/OggParser.d.ts +23 -23
- package/lib/ogg/OggParser.js +126 -126
- package/lib/ogg/opus/Opus.d.ts +48 -48
- package/lib/ogg/opus/Opus.js +28 -28
- package/lib/ogg/opus/OpusParser.d.ts +25 -25
- package/lib/ogg/opus/OpusParser.js +56 -56
- package/lib/ogg/speex/Speex.d.ts +36 -36
- package/lib/ogg/speex/Speex.js +31 -31
- package/lib/ogg/speex/SpeexParser.d.ts +22 -22
- package/lib/ogg/speex/SpeexParser.js +35 -35
- package/lib/ogg/theora/Theora.d.ts +20 -20
- package/lib/ogg/theora/Theora.js +23 -23
- package/lib/ogg/theora/TheoraParser.d.ts +28 -28
- package/lib/ogg/theora/TheoraParser.js +44 -44
- package/lib/ogg/vorbis/Vorbis.d.ts +79 -79
- package/lib/ogg/vorbis/Vorbis.js +78 -78
- package/lib/ogg/vorbis/VorbisDecoder.d.ts +12 -12
- package/lib/ogg/vorbis/VorbisDecoder.js +32 -32
- package/lib/ogg/vorbis/VorbisParser.d.ts +36 -36
- package/lib/ogg/vorbis/VorbisParser.js +128 -128
- package/lib/ogg/vorbis/VorbisTagMapper.d.ts +7 -7
- package/lib/ogg/vorbis/VorbisTagMapper.js +132 -132
- package/lib/riff/RiffChunk.d.ts +16 -16
- package/lib/riff/RiffChunk.js +32 -32
- package/lib/riff/RiffInfoTagMap.d.ts +10 -10
- package/lib/riff/RiffInfoTagMap.js +37 -37
- package/lib/type.d.ts +599 -599
- package/lib/type.js +13 -13
- package/lib/wav/WaveChunk.d.ts +64 -64
- package/lib/wav/WaveChunk.js +65 -65
- package/lib/wav/WaveParser.d.ts +24 -24
- package/lib/wav/WaveParser.js +144 -144
- package/lib/wavpack/WavPackParser.d.ts +14 -14
- package/lib/wavpack/WavPackParser.js +105 -105
- package/lib/wavpack/WavPackToken.d.ts +64 -64
- package/lib/wavpack/WavPackToken.js +76 -76
- package/package.json +142 -142
package/lib/aiff/AiffParser.js
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AIFFParser = void 0;
|
|
4
|
-
const Token = require("token-types");
|
|
5
|
-
const initDebug = require("debug");
|
|
6
|
-
const strtok3 = require("strtok3/lib/core");
|
|
7
|
-
const ID3v2Parser_1 = require("../id3v2/ID3v2Parser");
|
|
8
|
-
const FourCC_1 = require("../common/FourCC");
|
|
9
|
-
const BasicParser_1 = require("../common/BasicParser");
|
|
10
|
-
const AiffToken = require("./AiffToken");
|
|
11
|
-
const iff = require("../iff");
|
|
12
|
-
const debug = initDebug('music-metadata:parser:aiff');
|
|
13
|
-
/**
|
|
14
|
-
* AIFF - Audio Interchange File Format
|
|
15
|
-
*
|
|
16
|
-
* Ref:
|
|
17
|
-
* http://www.onicos.com/staff/iz/formats/aiff.html
|
|
18
|
-
* http://muratnkonar.com/aiff/index.html
|
|
19
|
-
* http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/AIFF/AIFF.html
|
|
20
|
-
*/
|
|
21
|
-
class AIFFParser extends BasicParser_1.BasicParser {
|
|
22
|
-
async parse() {
|
|
23
|
-
const header = await this.tokenizer.readToken(iff.Header);
|
|
24
|
-
if (header.chunkID !== 'FORM')
|
|
25
|
-
throw new Error('Invalid Chunk-ID, expected \'FORM\''); // Not AIFF format
|
|
26
|
-
const type = await this.tokenizer.readToken(FourCC_1.FourCcToken);
|
|
27
|
-
switch (type) {
|
|
28
|
-
case 'AIFF':
|
|
29
|
-
this.metadata.setFormat('container', type);
|
|
30
|
-
this.isCompressed = false;
|
|
31
|
-
break;
|
|
32
|
-
case 'AIFC':
|
|
33
|
-
this.metadata.setFormat('container', 'AIFF-C');
|
|
34
|
-
this.isCompressed = true;
|
|
35
|
-
break;
|
|
36
|
-
default:
|
|
37
|
-
throw Error('Unsupported AIFF type: ' + type);
|
|
38
|
-
}
|
|
39
|
-
this.metadata.setFormat('lossless', !this.isCompressed);
|
|
40
|
-
try {
|
|
41
|
-
while (!this.tokenizer.fileInfo.size || this.tokenizer.fileInfo.size - this.tokenizer.position >= iff.Header.len) {
|
|
42
|
-
debug('Reading AIFF chunk at offset=' + this.tokenizer.position);
|
|
43
|
-
const chunkHeader = await this.tokenizer.readToken(iff.Header);
|
|
44
|
-
debug(`Chunk id=${chunkHeader.chunkID}`);
|
|
45
|
-
const nextChunk = 2 * Math.round(chunkHeader.chunkSize / 2);
|
|
46
|
-
const bytesRead = await this.readData(chunkHeader);
|
|
47
|
-
await this.tokenizer.ignore(nextChunk - bytesRead);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
catch (err) {
|
|
51
|
-
if (err instanceof strtok3.EndOfStreamError) {
|
|
52
|
-
debug(`End-of-stream`);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
throw err;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
async readData(header) {
|
|
60
|
-
switch (header.chunkID) {
|
|
61
|
-
case 'COMM': // The Common Chunk
|
|
62
|
-
const common = await this.tokenizer.readToken(new AiffToken.Common(header, this.isCompressed));
|
|
63
|
-
this.metadata.setFormat('bitsPerSample', common.sampleSize);
|
|
64
|
-
this.metadata.setFormat('sampleRate', common.sampleRate);
|
|
65
|
-
this.metadata.setFormat('numberOfChannels', common.numChannels);
|
|
66
|
-
this.metadata.setFormat('numberOfSamples', common.numSampleFrames);
|
|
67
|
-
this.metadata.setFormat('duration', common.numSampleFrames / common.sampleRate);
|
|
68
|
-
this.metadata.setFormat('codec', common.compressionName);
|
|
69
|
-
return header.chunkSize;
|
|
70
|
-
case 'ID3 ': // ID3-meta-data
|
|
71
|
-
const id3_data = await this.tokenizer.readToken(new Token.Uint8ArrayType(header.chunkSize));
|
|
72
|
-
const rst = strtok3.fromBuffer(id3_data);
|
|
73
|
-
await new ID3v2Parser_1.ID3v2Parser().parse(this.metadata, rst, this.options);
|
|
74
|
-
return header.chunkSize;
|
|
75
|
-
case 'SSND': // Sound Data Chunk
|
|
76
|
-
if (this.metadata.format.duration) {
|
|
77
|
-
this.metadata.setFormat('bitrate', 8 * header.chunkSize / this.metadata.format.duration);
|
|
78
|
-
}
|
|
79
|
-
return 0;
|
|
80
|
-
default:
|
|
81
|
-
return 0;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.AIFFParser = AIFFParser;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AIFFParser = void 0;
|
|
4
|
+
const Token = require("token-types");
|
|
5
|
+
const initDebug = require("debug");
|
|
6
|
+
const strtok3 = require("strtok3/lib/core");
|
|
7
|
+
const ID3v2Parser_1 = require("../id3v2/ID3v2Parser");
|
|
8
|
+
const FourCC_1 = require("../common/FourCC");
|
|
9
|
+
const BasicParser_1 = require("../common/BasicParser");
|
|
10
|
+
const AiffToken = require("./AiffToken");
|
|
11
|
+
const iff = require("../iff");
|
|
12
|
+
const debug = initDebug('music-metadata:parser:aiff');
|
|
13
|
+
/**
|
|
14
|
+
* AIFF - Audio Interchange File Format
|
|
15
|
+
*
|
|
16
|
+
* Ref:
|
|
17
|
+
* http://www.onicos.com/staff/iz/formats/aiff.html
|
|
18
|
+
* http://muratnkonar.com/aiff/index.html
|
|
19
|
+
* http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/AIFF/AIFF.html
|
|
20
|
+
*/
|
|
21
|
+
class AIFFParser extends BasicParser_1.BasicParser {
|
|
22
|
+
async parse() {
|
|
23
|
+
const header = await this.tokenizer.readToken(iff.Header);
|
|
24
|
+
if (header.chunkID !== 'FORM')
|
|
25
|
+
throw new Error('Invalid Chunk-ID, expected \'FORM\''); // Not AIFF format
|
|
26
|
+
const type = await this.tokenizer.readToken(FourCC_1.FourCcToken);
|
|
27
|
+
switch (type) {
|
|
28
|
+
case 'AIFF':
|
|
29
|
+
this.metadata.setFormat('container', type);
|
|
30
|
+
this.isCompressed = false;
|
|
31
|
+
break;
|
|
32
|
+
case 'AIFC':
|
|
33
|
+
this.metadata.setFormat('container', 'AIFF-C');
|
|
34
|
+
this.isCompressed = true;
|
|
35
|
+
break;
|
|
36
|
+
default:
|
|
37
|
+
throw Error('Unsupported AIFF type: ' + type);
|
|
38
|
+
}
|
|
39
|
+
this.metadata.setFormat('lossless', !this.isCompressed);
|
|
40
|
+
try {
|
|
41
|
+
while (!this.tokenizer.fileInfo.size || this.tokenizer.fileInfo.size - this.tokenizer.position >= iff.Header.len) {
|
|
42
|
+
debug('Reading AIFF chunk at offset=' + this.tokenizer.position);
|
|
43
|
+
const chunkHeader = await this.tokenizer.readToken(iff.Header);
|
|
44
|
+
debug(`Chunk id=${chunkHeader.chunkID}`);
|
|
45
|
+
const nextChunk = 2 * Math.round(chunkHeader.chunkSize / 2);
|
|
46
|
+
const bytesRead = await this.readData(chunkHeader);
|
|
47
|
+
await this.tokenizer.ignore(nextChunk - bytesRead);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
if (err instanceof strtok3.EndOfStreamError) {
|
|
52
|
+
debug(`End-of-stream`);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
throw err;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async readData(header) {
|
|
60
|
+
switch (header.chunkID) {
|
|
61
|
+
case 'COMM': // The Common Chunk
|
|
62
|
+
const common = await this.tokenizer.readToken(new AiffToken.Common(header, this.isCompressed));
|
|
63
|
+
this.metadata.setFormat('bitsPerSample', common.sampleSize);
|
|
64
|
+
this.metadata.setFormat('sampleRate', common.sampleRate);
|
|
65
|
+
this.metadata.setFormat('numberOfChannels', common.numChannels);
|
|
66
|
+
this.metadata.setFormat('numberOfSamples', common.numSampleFrames);
|
|
67
|
+
this.metadata.setFormat('duration', common.numSampleFrames / common.sampleRate);
|
|
68
|
+
this.metadata.setFormat('codec', common.compressionName);
|
|
69
|
+
return header.chunkSize;
|
|
70
|
+
case 'ID3 ': // ID3-meta-data
|
|
71
|
+
const id3_data = await this.tokenizer.readToken(new Token.Uint8ArrayType(header.chunkSize));
|
|
72
|
+
const rst = strtok3.fromBuffer(id3_data);
|
|
73
|
+
await new ID3v2Parser_1.ID3v2Parser().parse(this.metadata, rst, this.options);
|
|
74
|
+
return header.chunkSize;
|
|
75
|
+
case 'SSND': // Sound Data Chunk
|
|
76
|
+
if (this.metadata.format.duration) {
|
|
77
|
+
this.metadata.setFormat('bitrate', 8 * header.chunkSize / this.metadata.format.duration);
|
|
78
|
+
}
|
|
79
|
+
return 0;
|
|
80
|
+
default:
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.AIFFParser = AIFFParser;
|
package/lib/aiff/AiffToken.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { IGetToken } from 'strtok3';
|
|
3
|
-
import * as iff from '../iff';
|
|
4
|
-
/**
|
|
5
|
-
* The Common Chunk.
|
|
6
|
-
* Describes fundamental parameters of the waveform data such as sample rate, bit resolution, and how many channels of
|
|
7
|
-
* digital audio are stored in the FORM AIFF.
|
|
8
|
-
*/
|
|
9
|
-
export interface ICommon {
|
|
10
|
-
numChannels: number;
|
|
11
|
-
numSampleFrames: number;
|
|
12
|
-
sampleSize: number;
|
|
13
|
-
sampleRate: number;
|
|
14
|
-
compressionType?: string;
|
|
15
|
-
compressionName?: string;
|
|
16
|
-
}
|
|
17
|
-
export declare class Common implements IGetToken<ICommon> {
|
|
18
|
-
private isAifc;
|
|
19
|
-
len: number;
|
|
20
|
-
constructor(header: iff.IChunkHeader, isAifc: boolean);
|
|
21
|
-
get(buf: Buffer, off: number): ICommon;
|
|
22
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IGetToken } from 'strtok3';
|
|
3
|
+
import * as iff from '../iff';
|
|
4
|
+
/**
|
|
5
|
+
* The Common Chunk.
|
|
6
|
+
* Describes fundamental parameters of the waveform data such as sample rate, bit resolution, and how many channels of
|
|
7
|
+
* digital audio are stored in the FORM AIFF.
|
|
8
|
+
*/
|
|
9
|
+
export interface ICommon {
|
|
10
|
+
numChannels: number;
|
|
11
|
+
numSampleFrames: number;
|
|
12
|
+
sampleSize: number;
|
|
13
|
+
sampleRate: number;
|
|
14
|
+
compressionType?: string;
|
|
15
|
+
compressionName?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class Common implements IGetToken<ICommon> {
|
|
18
|
+
private isAifc;
|
|
19
|
+
len: number;
|
|
20
|
+
constructor(header: iff.IChunkHeader, isAifc: boolean);
|
|
21
|
+
get(buf: Buffer, off: number): ICommon;
|
|
22
|
+
}
|
package/lib/aiff/AiffToken.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Common = void 0;
|
|
4
|
-
const Token = require("token-types");
|
|
5
|
-
const FourCC_1 = require("../common/FourCC");
|
|
6
|
-
class Common {
|
|
7
|
-
constructor(header, isAifc) {
|
|
8
|
-
this.isAifc = isAifc;
|
|
9
|
-
const minimumChunkSize = isAifc ? 22 : 18;
|
|
10
|
-
if (header.chunkSize < minimumChunkSize)
|
|
11
|
-
throw new Error(`COMMON CHUNK size should always be at least ${minimumChunkSize}`);
|
|
12
|
-
this.len = header.chunkSize;
|
|
13
|
-
}
|
|
14
|
-
get(buf, off) {
|
|
15
|
-
// see: https://cycling74.com/forums/aiffs-80-bit-sample-rate-value
|
|
16
|
-
const shift = buf.readUInt16BE(off + 8) - 16398;
|
|
17
|
-
const baseSampleRate = buf.readUInt16BE(off + 8 + 2);
|
|
18
|
-
const res = {
|
|
19
|
-
numChannels: buf.readUInt16BE(off),
|
|
20
|
-
numSampleFrames: buf.readUInt32BE(off + 2),
|
|
21
|
-
sampleSize: buf.readUInt16BE(off + 6),
|
|
22
|
-
sampleRate: shift < 0 ? baseSampleRate >> Math.abs(shift) : baseSampleRate << shift
|
|
23
|
-
};
|
|
24
|
-
if (this.isAifc) {
|
|
25
|
-
res.compressionType = FourCC_1.FourCcToken.get(buf, off + 18);
|
|
26
|
-
if (this.len > 22) {
|
|
27
|
-
const strLen = buf.readInt8(off + 22);
|
|
28
|
-
const padding = (strLen + 1) % 2;
|
|
29
|
-
if (23 + strLen + padding === this.len) {
|
|
30
|
-
res.compressionName = new Token.StringType(strLen, 'binary').get(buf, off + 23);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
throw new Error('Illegal pstring length');
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
res.compressionName = 'PCM';
|
|
39
|
-
}
|
|
40
|
-
return res;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.Common = Common;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Common = void 0;
|
|
4
|
+
const Token = require("token-types");
|
|
5
|
+
const FourCC_1 = require("../common/FourCC");
|
|
6
|
+
class Common {
|
|
7
|
+
constructor(header, isAifc) {
|
|
8
|
+
this.isAifc = isAifc;
|
|
9
|
+
const minimumChunkSize = isAifc ? 22 : 18;
|
|
10
|
+
if (header.chunkSize < minimumChunkSize)
|
|
11
|
+
throw new Error(`COMMON CHUNK size should always be at least ${minimumChunkSize}`);
|
|
12
|
+
this.len = header.chunkSize;
|
|
13
|
+
}
|
|
14
|
+
get(buf, off) {
|
|
15
|
+
// see: https://cycling74.com/forums/aiffs-80-bit-sample-rate-value
|
|
16
|
+
const shift = buf.readUInt16BE(off + 8) - 16398;
|
|
17
|
+
const baseSampleRate = buf.readUInt16BE(off + 8 + 2);
|
|
18
|
+
const res = {
|
|
19
|
+
numChannels: buf.readUInt16BE(off),
|
|
20
|
+
numSampleFrames: buf.readUInt32BE(off + 2),
|
|
21
|
+
sampleSize: buf.readUInt16BE(off + 6),
|
|
22
|
+
sampleRate: shift < 0 ? baseSampleRate >> Math.abs(shift) : baseSampleRate << shift
|
|
23
|
+
};
|
|
24
|
+
if (this.isAifc) {
|
|
25
|
+
res.compressionType = FourCC_1.FourCcToken.get(buf, off + 18);
|
|
26
|
+
if (this.len > 22) {
|
|
27
|
+
const strLen = buf.readInt8(off + 22);
|
|
28
|
+
const padding = (strLen + 1) % 2;
|
|
29
|
+
if (23 + strLen + padding === this.len) {
|
|
30
|
+
res.compressionName = new Token.StringType(strLen, 'binary').get(buf, off + 23);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
throw new Error('Illegal pstring length');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
res.compressionName = 'PCM';
|
|
39
|
+
}
|
|
40
|
+
return res;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.Common = Common;
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import * as strtok3 from 'strtok3/lib/core';
|
|
2
|
-
import { IOptions, IRandomReader, IApeHeader } from '../type';
|
|
3
|
-
import { INativeMetadataCollector } from '../common/MetadataCollector';
|
|
4
|
-
import { BasicParser } from '../common/BasicParser';
|
|
5
|
-
import { IFooter, IHeader } from './APEv2Token';
|
|
6
|
-
export declare class APEv2Parser extends BasicParser {
|
|
7
|
-
static tryParseApeHeader(metadata: INativeMetadataCollector, tokenizer: strtok3.ITokenizer, options: IOptions): Promise<void>;
|
|
8
|
-
/**
|
|
9
|
-
* Calculate the media file duration
|
|
10
|
-
* @param ah ApeHeader
|
|
11
|
-
* @return {number} duration in seconds
|
|
12
|
-
*/
|
|
13
|
-
static calculateDuration(ah: IHeader): number;
|
|
14
|
-
/**
|
|
15
|
-
* Calculates the APEv1 / APEv2 first field offset
|
|
16
|
-
* @param reader
|
|
17
|
-
* @param offset
|
|
18
|
-
*/
|
|
19
|
-
static findApeFooterOffset(reader: IRandomReader, offset: number): Promise<IApeHeader>;
|
|
20
|
-
private static parseTagFooter;
|
|
21
|
-
private ape;
|
|
22
|
-
/**
|
|
23
|
-
* Parse APEv1 / APEv2 header if header signature found
|
|
24
|
-
*/
|
|
25
|
-
tryParseApeHeader(): Promise<void>;
|
|
26
|
-
parse(): Promise<void>;
|
|
27
|
-
parseTags(footer: IFooter): Promise<void>;
|
|
28
|
-
private parseDescriptorExpansion;
|
|
29
|
-
private parseHeader;
|
|
30
|
-
}
|
|
1
|
+
import * as strtok3 from 'strtok3/lib/core';
|
|
2
|
+
import { IOptions, IRandomReader, IApeHeader } from '../type';
|
|
3
|
+
import { INativeMetadataCollector } from '../common/MetadataCollector';
|
|
4
|
+
import { BasicParser } from '../common/BasicParser';
|
|
5
|
+
import { IFooter, IHeader } from './APEv2Token';
|
|
6
|
+
export declare class APEv2Parser extends BasicParser {
|
|
7
|
+
static tryParseApeHeader(metadata: INativeMetadataCollector, tokenizer: strtok3.ITokenizer, options: IOptions): Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Calculate the media file duration
|
|
10
|
+
* @param ah ApeHeader
|
|
11
|
+
* @return {number} duration in seconds
|
|
12
|
+
*/
|
|
13
|
+
static calculateDuration(ah: IHeader): number;
|
|
14
|
+
/**
|
|
15
|
+
* Calculates the APEv1 / APEv2 first field offset
|
|
16
|
+
* @param reader
|
|
17
|
+
* @param offset
|
|
18
|
+
*/
|
|
19
|
+
static findApeFooterOffset(reader: IRandomReader, offset: number): Promise<IApeHeader>;
|
|
20
|
+
private static parseTagFooter;
|
|
21
|
+
private ape;
|
|
22
|
+
/**
|
|
23
|
+
* Parse APEv1 / APEv2 header if header signature found
|
|
24
|
+
*/
|
|
25
|
+
tryParseApeHeader(): Promise<void>;
|
|
26
|
+
parse(): Promise<void>;
|
|
27
|
+
parseTags(footer: IFooter): Promise<void>;
|
|
28
|
+
private parseDescriptorExpansion;
|
|
29
|
+
private parseHeader;
|
|
30
|
+
}
|