-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
test-file-asf.ts
156 lines (125 loc) · 5.09 KB
/
test-file-asf.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import {assert} from 'chai';
import * as mm from '../src';
import * as path from 'path';
import GUID from "../src/asf/GUID";
import {AsfUtil} from "../src/asf/AsfUtil";
import {DataType} from "../src/asf/AsfObject";
import {Parsers} from './metadata-parsers';
const t = assert;
describe("Parse ASF", () => {
describe("GUID", () => {
it("should construct GUID from string", () => {
const Header_GUID = Buffer.from([
0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11,
0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C
]);
assert.deepEqual(GUID.HeaderObject.toBin(), Header_GUID);
});
});
/**
* Trying Buffer.readUIntLE(0, 8)
* Where 8 is 2 bytes longer then maximum allowed of 6
*/
it("should be able to roughly decode a 64-bit QWord", () => {
const tests: Array<{ raw: string, expected: number, description: string }> = [
{
raw: "\xFF\x00\x00\x00\x00\x00\x00\x00",
expected: 0xFF,
description: "8-bit"
},
{
raw: "\xFF\xFF\x00\x00\x00\x00\x00\x00",
expected: 0xFFFF,
description: "16-bit"
},
{
raw: "\xFF\xFF\xFF\xFF\x00\x00\x00\x00",
expected: 0xFFFFFFFF,
description: "32-bit"
},
{
raw: "\xFF\xFF\xFF\xFF\xFF\x00\x00\x00",
expected: 0xFFFFFFFFFF,
description: "40-bit"
},
{
raw: "\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00",
expected: 0xFFFFFFFFFFFF,
description: "48-bit"
},
{
raw: "\xFF\xFF\xFF\xFF\xFF\xFF\x0F\x00",
expected: 0xFFFFFFFFFFFFF,
description: "52-bit"
}
];
tests.forEach(test => {
const buf = Buffer.from(test.raw, "binary");
t.strictEqual(AsfUtil.getParserForAttr(DataType.QWord)(buf), test.expected, test.description);
});
});
describe("parse", () => {
const asfFilePath = path.join(__dirname, 'samples', 'asf.wma');
function checkFormat(format) {
t.strictEqual(format.dataformat, 'ASF/audio', 'format.dataformat');
t.strictEqual(format.duration, 244.885, 'format.duration');
t.strictEqual(format.bitrate, 192639, 'format.bitrate');
}
function checkCommon(common) {
t.strictEqual(common.title, "Don't Bring Me Down", 'common.title');
t.deepEqual(common.artist, 'Electric Light Orchestra', 'common.artist');
t.deepEqual(common.albumartist, 'Electric Light Orchestra', 'common.albumartist');
t.strictEqual(common.album, 'Discovery', 'common.album');
t.strictEqual(common.year, 2001, 'common.year');
t.deepEqual(common.track, {no: 9, of: null}, 'common.track 9/0');
t.deepEqual(common.disk, {no: null, of: null}, 'common.disk 0/0');
t.deepEqual(common.genre, ['Rock'], 'common.genre');
}
function checkNative(native: mm.INativeTagDict) {
t.deepEqual(native['WM/AlbumTitle'], ['Discovery'], 'native: WM/AlbumTitle');
t.deepEqual(native['WM/BeatsPerMinute'], [117], 'native: WM/BeatsPerMinute');
t.deepEqual(native.REPLAYGAIN_TRACK_GAIN, ['-4.7 dB'], 'native: REPLAYGAIN_TRACK_GAIN');
}
describe("should decode an ASF audio file (.wma)", () => {
Parsers.forEach(parser => {
it(parser.description, () => {
return parser.initParser(asfFilePath, 'audio/x-ms-wma', {native: true}).then(metadata => {
checkFormat(metadata.format);
checkCommon(metadata.common);
t.ok(metadata.native && metadata.native.asf, 'should include native ASF tags');
checkNative(mm.orderTags(metadata.native.asf));
});
});
});
});
describe("should decode picture from", () => {
Parsers.forEach(parser => {
it(parser.description, () => {
const filePath = path.join(__dirname, 'samples', 'issue_57.wma');
return parser.initParser(filePath, 'audio/x-ms-wma', {native: true}).then(metadata => {
const asf = mm.orderTags(metadata.native.asf);
assert.exists(asf['WM/Picture'][0], 'ASF WM/Picture should be set');
const nativePicture = asf['WM/Picture'][0];
assert.exists(nativePicture.data);
});
});
});
});
/**
* Related issue: https://github.com/Borewit/music-metadata/issues/68
*/
it("should be able to parse truncated .wma file", () => {
const filePath = path.join(__dirname, 'samples', '13 Thirty Dirty Birds.wma');
return mm.parseFile(filePath, {duration: true, native: true}).then(metadata => {
const asf = mm.orderTags(metadata.native.asf);
// ToDo: Contains some WM/... tags which could be parsed / mapped better
assert.strictEqual(metadata.common.title, "Thirty Dirty Birds", "metadata.common.title");
assert.strictEqual(metadata.common.artist, "The Red Hot Chili Peppers", "metadata.common.artist");
assert.strictEqual(metadata.common.date, "2003", "metadata.common.date");
assert.deepEqual(metadata.common.label, ["Capitol"], "metadata.common.label");
assert.strictEqual(metadata.common.track.no, 13, "metadata.common.track.no");
assert.exists(asf);
});
});
});
});