music-metadata 11.13.0 → 11.14.0
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/lib/common/Util.d.ts +1 -1
- package/lib/common/Util.js +7 -1
- package/lib/id3v2/FrameHeader.js +23 -3
- package/lib/id3v2/FrameParser.js +2 -2
- package/lib/id3v2/ID3v2Token.js +1 -1
- package/lib/mp4/AtomToken.js +38 -13
- package/lib/mpeg/MpegParser.js +1 -1
- package/package.json +6 -6
package/lib/common/Util.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IRatio } from '../type.js';
|
|
2
|
-
export type StringEncoding = 'ascii' | 'utf8' | 'utf-16le' | 'ucs2' | 'base64url' | 'latin1' | 'hex';
|
|
2
|
+
export type StringEncoding = 'ascii' | 'utf8' | 'utf-16le' | 'utf-16be' | 'ucs2' | 'base64url' | 'latin1' | 'hex';
|
|
3
3
|
export declare function getBit(buf: Uint8Array, off: number, bit: number): boolean;
|
|
4
4
|
/**
|
|
5
5
|
* Find delimiting zero in uint8Array
|
package/lib/common/Util.js
CHANGED
|
@@ -12,7 +12,7 @@ export function getBit(buf, off, bit) {
|
|
|
12
12
|
*/
|
|
13
13
|
export function findZero(uint8Array, encoding) {
|
|
14
14
|
const len = uint8Array.length;
|
|
15
|
-
if (encoding === 'utf-16le') {
|
|
15
|
+
if (encoding === 'utf-16le' || encoding === 'utf-16be') {
|
|
16
16
|
// Look for 0x00 0x00 on 2-byte boundary
|
|
17
17
|
for (let i = 0; i + 1 < len; i += 2) {
|
|
18
18
|
if (uint8Array[i] === 0 && uint8Array[i + 1] === 0)
|
|
@@ -57,6 +57,12 @@ export function decodeString(uint8Array, encoding) {
|
|
|
57
57
|
throw new FieldDecodingError('Expected even number of octets for 16-bit unicode string');
|
|
58
58
|
return decodeString(swapBytes(uint8Array), encoding);
|
|
59
59
|
}
|
|
60
|
+
if (encoding === 'utf-16be') {
|
|
61
|
+
// There is no native UTF-16BE decoder; swap to UTF-16LE and decode that.
|
|
62
|
+
if ((uint8Array.length & 1) !== 0)
|
|
63
|
+
throw new FieldDecodingError('Expected even number of octets for 16-bit unicode string');
|
|
64
|
+
return new StringType(uint8Array.length, 'utf-16le').get(swapBytes(Uint8Array.from(uint8Array)), 0);
|
|
65
|
+
}
|
|
60
66
|
return new StringType(uint8Array.length, encoding).get(uint8Array, 0);
|
|
61
67
|
}
|
|
62
68
|
export function stripNulls(str) {
|
package/lib/id3v2/FrameHeader.js
CHANGED
|
@@ -15,7 +15,27 @@ export function getFrameHeaderLength(majorVer) {
|
|
|
15
15
|
default: throw makeUnexpectedMajorVersionError(majorVer);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
function readFrameFlags(b) {
|
|
18
|
+
function readFrameFlags(b, majorVer) {
|
|
19
|
+
// ID3v2.3 and ID3v2.4 use different bit layouts for the frame status and format flags.
|
|
20
|
+
if (majorVer === 3) {
|
|
21
|
+
// ID3v2.3: status `%abc00000`, format `%ijk00000` (https://id3.org/id3v2.3.0)
|
|
22
|
+
return {
|
|
23
|
+
status: {
|
|
24
|
+
tag_alter_preservation: util.getBit(b, 0, 7),
|
|
25
|
+
file_alter_preservation: util.getBit(b, 0, 6),
|
|
26
|
+
read_only: util.getBit(b, 0, 5)
|
|
27
|
+
},
|
|
28
|
+
format: {
|
|
29
|
+
compression: util.getBit(b, 1, 7),
|
|
30
|
+
encryption: util.getBit(b, 1, 6),
|
|
31
|
+
grouping_identity: util.getBit(b, 1, 5),
|
|
32
|
+
// Unsynchronisation and data-length-indicator do not exist as per-frame flags in ID3v2.3.
|
|
33
|
+
unsynchronisation: false,
|
|
34
|
+
data_length_indicator: false
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// ID3v2.4: status `%0abc0000`, format `%0h00kmnp` (https://id3.org/id3v2.4.0-structure)
|
|
19
39
|
return {
|
|
20
40
|
status: {
|
|
21
41
|
tag_alter_preservation: util.getBit(b, 0, 6),
|
|
@@ -23,7 +43,7 @@ function readFrameFlags(b) {
|
|
|
23
43
|
read_only: util.getBit(b, 0, 4)
|
|
24
44
|
},
|
|
25
45
|
format: {
|
|
26
|
-
grouping_identity: util.getBit(b, 1,
|
|
46
|
+
grouping_identity: util.getBit(b, 1, 6),
|
|
27
47
|
compression: util.getBit(b, 1, 3),
|
|
28
48
|
encryption: util.getBit(b, 1, 2),
|
|
29
49
|
unsynchronisation: util.getBit(b, 1, 1),
|
|
@@ -61,7 +81,7 @@ function parseFrameHeaderV23V24(uint8Array, majorVer, warningCollector) {
|
|
|
61
81
|
const header = {
|
|
62
82
|
id: textDecode(uint8Array.subarray(0, 4), 'ascii'),
|
|
63
83
|
length: (majorVer === 4 ? UINT32SYNCSAFE : Token.UINT32_BE).get(uint8Array, 4),
|
|
64
|
-
flags: readFrameFlags(uint8Array.subarray(8, 10))
|
|
84
|
+
flags: readFrameFlags(uint8Array.subarray(8, 10), majorVer)
|
|
65
85
|
};
|
|
66
86
|
if (!header.id.match(/^[A-Z0-9]{4}$/)) {
|
|
67
87
|
warningCollector.addWarning(`Invalid ID3v2.${majorVer} frame-header-ID: ${header.id}`);
|
package/lib/id3v2/FrameParser.js
CHANGED
|
@@ -390,11 +390,11 @@ export class FrameParser {
|
|
|
390
390
|
if (zeroIndex >= valueArray.length) {
|
|
391
391
|
// No terminator found, decode full buffer remainder
|
|
392
392
|
return {
|
|
393
|
-
text: util.decodeString(
|
|
393
|
+
text: util.decodeString(uint8Array, encoding.encoding),
|
|
394
394
|
len: originalLen
|
|
395
395
|
};
|
|
396
396
|
}
|
|
397
|
-
const txt =
|
|
397
|
+
const txt = uint8Array.subarray(0, bomSize + zeroIndex);
|
|
398
398
|
return {
|
|
399
399
|
text: util.decodeString(txt, encoding.encoding),
|
|
400
400
|
len: bomSize + zeroIndex + FrameParser.getNullTerminatorLength(encoding.encoding)
|
package/lib/id3v2/ID3v2Token.js
CHANGED
|
@@ -109,7 +109,7 @@ export const TextEncodingToken = {
|
|
|
109
109
|
case 0x01:
|
|
110
110
|
return { encoding: 'utf-16le', bom: true };
|
|
111
111
|
case 0x02:
|
|
112
|
-
return { encoding: 'utf-
|
|
112
|
+
return { encoding: 'utf-16be', bom: false };
|
|
113
113
|
case 0x03:
|
|
114
114
|
return { encoding: 'utf8', bom: false };
|
|
115
115
|
default:
|
package/lib/mp4/AtomToken.js
CHANGED
|
@@ -226,19 +226,44 @@ export class TrackHeaderAtom {
|
|
|
226
226
|
this.len = len;
|
|
227
227
|
}
|
|
228
228
|
get(buf, off) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
229
|
+
const version = Token.UINT8.get(buf, off);
|
|
230
|
+
const flags = Token.UINT24_BE.get(buf, off + 1);
|
|
231
|
+
switch (version) {
|
|
232
|
+
case 0:
|
|
233
|
+
// Version 0: 32-bit fields
|
|
234
|
+
return {
|
|
235
|
+
version,
|
|
236
|
+
flags,
|
|
237
|
+
creationTime: SecondsSinceMacEpoch.get(buf, off + 4),
|
|
238
|
+
modificationTime: SecondsSinceMacEpoch.get(buf, off + 8),
|
|
239
|
+
trackId: Token.UINT32_BE.get(buf, off + 12),
|
|
240
|
+
// reserved 4 bytes
|
|
241
|
+
duration: Token.UINT32_BE.get(buf, off + 20),
|
|
242
|
+
// reserved 8 bytes
|
|
243
|
+
layer: Token.UINT16_BE.get(buf, off + 32),
|
|
244
|
+
alternateGroup: Token.UINT16_BE.get(buf, off + 34),
|
|
245
|
+
volume: Token.UINT16_BE.get(buf, off + 36) // ToDo: fixed point
|
|
246
|
+
// ToDo: add remaining fields
|
|
247
|
+
};
|
|
248
|
+
case 1:
|
|
249
|
+
// Version 1: 64-bit creation/modification times and duration
|
|
250
|
+
return {
|
|
251
|
+
version,
|
|
252
|
+
flags,
|
|
253
|
+
creationTime: SecondsSinceMacEpoch64.get(buf, off + 4),
|
|
254
|
+
modificationTime: SecondsSinceMacEpoch64.get(buf, off + 12),
|
|
255
|
+
trackId: Token.UINT32_BE.get(buf, off + 20),
|
|
256
|
+
// reserved 4 bytes
|
|
257
|
+
duration: Number(Token.UINT64_BE.get(buf, off + 28)),
|
|
258
|
+
// reserved 8 bytes
|
|
259
|
+
layer: Token.UINT16_BE.get(buf, off + 44),
|
|
260
|
+
alternateGroup: Token.UINT16_BE.get(buf, off + 46),
|
|
261
|
+
volume: Token.UINT16_BE.get(buf, off + 48) // ToDo: fixed point
|
|
262
|
+
// ToDo: add remaining fields
|
|
263
|
+
};
|
|
264
|
+
default:
|
|
265
|
+
throw new FieldDecodingError('Invalid tkhd version header');
|
|
266
|
+
}
|
|
242
267
|
}
|
|
243
268
|
}
|
|
244
269
|
/**
|
package/lib/mpeg/MpegParser.js
CHANGED
|
@@ -31,7 +31,7 @@ const MPEG4 = {
|
|
|
31
31
|
* https://wiki.multimedia.cx/index.php/MPEG-4_Audio#Sampling_Frequencies
|
|
32
32
|
*/
|
|
33
33
|
SamplingFrequencies: [
|
|
34
|
-
96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350, null, null,
|
|
34
|
+
96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350, null, null, null
|
|
35
35
|
]
|
|
36
36
|
/**
|
|
37
37
|
* Channel Configurations
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "music-metadata",
|
|
3
3
|
"description": "Music metadata parser for Node.js, supporting virtual any audio and tag format.",
|
|
4
|
-
"version": "11.
|
|
4
|
+
"version": "11.14.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Borewit",
|
|
7
7
|
"url": "https://github.com/Borewit"
|
|
@@ -124,20 +124,20 @@
|
|
|
124
124
|
"win-guid": "^0.2.1"
|
|
125
125
|
},
|
|
126
126
|
"devDependencies": {
|
|
127
|
-
"@biomejs/biome": "2.
|
|
127
|
+
"@biomejs/biome": "2.5.3",
|
|
128
128
|
"@types/chai": "^5.2.3",
|
|
129
129
|
"@types/chai-as-promised": "^8.0.2",
|
|
130
|
-
"@types/content-type": "^
|
|
131
|
-
"@types/debug": "^4.1.
|
|
130
|
+
"@types/content-type": "^2.0.0",
|
|
131
|
+
"@types/debug": "^4.1.13",
|
|
132
132
|
"@types/media-typer": "^1.1.3",
|
|
133
133
|
"@types/mocha": "^10.0.10",
|
|
134
|
-
"@types/node": "^
|
|
134
|
+
"@types/node": "^26.1.1",
|
|
135
135
|
"c8": "^11.0.0",
|
|
136
136
|
"chai": "^6.2.2",
|
|
137
137
|
"chai-as-promised": "^8.0.2",
|
|
138
138
|
"del-cli": "^7.0.0",
|
|
139
139
|
"mime": "^4.1.0",
|
|
140
|
-
"mocha": "^11.7.
|
|
140
|
+
"mocha": "^11.7.6",
|
|
141
141
|
"node-readable-to-web-readable-stream": "^0.4.2",
|
|
142
142
|
"remark-cli": "^12.0.1",
|
|
143
143
|
"remark-preset-lint-consistent": "^6.0.1",
|