taglib-wasm 2.4.0 → 2.5.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/LICENSE +0 -29
- package/NOTICE +35 -0
- package/README.md +42 -36
- package/dist/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/assertClassBrand.js +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/checkPrivateRedeclaration.js +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/classPrivateFieldGet2.js +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/classPrivateFieldInitSpec.js +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/classPrivateFieldSet2.js +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/defineProperty.js +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/toPrimitive.js +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/toPropertyKey.js +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/typeof.js +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/usingCtx.js +1 -1
- package/dist/bwf/bext.d.ts.map +1 -1
- package/dist/bwf/bext.js +25 -16
- package/dist/constants/complex-properties.d.ts.map +1 -1
- package/dist/constants/general-extended-properties.d.ts +2 -1
- package/dist/constants/general-extended-properties.d.ts.map +1 -1
- package/dist/constants/general-extended-properties.js +5 -2
- package/dist/constants/properties.js +4 -2
- package/dist/constants/specialized-properties.d.ts +14 -0
- package/dist/constants/specialized-properties.d.ts.map +1 -1
- package/dist/constants/specialized-properties.js +21 -0
- package/dist/disc-folder.js +79 -45
- package/dist/folder-api/album-corroborate.d.ts.map +1 -1
- package/dist/folder-api/album-corroborate.js +25 -11
- package/dist/folder-api/album-discs.d.ts.map +1 -1
- package/dist/folder-api/album-discs.js +2 -5
- package/dist/folder-api/album-grouping.d.ts.map +1 -1
- package/dist/folder-api/album-grouping.js +27 -15
- package/dist/folder-api/album-identity.js +1 -1
- package/dist/folder-api/folder-disc.d.ts.map +1 -1
- package/dist/folder-api/folder-disc.js +24 -13
- package/dist/index.browser.d.ts +1 -1
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.browser.js +2 -4453
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/msgpack/encoder.d.ts.map +1 -1
- package/dist/msgpack/encoder.js +3 -1
- package/dist/rating.js +1 -2
- package/dist/runtime/module-loader.d.ts.map +1 -1
- package/dist/runtime/module-loader.js +43 -33
- package/dist/runtime/platform-io.d.ts.map +1 -1
- package/dist/runtime/platform-io.js +4 -2
- package/dist/runtime/unified-loader/module-loading.d.ts.map +1 -1
- package/dist/runtime/unified-loader/module-loading.js +3 -2
- package/dist/runtime/wasi-adapter/adapter.js +1 -1
- package/dist/runtime/wasi-adapter/audio-properties.d.ts.map +1 -1
- package/dist/runtime/wasi-adapter/audio-properties.js +8 -2
- package/dist/runtime/wasi-adapter/file-handle.d.ts +3 -1
- package/dist/runtime/wasi-adapter/file-handle.d.ts.map +1 -1
- package/dist/runtime/wasi-adapter/file-handle.js +17 -5
- package/dist/runtime/wasi-adapter/handle-state.d.ts.map +1 -1
- package/dist/runtime/wasi-adapter/handle-state.js +7 -1
- package/dist/runtime/wasi-adapter/index.js +1 -2
- package/dist/runtime/wasi-adapter/mp4-items.d.ts +24 -0
- package/dist/runtime/wasi-adapter/mp4-items.d.ts.map +1 -1
- package/dist/runtime/wasi-adapter/mp4-items.js +119 -2
- package/dist/runtime/wasi-adapter/property-surface.d.ts.map +1 -1
- package/dist/runtime/wasi-adapter/property-surface.js +15 -6
- package/dist/runtime/wasi-adapter/structured-fields.js +1 -1
- package/dist/runtime/wasi-adapter/tag-keys.d.ts.map +1 -1
- package/dist/runtime/wasi-adapter/tag-keys.js +3 -1
- package/dist/runtime/wasi-adapter/wasm-io.d.ts.map +1 -1
- package/dist/runtime/wasi-adapter/wasm-io.js +1 -1
- package/dist/runtime/wasi-memory.js +3 -3
- package/dist/simple/batch-operations.d.ts.map +1 -1
- package/dist/simple/batch-operations.js +5 -1
- package/dist/simple/picture-operations.d.ts +6 -0
- package/dist/simple/picture-operations.d.ts.map +1 -1
- package/dist/simple/picture-operations.js +6 -0
- package/dist/simple/tag-operations.d.ts +7 -0
- package/dist/simple/tag-operations.d.ts.map +1 -1
- package/dist/simple/tag-operations.js +7 -0
- package/dist/simple/with-audio-file.d.ts.map +1 -1
- package/dist/simple/with-audio-file.js +2 -1
- package/dist/simple.browser.js +2 -3670
- package/dist/taglib/audio-file-base.d.ts +35 -1
- package/dist/taglib/audio-file-base.d.ts.map +1 -1
- package/dist/taglib/audio-file-base.js +91 -21
- package/dist/taglib/audio-file-checksum.d.ts.map +1 -1
- package/dist/taglib/audio-file-checksum.js +17 -13
- package/dist/taglib/audio-file-impl.d.ts.map +1 -1
- package/dist/taglib/audio-file-impl.js +1 -1
- package/dist/taglib/audio-file-interface.d.ts +18 -1
- package/dist/taglib/audio-file-interface.d.ts.map +1 -1
- package/dist/taglib/embind-adapter.d.ts +3 -0
- package/dist/taglib/embind-adapter.d.ts.map +1 -1
- package/dist/taglib/embind-adapter.js +6 -0
- package/dist/taglib/extra-state-registry.d.ts.map +1 -1
- package/dist/taglib/extra-state-registry.js +15 -0
- package/dist/taglib/load-audio-data.d.ts +11 -8
- package/dist/taglib/load-audio-data.d.ts.map +1 -1
- package/dist/taglib/load-audio-data.js +39 -43
- package/dist/taglib/metadata-extent.d.ts.map +1 -1
- package/dist/taglib/metadata-extent.js +59 -32
- package/dist/taglib/mutable-tag-impl.d.ts.map +1 -1
- package/dist/taglib/mutable-tag-impl.js +72 -69
- package/dist/taglib/taglib-class.d.ts.map +1 -1
- package/dist/taglib/taglib-class.js +16 -6
- package/dist/taglib-wasi.wasm +0 -0
- package/dist/taglib-web.wasm +0 -0
- package/dist/taglib-wrapper.js +1 -1
- package/dist/types/metadata-mappings.d.ts.map +1 -1
- package/dist/types/metadata-mappings.js +8 -0
- package/dist/types/tags.d.ts +48 -0
- package/dist/types/tags.d.ts.map +1 -1
- package/dist/utils/mp4-freeform.d.ts +20 -0
- package/dist/utils/mp4-freeform.d.ts.map +1 -0
- package/dist/utils/mp4-freeform.js +111 -0
- package/dist/utils/path.d.ts.map +1 -1
- package/dist/utils/path.js +3 -1
- package/dist/utils/tag-mapping.d.ts.map +1 -1
- package/dist/utils/tag-mapping.js +30 -18
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/wasm.d.ts +3 -0
- package/dist/wasm.d.ts.map +1 -1
- package/dist/web-utils/data-url.js +1 -1
- package/dist/web.browser.js +2 -3388
- package/legal/COPYING.LGPL +502 -0
- package/package.json +17 -10
package/dist/web.browser.js
CHANGED
|
@@ -1,3388 +1,2 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __esmMin = (fn, res, err) => () => {
|
|
4
|
-
if (err) throw err[0];
|
|
5
|
-
try {
|
|
6
|
-
return fn && (res = fn(fn = 0)), res;
|
|
7
|
-
} catch (e) {
|
|
8
|
-
throw err = [e], e;
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
var __exportAll = (all, no_symbols) => {
|
|
12
|
-
let target = {};
|
|
13
|
-
for (var name in all) __defProp(target, name, {
|
|
14
|
-
get: all[name],
|
|
15
|
-
enumerable: true
|
|
16
|
-
});
|
|
17
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
18
|
-
return target;
|
|
19
|
-
};
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region src/errors/base.ts
|
|
22
|
-
var SUPPORTED_FORMATS, TagLibError;
|
|
23
|
-
var init_base = __esmMin((() => {
|
|
24
|
-
SUPPORTED_FORMATS = [
|
|
25
|
-
"MP3",
|
|
26
|
-
"AAC",
|
|
27
|
-
"MP4",
|
|
28
|
-
"M4A",
|
|
29
|
-
"FLAC",
|
|
30
|
-
"OGG",
|
|
31
|
-
"OPUS",
|
|
32
|
-
"OggFLAC",
|
|
33
|
-
"SPEEX",
|
|
34
|
-
"WAV",
|
|
35
|
-
"AIFF",
|
|
36
|
-
"ASF",
|
|
37
|
-
"APE",
|
|
38
|
-
"DSF",
|
|
39
|
-
"DSDIFF",
|
|
40
|
-
"WV",
|
|
41
|
-
"MPC",
|
|
42
|
-
"TTA",
|
|
43
|
-
"SHN",
|
|
44
|
-
"MOD",
|
|
45
|
-
"S3M",
|
|
46
|
-
"IT",
|
|
47
|
-
"XM",
|
|
48
|
-
"MATROSKA",
|
|
49
|
-
"MKA"
|
|
50
|
-
];
|
|
51
|
-
TagLibError = class TagLibError extends Error {
|
|
52
|
-
constructor(code, message, details) {
|
|
53
|
-
super(message);
|
|
54
|
-
this.code = code;
|
|
55
|
-
this.details = details;
|
|
56
|
-
this.name = "TagLibError";
|
|
57
|
-
Object.setPrototypeOf(this, TagLibError.prototype);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}));
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region src/errors/classes.ts
|
|
63
|
-
function errorMessage(error) {
|
|
64
|
-
return error instanceof Error ? error.message : String(error);
|
|
65
|
-
}
|
|
66
|
-
function createErrorMessage(prefix, details) {
|
|
67
|
-
return `${prefix}: ${details}`;
|
|
68
|
-
}
|
|
69
|
-
function formatFileSize(bytes) {
|
|
70
|
-
if (bytes < 1024) return `${bytes} bytes`;
|
|
71
|
-
if (bytes < 1048576) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
72
|
-
return `${(bytes / 1048576).toFixed(1)} MB`;
|
|
73
|
-
}
|
|
74
|
-
var TagLibInitializationError, InvalidFormatError, UnsupportedFormatError, FileOperationError, MetadataError, MemoryError, EnvironmentError;
|
|
75
|
-
var init_classes = __esmMin((() => {
|
|
76
|
-
init_base();
|
|
77
|
-
TagLibInitializationError = class TagLibInitializationError extends TagLibError {
|
|
78
|
-
constructor(message, details) {
|
|
79
|
-
super("INITIALIZATION", createErrorMessage("Failed to initialize TagLib Wasm module", message), details);
|
|
80
|
-
this.name = "TagLibInitializationError";
|
|
81
|
-
Object.setPrototypeOf(this, TagLibInitializationError.prototype);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
InvalidFormatError = class InvalidFormatError extends TagLibError {
|
|
85
|
-
constructor(message, bufferSize, details) {
|
|
86
|
-
const errorDetails = [`Invalid audio file format: ${message}`];
|
|
87
|
-
if (bufferSize !== void 0) {
|
|
88
|
-
errorDetails.push(`Buffer size: ${formatFileSize(bufferSize)}`);
|
|
89
|
-
if (bufferSize < 1024) errorDetails.push("Audio files must be at least 1KB to contain valid headers.");
|
|
90
|
-
}
|
|
91
|
-
super("INVALID_FORMAT", errorDetails.join(". "), {
|
|
92
|
-
...details,
|
|
93
|
-
bufferSize
|
|
94
|
-
});
|
|
95
|
-
this.bufferSize = bufferSize;
|
|
96
|
-
this.name = "InvalidFormatError";
|
|
97
|
-
Object.setPrototypeOf(this, InvalidFormatError.prototype);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
UnsupportedFormatError = class UnsupportedFormatError extends TagLibError {
|
|
101
|
-
constructor(format, supportedFormats = SUPPORTED_FORMATS, details) {
|
|
102
|
-
super("UNSUPPORTED_FORMAT", `Unsupported audio format: ${format}. Supported formats: ${supportedFormats.join(", ")}`, {
|
|
103
|
-
...details,
|
|
104
|
-
format,
|
|
105
|
-
supportedFormats
|
|
106
|
-
});
|
|
107
|
-
this.format = format;
|
|
108
|
-
this.supportedFormats = supportedFormats;
|
|
109
|
-
this.name = "UnsupportedFormatError";
|
|
110
|
-
Object.setPrototypeOf(this, UnsupportedFormatError.prototype);
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
FileOperationError = class FileOperationError extends TagLibError {
|
|
114
|
-
constructor(operation, message, path, details) {
|
|
115
|
-
const errorDetails = [`Failed to ${operation} file`];
|
|
116
|
-
if (path) errorDetails.push(`Path: ${path}`);
|
|
117
|
-
errorDetails.push(message);
|
|
118
|
-
super("FILE_OPERATION", errorDetails.join(". "), {
|
|
119
|
-
...details,
|
|
120
|
-
operation,
|
|
121
|
-
path
|
|
122
|
-
});
|
|
123
|
-
this.operation = operation;
|
|
124
|
-
this.path = path;
|
|
125
|
-
this.name = "FileOperationError";
|
|
126
|
-
Object.setPrototypeOf(this, FileOperationError.prototype);
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
MetadataError = class MetadataError extends TagLibError {
|
|
130
|
-
constructor(operation, message, field, details) {
|
|
131
|
-
const errorDetails = [`Failed to ${operation} metadata`];
|
|
132
|
-
if (field) errorDetails.push(`Field: ${field}`);
|
|
133
|
-
errorDetails.push(message);
|
|
134
|
-
super("METADATA", errorDetails.join(". "), {
|
|
135
|
-
...details,
|
|
136
|
-
operation,
|
|
137
|
-
field
|
|
138
|
-
});
|
|
139
|
-
this.operation = operation;
|
|
140
|
-
this.field = field;
|
|
141
|
-
this.name = "MetadataError";
|
|
142
|
-
Object.setPrototypeOf(this, MetadataError.prototype);
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
MemoryError = class MemoryError extends TagLibError {
|
|
146
|
-
constructor(message, details) {
|
|
147
|
-
super("MEMORY", createErrorMessage("Memory allocation failed", message), details);
|
|
148
|
-
this.name = "MemoryError";
|
|
149
|
-
Object.setPrototypeOf(this, MemoryError.prototype);
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
EnvironmentError = class EnvironmentError extends TagLibError {
|
|
153
|
-
constructor(environment, reason, requiredFeature) {
|
|
154
|
-
const message = requiredFeature ? `Environment '${environment}' ${reason}. Required feature: ${requiredFeature}.` : `Environment '${environment}' ${reason}.`;
|
|
155
|
-
super("ENVIRONMENT", message);
|
|
156
|
-
this.environment = environment;
|
|
157
|
-
this.reason = reason;
|
|
158
|
-
this.requiredFeature = requiredFeature;
|
|
159
|
-
this.name = "EnvironmentError";
|
|
160
|
-
Object.setPrototypeOf(this, EnvironmentError.prototype);
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
}));
|
|
164
|
-
//#endregion
|
|
165
|
-
//#region src/web-utils/data-url.ts
|
|
166
|
-
init_classes();
|
|
167
|
-
function pictureToDataURL(picture) {
|
|
168
|
-
const data = picture.data;
|
|
169
|
-
const CHUNK = 32768;
|
|
170
|
-
let binary = "";
|
|
171
|
-
for (let i = 0; i < data.length; i += CHUNK) binary += String.fromCharCode(...data.subarray(i, i + CHUNK));
|
|
172
|
-
const base64 = btoa(binary);
|
|
173
|
-
return `data:${picture.mimeType};base64,${base64}`;
|
|
174
|
-
}
|
|
175
|
-
function dataURLToPicture(dataURL, type = "FrontCover", description) {
|
|
176
|
-
const matches = /^data:([^;]+);base64,(.+)$/.exec(dataURL);
|
|
177
|
-
if (!matches) throw new InvalidFormatError("Invalid data URL format");
|
|
178
|
-
const [, mimeType, base64] = matches;
|
|
179
|
-
const binaryString = atob(base64);
|
|
180
|
-
const data = new Uint8Array(binaryString.length);
|
|
181
|
-
for (let i = 0; i < binaryString.length; i++) data[i] = binaryString.codePointAt(i);
|
|
182
|
-
return {
|
|
183
|
-
mimeType,
|
|
184
|
-
data,
|
|
185
|
-
type,
|
|
186
|
-
...description !== void 0 ? { description } : {}
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
//#endregion
|
|
190
|
-
//#region src/types/audio-formats.ts
|
|
191
|
-
function isNamedAudioInput(input) {
|
|
192
|
-
return typeof input === "object" && input !== null && "name" in input && "data" in input && !(input instanceof File) && !(input instanceof Uint8Array) && !(input instanceof ArrayBuffer);
|
|
193
|
-
}
|
|
194
|
-
var init_audio_formats = __esmMin((() => {}));
|
|
195
|
-
//#endregion
|
|
196
|
-
//#region src/types/tags.ts
|
|
197
|
-
var init_tags = __esmMin((() => {}));
|
|
198
|
-
//#endregion
|
|
199
|
-
//#region src/types/metadata-mappings.ts
|
|
200
|
-
var init_metadata_mappings = __esmMin((() => {}));
|
|
201
|
-
//#endregion
|
|
202
|
-
//#region src/types/pictures.ts
|
|
203
|
-
var PICTURE_TYPE_VALUES, PICTURE_TYPE_NAMES;
|
|
204
|
-
var init_pictures = __esmMin((() => {
|
|
205
|
-
PICTURE_TYPE_VALUES = {
|
|
206
|
-
Other: 0,
|
|
207
|
-
FileIcon: 1,
|
|
208
|
-
OtherFileIcon: 2,
|
|
209
|
-
FrontCover: 3,
|
|
210
|
-
BackCover: 4,
|
|
211
|
-
LeafletPage: 5,
|
|
212
|
-
Media: 6,
|
|
213
|
-
LeadArtist: 7,
|
|
214
|
-
Artist: 8,
|
|
215
|
-
Conductor: 9,
|
|
216
|
-
Band: 10,
|
|
217
|
-
Composer: 11,
|
|
218
|
-
Lyricist: 12,
|
|
219
|
-
RecordingLocation: 13,
|
|
220
|
-
DuringRecording: 14,
|
|
221
|
-
DuringPerformance: 15,
|
|
222
|
-
MovieScreenCapture: 16,
|
|
223
|
-
ColouredFish: 17,
|
|
224
|
-
Illustration: 18,
|
|
225
|
-
BandLogo: 19,
|
|
226
|
-
PublisherLogo: 20
|
|
227
|
-
};
|
|
228
|
-
PICTURE_TYPE_NAMES = {
|
|
229
|
-
0: "Other",
|
|
230
|
-
1: "FileIcon",
|
|
231
|
-
2: "OtherFileIcon",
|
|
232
|
-
3: "FrontCover",
|
|
233
|
-
4: "BackCover",
|
|
234
|
-
5: "LeafletPage",
|
|
235
|
-
6: "Media",
|
|
236
|
-
7: "LeadArtist",
|
|
237
|
-
8: "Artist",
|
|
238
|
-
9: "Conductor",
|
|
239
|
-
10: "Band",
|
|
240
|
-
11: "Composer",
|
|
241
|
-
12: "Lyricist",
|
|
242
|
-
13: "RecordingLocation",
|
|
243
|
-
14: "DuringRecording",
|
|
244
|
-
15: "DuringPerformance",
|
|
245
|
-
16: "MovieScreenCapture",
|
|
246
|
-
17: "ColouredFish",
|
|
247
|
-
18: "Illustration",
|
|
248
|
-
19: "BandLogo",
|
|
249
|
-
20: "PublisherLogo"
|
|
250
|
-
};
|
|
251
|
-
}));
|
|
252
|
-
//#endregion
|
|
253
|
-
//#region src/types/chapters.ts
|
|
254
|
-
var init_chapters = __esmMin((() => {}));
|
|
255
|
-
//#endregion
|
|
256
|
-
//#region src/types/bwf.ts
|
|
257
|
-
var init_bwf = __esmMin((() => {}));
|
|
258
|
-
//#endregion
|
|
259
|
-
//#region src/types/config.ts
|
|
260
|
-
var init_config = __esmMin((() => {}));
|
|
261
|
-
//#endregion
|
|
262
|
-
//#region src/types/format-property-keys.ts
|
|
263
|
-
var init_format_property_keys = __esmMin((() => {}));
|
|
264
|
-
//#endregion
|
|
265
|
-
//#region src/types/index.ts
|
|
266
|
-
var init_types$1 = __esmMin((() => {
|
|
267
|
-
init_audio_formats();
|
|
268
|
-
init_tags();
|
|
269
|
-
init_metadata_mappings();
|
|
270
|
-
init_pictures();
|
|
271
|
-
init_chapters();
|
|
272
|
-
init_bwf();
|
|
273
|
-
init_config();
|
|
274
|
-
init_format_property_keys();
|
|
275
|
-
}));
|
|
276
|
-
//#endregion
|
|
277
|
-
//#region src/types.ts
|
|
278
|
-
var init_types = __esmMin((() => {
|
|
279
|
-
init_types$1();
|
|
280
|
-
}));
|
|
281
|
-
//#endregion
|
|
282
|
-
//#region src/bwf/bext.ts
|
|
283
|
-
function readFixedString(bytes, offset, len) {
|
|
284
|
-
let end = offset;
|
|
285
|
-
const max = Math.min(offset + len, bytes.length);
|
|
286
|
-
while (end < max && bytes[end] !== 0) end++;
|
|
287
|
-
let s = "";
|
|
288
|
-
for (let i = offset; i < end; i++) s += String.fromCharCode(bytes[i]);
|
|
289
|
-
return s;
|
|
290
|
-
}
|
|
291
|
-
function writeFixedString(bytes, offset, len, value) {
|
|
292
|
-
for (let i = 0; i < len; i++) bytes[offset + i] = i < value.length ? value.charCodeAt(i) & 255 : 0;
|
|
293
|
-
}
|
|
294
|
-
function clampInt16(n) {
|
|
295
|
-
return Math.max(-32768, Math.min(32767, Math.round(n)));
|
|
296
|
-
}
|
|
297
|
-
function loudnessRaw(v) {
|
|
298
|
-
return v === void 0 ? LOUDNESS_UNSET : clampInt16(v * 100);
|
|
299
|
-
}
|
|
300
|
-
function loudnessFromRaw(raw) {
|
|
301
|
-
return raw === LOUDNESS_UNSET ? void 0 : raw / 100;
|
|
302
|
-
}
|
|
303
|
-
function bytesToHex(bytes) {
|
|
304
|
-
let s = "";
|
|
305
|
-
for (const b of bytes) s += b.toString(16).padStart(2, "0");
|
|
306
|
-
return s;
|
|
307
|
-
}
|
|
308
|
-
function hexToBytes(hex, outLen) {
|
|
309
|
-
const clean = hex.replace(/[^0-9a-fA-F]/g, "");
|
|
310
|
-
const out = new Uint8Array(outLen);
|
|
311
|
-
for (let i = 0; i + 1 < clean.length + 1 && i / 2 < outLen; i += 2) {
|
|
312
|
-
const pair = clean.slice(i, i + 2);
|
|
313
|
-
if (pair.length === 2) out[i / 2] = parseInt(pair, 16);
|
|
314
|
-
}
|
|
315
|
-
return out;
|
|
316
|
-
}
|
|
317
|
-
function decodeBext(bytes) {
|
|
318
|
-
if (bytes.length < 348) return void 0;
|
|
319
|
-
const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
320
|
-
const timeRefLow = dv.getUint32(338, true);
|
|
321
|
-
const timeRefHigh = dv.getUint32(342, true);
|
|
322
|
-
const version = dv.getUint16(VERSION_OFFSET, true);
|
|
323
|
-
const result = {
|
|
324
|
-
description: readFixedString(bytes, 0, 256),
|
|
325
|
-
originator: readFixedString(bytes, 256, 32),
|
|
326
|
-
originatorReference: readFixedString(bytes, 288, 32),
|
|
327
|
-
originationDate: readFixedString(bytes, 320, 10),
|
|
328
|
-
originationTime: readFixedString(bytes, 330, 8),
|
|
329
|
-
timeReferenceSamples: BigInt(timeRefHigh) << 32n | BigInt(timeRefLow),
|
|
330
|
-
version,
|
|
331
|
-
codingHistory: bytes.length > FIXED_PREFIX_LEN ? readFixedString(bytes, FIXED_PREFIX_LEN, bytes.length - FIXED_PREFIX_LEN) : ""
|
|
332
|
-
};
|
|
333
|
-
if (version >= 1 && bytes.length >= 412) result.umid = bytesToHex(bytes.subarray(UMID_OFFSET, 412));
|
|
334
|
-
if (version >= 2 && bytes.length >= 422) {
|
|
335
|
-
const lv = loudnessFromRaw(dv.getInt16(LOUDNESS_OFFSET, true));
|
|
336
|
-
const lr = loudnessFromRaw(dv.getInt16(414, true));
|
|
337
|
-
const mtp = loudnessFromRaw(dv.getInt16(416, true));
|
|
338
|
-
const mml = loudnessFromRaw(dv.getInt16(418, true));
|
|
339
|
-
const msl = loudnessFromRaw(dv.getInt16(420, true));
|
|
340
|
-
if (lv !== void 0) result.loudnessValueDb = lv;
|
|
341
|
-
if (lr !== void 0) result.loudnessRangeDb = lr;
|
|
342
|
-
if (mtp !== void 0) result.maxTruePeakLevelDbtp = mtp;
|
|
343
|
-
if (mml !== void 0) result.maxMomentaryLoudnessDb = mml;
|
|
344
|
-
if (msl !== void 0) result.maxShortTermLoudnessDb = msl;
|
|
345
|
-
}
|
|
346
|
-
return result;
|
|
347
|
-
}
|
|
348
|
-
function encodeBext(b) {
|
|
349
|
-
const codingHistory = b.codingHistory ?? "";
|
|
350
|
-
const bytes = new Uint8Array(FIXED_PREFIX_LEN + codingHistory.length);
|
|
351
|
-
const dv = new DataView(bytes.buffer);
|
|
352
|
-
const hasLoudness = b.loudnessValueDb !== void 0 || b.loudnessRangeDb !== void 0 || b.maxTruePeakLevelDbtp !== void 0 || b.maxMomentaryLoudnessDb !== void 0 || b.maxShortTermLoudnessDb !== void 0;
|
|
353
|
-
const version = Number.isInteger(b.version) ? b.version : hasLoudness ? 2 : b.umid ? 1 : 0;
|
|
354
|
-
writeFixedString(bytes, 0, 256, b.description ?? "");
|
|
355
|
-
writeFixedString(bytes, 256, 32, b.originator ?? "");
|
|
356
|
-
writeFixedString(bytes, 288, 32, b.originatorReference ?? "");
|
|
357
|
-
writeFixedString(bytes, 320, 10, b.originationDate ?? "");
|
|
358
|
-
writeFixedString(bytes, 330, 8, b.originationTime ?? "");
|
|
359
|
-
const tr = b.timeReferenceSamples ?? 0n;
|
|
360
|
-
dv.setUint32(338, Number(tr & 4294967295n), true);
|
|
361
|
-
dv.setUint32(342, Number(tr >> 32n & 4294967295n), true);
|
|
362
|
-
dv.setUint16(VERSION_OFFSET, version, true);
|
|
363
|
-
if (version >= 1 && b.umid) bytes.set(hexToBytes(b.umid, UMID_LEN), UMID_OFFSET);
|
|
364
|
-
if (version >= 2) {
|
|
365
|
-
dv.setInt16(LOUDNESS_OFFSET, loudnessRaw(b.loudnessValueDb), true);
|
|
366
|
-
dv.setInt16(414, loudnessRaw(b.loudnessRangeDb), true);
|
|
367
|
-
dv.setInt16(416, loudnessRaw(b.maxTruePeakLevelDbtp), true);
|
|
368
|
-
dv.setInt16(418, loudnessRaw(b.maxMomentaryLoudnessDb), true);
|
|
369
|
-
dv.setInt16(420, loudnessRaw(b.maxShortTermLoudnessDb), true);
|
|
370
|
-
}
|
|
371
|
-
writeFixedString(bytes, FIXED_PREFIX_LEN, codingHistory.length, codingHistory);
|
|
372
|
-
return bytes;
|
|
373
|
-
}
|
|
374
|
-
var FIXED_PREFIX_LEN, VERSION_OFFSET, UMID_OFFSET, UMID_LEN, LOUDNESS_OFFSET, LOUDNESS_UNSET;
|
|
375
|
-
var init_bext = __esmMin((() => {
|
|
376
|
-
FIXED_PREFIX_LEN = 602;
|
|
377
|
-
VERSION_OFFSET = 346;
|
|
378
|
-
UMID_OFFSET = 348;
|
|
379
|
-
UMID_LEN = 64;
|
|
380
|
-
LOUDNESS_OFFSET = 412;
|
|
381
|
-
LOUDNESS_UNSET = 32767;
|
|
382
|
-
}));
|
|
383
|
-
//#endregion
|
|
384
|
-
//#region src/errors/guards.ts
|
|
385
|
-
function isTagLibError(error) {
|
|
386
|
-
return error instanceof TagLibError;
|
|
387
|
-
}
|
|
388
|
-
function isInvalidFormatError(error) {
|
|
389
|
-
return error instanceof InvalidFormatError;
|
|
390
|
-
}
|
|
391
|
-
function isUnsupportedFormatError(error) {
|
|
392
|
-
return error instanceof UnsupportedFormatError;
|
|
393
|
-
}
|
|
394
|
-
function isFileOperationError(error) {
|
|
395
|
-
return error instanceof FileOperationError;
|
|
396
|
-
}
|
|
397
|
-
function isMetadataError(error) {
|
|
398
|
-
return error instanceof MetadataError;
|
|
399
|
-
}
|
|
400
|
-
function isMemoryError(error) {
|
|
401
|
-
return error instanceof MemoryError;
|
|
402
|
-
}
|
|
403
|
-
function isEnvironmentError(error) {
|
|
404
|
-
return error instanceof EnvironmentError;
|
|
405
|
-
}
|
|
406
|
-
var init_guards = __esmMin((() => {
|
|
407
|
-
init_base();
|
|
408
|
-
init_classes();
|
|
409
|
-
}));
|
|
410
|
-
//#endregion
|
|
411
|
-
//#region src/errors/index.ts
|
|
412
|
-
var init_errors$1 = __esmMin((() => {
|
|
413
|
-
init_base();
|
|
414
|
-
init_classes();
|
|
415
|
-
init_guards();
|
|
416
|
-
}));
|
|
417
|
-
//#endregion
|
|
418
|
-
//#region src/errors.ts
|
|
419
|
-
var init_errors = __esmMin((() => {
|
|
420
|
-
init_errors$1();
|
|
421
|
-
}));
|
|
422
|
-
//#endregion
|
|
423
|
-
//#region src/taglib/audio-file-bwf.ts
|
|
424
|
-
function requireBwf(format) {
|
|
425
|
-
if (!BWF_FORMATS.has(format)) throw new UnsupportedFormatError(format, ["WAV", "FLAC"], { operation: "BWF metadata" });
|
|
426
|
-
}
|
|
427
|
-
function getBextData(handle) {
|
|
428
|
-
const raw = handle.getBextData();
|
|
429
|
-
return raw && raw.length > 0 ? raw : void 0;
|
|
430
|
-
}
|
|
431
|
-
function setBextData(handle, format, data) {
|
|
432
|
-
requireBwf(format);
|
|
433
|
-
handle.setBextData(data);
|
|
434
|
-
}
|
|
435
|
-
function getBext(handle) {
|
|
436
|
-
const raw = handle.getBextData();
|
|
437
|
-
return raw && raw.length > 0 ? decodeBext(raw) : void 0;
|
|
438
|
-
}
|
|
439
|
-
function setBext(handle, format, bext) {
|
|
440
|
-
requireBwf(format);
|
|
441
|
-
handle.setBextData(encodeBext(bext));
|
|
442
|
-
}
|
|
443
|
-
function getIxml(handle) {
|
|
444
|
-
return handle.getIxml();
|
|
445
|
-
}
|
|
446
|
-
function setIxml(handle, format, data) {
|
|
447
|
-
requireBwf(format);
|
|
448
|
-
handle.setIxml(data);
|
|
449
|
-
}
|
|
450
|
-
var BWF_FORMATS;
|
|
451
|
-
var init_audio_file_bwf = __esmMin((() => {
|
|
452
|
-
init_bext();
|
|
453
|
-
init_errors();
|
|
454
|
-
BWF_FORMATS = /* @__PURE__ */ new Set(["WAV", "FLAC"]);
|
|
455
|
-
}));
|
|
456
|
-
//#endregion
|
|
457
|
-
//#region src/taglib/id3v2-frames.ts
|
|
458
|
-
function assertMp3(format) {
|
|
459
|
-
if (format !== "MP3" && format !== "AAC") throw new UnsupportedFormatError(format, ["MP3", "AAC"], { operation: "id3v2Frames" });
|
|
460
|
-
}
|
|
461
|
-
function assertFrameId(id, operation) {
|
|
462
|
-
if (!FRAME_ID_PATTERN.test(id)) throw new MetadataError(operation, `Invalid ID3v2 frame ID: "${id}". Frame IDs must match [A-Z0-9]{4}`, id);
|
|
463
|
-
}
|
|
464
|
-
function assertFrameBodies(id, data) {
|
|
465
|
-
for (const body of data) if (body.length === 0) throw new MetadataError("write", "Frame data must not be empty: zero-size ID3v2 frames are invalid", id);
|
|
466
|
-
}
|
|
467
|
-
function toPublicFrame(frame) {
|
|
468
|
-
return {
|
|
469
|
-
id: frame.id,
|
|
470
|
-
data: frame.data,
|
|
471
|
-
...frame.flags ? { flags: frame.flags } : {}
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
var FRAME_ID_PATTERN;
|
|
475
|
-
var init_id3v2_frames = __esmMin((() => {
|
|
476
|
-
init_classes();
|
|
477
|
-
FRAME_ID_PATTERN = /^[A-Z0-9]{4}$/;
|
|
478
|
-
}));
|
|
479
|
-
//#endregion
|
|
480
|
-
//#region \0taglib:platform-io-stub
|
|
481
|
-
function getPlatformIO() {
|
|
482
|
-
throw new Error("Filesystem operations are not available in the browser.");
|
|
483
|
-
}
|
|
484
|
-
var init__taglib_platform_io_stub = __esmMin((() => {}));
|
|
485
|
-
//#endregion
|
|
486
|
-
//#region src/utils/write.ts
|
|
487
|
-
async function writeFileData(path, data) {
|
|
488
|
-
try {
|
|
489
|
-
await getPlatformIO().writeFile(path, data);
|
|
490
|
-
} catch (error) {
|
|
491
|
-
if (error instanceof EnvironmentError) throw error;
|
|
492
|
-
throw new FileOperationError("write", error.message, path);
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
var init_write = __esmMin((() => {
|
|
496
|
-
init_errors();
|
|
497
|
-
init__taglib_platform_io_stub();
|
|
498
|
-
}));
|
|
499
|
-
//#endregion
|
|
500
|
-
//#region \0taglib:node-fs-stub
|
|
501
|
-
function getNodeFsSync() {
|
|
502
|
-
return null;
|
|
503
|
-
}
|
|
504
|
-
var init__taglib_node_fs_stub = __esmMin((() => {}));
|
|
505
|
-
//#endregion
|
|
506
|
-
//#region src/utils/rating.ts
|
|
507
|
-
function normalized(value) {
|
|
508
|
-
return value;
|
|
509
|
-
}
|
|
510
|
-
var init_rating = __esmMin((() => {}));
|
|
511
|
-
//#endregion
|
|
512
|
-
//#region src/runtime/detector.ts
|
|
513
|
-
function isDeno() {
|
|
514
|
-
return g.Deno !== void 0;
|
|
515
|
-
}
|
|
516
|
-
var g;
|
|
517
|
-
var init_detector = __esmMin((() => {
|
|
518
|
-
g = globalThis;
|
|
519
|
-
new Uint8Array([
|
|
520
|
-
0,
|
|
521
|
-
97,
|
|
522
|
-
115,
|
|
523
|
-
109,
|
|
524
|
-
1,
|
|
525
|
-
0,
|
|
526
|
-
0,
|
|
527
|
-
0,
|
|
528
|
-
6,
|
|
529
|
-
6,
|
|
530
|
-
1,
|
|
531
|
-
105,
|
|
532
|
-
0,
|
|
533
|
-
208,
|
|
534
|
-
105,
|
|
535
|
-
11
|
|
536
|
-
]);
|
|
537
|
-
}));
|
|
538
|
-
//#endregion
|
|
539
|
-
//#region src/constants/additional-properties.ts
|
|
540
|
-
var ADDITIONAL_PROPERTIES;
|
|
541
|
-
var init_additional_properties = __esmMin((() => {
|
|
542
|
-
ADDITIONAL_PROPERTIES = {
|
|
543
|
-
albumArtistSort: {
|
|
544
|
-
key: "ALBUMARTISTSORT",
|
|
545
|
-
description: "Sort name for album artist (for alphabetization)",
|
|
546
|
-
type: "string",
|
|
547
|
-
supportedFormats: [
|
|
548
|
-
"ID3v2",
|
|
549
|
-
"MP4",
|
|
550
|
-
"Vorbis"
|
|
551
|
-
],
|
|
552
|
-
mappings: {
|
|
553
|
-
id3v2: { frame: "TSO2" },
|
|
554
|
-
vorbis: "ALBUMARTISTSORT",
|
|
555
|
-
mp4: "soaa"
|
|
556
|
-
}
|
|
557
|
-
},
|
|
558
|
-
composerSort: {
|
|
559
|
-
key: "COMPOSERSORT",
|
|
560
|
-
description: "Sort name for composer (for alphabetization)",
|
|
561
|
-
type: "string",
|
|
562
|
-
supportedFormats: [
|
|
563
|
-
"ID3v2",
|
|
564
|
-
"MP4",
|
|
565
|
-
"Vorbis"
|
|
566
|
-
],
|
|
567
|
-
mappings: {
|
|
568
|
-
id3v2: { frame: "TSOC" },
|
|
569
|
-
vorbis: "COMPOSERSORT",
|
|
570
|
-
mp4: "soco"
|
|
571
|
-
}
|
|
572
|
-
},
|
|
573
|
-
subtitle: {
|
|
574
|
-
key: "SUBTITLE",
|
|
575
|
-
description: "Subtitle or description refinement",
|
|
576
|
-
type: "string",
|
|
577
|
-
supportedFormats: [
|
|
578
|
-
"ID3v2",
|
|
579
|
-
"MP4",
|
|
580
|
-
"Vorbis"
|
|
581
|
-
],
|
|
582
|
-
mappings: {
|
|
583
|
-
id3v2: { frame: "TIT3" },
|
|
584
|
-
vorbis: "SUBTITLE",
|
|
585
|
-
mp4: "----:com.apple.iTunes:SUBTITLE"
|
|
586
|
-
}
|
|
587
|
-
},
|
|
588
|
-
label: {
|
|
589
|
-
key: "LABEL",
|
|
590
|
-
description: "Record label name",
|
|
591
|
-
type: "string",
|
|
592
|
-
supportedFormats: [
|
|
593
|
-
"ID3v2",
|
|
594
|
-
"MP4",
|
|
595
|
-
"Vorbis",
|
|
596
|
-
"WAV"
|
|
597
|
-
],
|
|
598
|
-
mappings: {
|
|
599
|
-
id3v2: { frame: "TPUB" },
|
|
600
|
-
vorbis: "LABEL",
|
|
601
|
-
mp4: "----:com.apple.iTunes:LABEL",
|
|
602
|
-
wav: "IPUB"
|
|
603
|
-
}
|
|
604
|
-
},
|
|
605
|
-
producer: {
|
|
606
|
-
key: "PRODUCER",
|
|
607
|
-
description: "Producer of the recording",
|
|
608
|
-
type: "string",
|
|
609
|
-
supportedFormats: [
|
|
610
|
-
"ID3v2",
|
|
611
|
-
"MP4",
|
|
612
|
-
"Vorbis"
|
|
613
|
-
],
|
|
614
|
-
mappings: {
|
|
615
|
-
id3v2: {
|
|
616
|
-
frame: "TXXX",
|
|
617
|
-
description: "PRODUCER"
|
|
618
|
-
},
|
|
619
|
-
vorbis: "PRODUCER",
|
|
620
|
-
mp4: "----:com.apple.iTunes:PRODUCER"
|
|
621
|
-
}
|
|
622
|
-
},
|
|
623
|
-
radioStationOwner: {
|
|
624
|
-
key: "RADIOSTATIONOWNER",
|
|
625
|
-
description: "Owner of the radio station",
|
|
626
|
-
type: "string",
|
|
627
|
-
supportedFormats: ["ID3v2"],
|
|
628
|
-
mappings: { id3v2: { frame: "TRSO" } }
|
|
629
|
-
},
|
|
630
|
-
asin: {
|
|
631
|
-
key: "ASIN",
|
|
632
|
-
description: "Amazon Standard Identification Number",
|
|
633
|
-
type: "string",
|
|
634
|
-
supportedFormats: [
|
|
635
|
-
"ID3v2",
|
|
636
|
-
"MP4",
|
|
637
|
-
"Vorbis"
|
|
638
|
-
],
|
|
639
|
-
mappings: {
|
|
640
|
-
id3v2: {
|
|
641
|
-
frame: "TXXX",
|
|
642
|
-
description: "ASIN"
|
|
643
|
-
},
|
|
644
|
-
vorbis: "ASIN",
|
|
645
|
-
mp4: "----:com.apple.iTunes:ASIN"
|
|
646
|
-
}
|
|
647
|
-
},
|
|
648
|
-
musicbrainzReleaseArtistId: {
|
|
649
|
-
key: "MUSICBRAINZ_ALBUMARTISTID",
|
|
650
|
-
description: "MusicBrainz Release Artist ID (UUID)",
|
|
651
|
-
type: "string",
|
|
652
|
-
supportedFormats: [
|
|
653
|
-
"ID3v2",
|
|
654
|
-
"MP4",
|
|
655
|
-
"Vorbis"
|
|
656
|
-
],
|
|
657
|
-
mappings: {
|
|
658
|
-
id3v2: {
|
|
659
|
-
frame: "TXXX",
|
|
660
|
-
description: "MusicBrainz Album Artist Id"
|
|
661
|
-
},
|
|
662
|
-
vorbis: "MUSICBRAINZ_ALBUMARTISTID",
|
|
663
|
-
mp4: "----:com.apple.iTunes:MusicBrainz Album Artist Id"
|
|
664
|
-
}
|
|
665
|
-
},
|
|
666
|
-
musicbrainzWorkId: {
|
|
667
|
-
key: "MUSICBRAINZ_WORKID",
|
|
668
|
-
description: "MusicBrainz Work ID (UUID)",
|
|
669
|
-
type: "string",
|
|
670
|
-
supportedFormats: [
|
|
671
|
-
"ID3v2",
|
|
672
|
-
"MP4",
|
|
673
|
-
"Vorbis"
|
|
674
|
-
],
|
|
675
|
-
mappings: {
|
|
676
|
-
id3v2: {
|
|
677
|
-
frame: "TXXX",
|
|
678
|
-
description: "MusicBrainz Work Id"
|
|
679
|
-
},
|
|
680
|
-
vorbis: "MUSICBRAINZ_WORKID",
|
|
681
|
-
mp4: "----:com.apple.iTunes:MusicBrainz Work Id"
|
|
682
|
-
}
|
|
683
|
-
},
|
|
684
|
-
musicbrainzReleaseTrackId: {
|
|
685
|
-
key: "MUSICBRAINZ_RELEASETRACKID",
|
|
686
|
-
description: "MusicBrainz Release Track ID (UUID)",
|
|
687
|
-
type: "string",
|
|
688
|
-
supportedFormats: [
|
|
689
|
-
"ID3v2",
|
|
690
|
-
"MP4",
|
|
691
|
-
"Vorbis"
|
|
692
|
-
],
|
|
693
|
-
mappings: {
|
|
694
|
-
id3v2: {
|
|
695
|
-
frame: "TXXX",
|
|
696
|
-
description: "MusicBrainz Release Track Id"
|
|
697
|
-
},
|
|
698
|
-
vorbis: "MUSICBRAINZ_RELEASETRACKID",
|
|
699
|
-
mp4: "----:com.apple.iTunes:MusicBrainz Release Track Id"
|
|
700
|
-
}
|
|
701
|
-
},
|
|
702
|
-
podcastId: {
|
|
703
|
-
key: "PODCASTID",
|
|
704
|
-
description: "Podcast episode identifier",
|
|
705
|
-
type: "string",
|
|
706
|
-
supportedFormats: [
|
|
707
|
-
"ID3v2",
|
|
708
|
-
"MP4",
|
|
709
|
-
"Vorbis"
|
|
710
|
-
],
|
|
711
|
-
mappings: {
|
|
712
|
-
id3v2: { frame: "TGID" },
|
|
713
|
-
vorbis: "PODCASTID",
|
|
714
|
-
mp4: "egid"
|
|
715
|
-
}
|
|
716
|
-
},
|
|
717
|
-
podcastUrl: {
|
|
718
|
-
key: "PODCASTURL",
|
|
719
|
-
description: "Podcast feed URL",
|
|
720
|
-
type: "string",
|
|
721
|
-
supportedFormats: [
|
|
722
|
-
"ID3v2",
|
|
723
|
-
"MP4",
|
|
724
|
-
"Vorbis"
|
|
725
|
-
],
|
|
726
|
-
mappings: {
|
|
727
|
-
id3v2: { frame: "WFED" },
|
|
728
|
-
vorbis: "PODCASTURL",
|
|
729
|
-
mp4: "purl"
|
|
730
|
-
}
|
|
731
|
-
},
|
|
732
|
-
originalArtist: {
|
|
733
|
-
key: "ORIGINALARTIST",
|
|
734
|
-
description: "Original artist of a cover or remix",
|
|
735
|
-
type: "string",
|
|
736
|
-
supportedFormats: ["ID3v2", "Vorbis"],
|
|
737
|
-
mappings: {
|
|
738
|
-
id3v2: { frame: "TOPE" },
|
|
739
|
-
vorbis: "ORIGINALARTIST"
|
|
740
|
-
}
|
|
741
|
-
},
|
|
742
|
-
originalAlbum: {
|
|
743
|
-
key: "ORIGINALALBUM",
|
|
744
|
-
description: "Original album of a cover or remix",
|
|
745
|
-
type: "string",
|
|
746
|
-
supportedFormats: ["ID3v2", "Vorbis"],
|
|
747
|
-
mappings: {
|
|
748
|
-
id3v2: { frame: "TOAL" },
|
|
749
|
-
vorbis: "ORIGINALALBUM"
|
|
750
|
-
}
|
|
751
|
-
},
|
|
752
|
-
originalDate: {
|
|
753
|
-
key: "ORIGINALDATE",
|
|
754
|
-
description: "Original release date",
|
|
755
|
-
type: "string",
|
|
756
|
-
supportedFormats: [
|
|
757
|
-
"ID3v2",
|
|
758
|
-
"MP4",
|
|
759
|
-
"Vorbis"
|
|
760
|
-
],
|
|
761
|
-
mappings: {
|
|
762
|
-
id3v2: { frame: "TDOR" },
|
|
763
|
-
vorbis: "ORIGINALDATE",
|
|
764
|
-
mp4: "----:com.apple.iTunes:ORIGINALDATE"
|
|
765
|
-
}
|
|
766
|
-
},
|
|
767
|
-
script: {
|
|
768
|
-
key: "SCRIPT",
|
|
769
|
-
description: "Writing script used for text (e.g., Latn, Jpan)",
|
|
770
|
-
type: "string",
|
|
771
|
-
supportedFormats: ["MP4", "Vorbis"],
|
|
772
|
-
mappings: {
|
|
773
|
-
vorbis: "SCRIPT",
|
|
774
|
-
mp4: "----:com.apple.iTunes:SCRIPT"
|
|
775
|
-
}
|
|
776
|
-
},
|
|
777
|
-
involvedPeople: {
|
|
778
|
-
key: "INVOLVEDPEOPLE",
|
|
779
|
-
description: "List of involved people and their roles",
|
|
780
|
-
type: "string",
|
|
781
|
-
supportedFormats: ["ID3v2"],
|
|
782
|
-
mappings: { id3v2: { frame: "TIPL" } }
|
|
783
|
-
},
|
|
784
|
-
encoding: {
|
|
785
|
-
key: "ENCODING",
|
|
786
|
-
description: "Encoding software or settings",
|
|
787
|
-
type: "string",
|
|
788
|
-
supportedFormats: [
|
|
789
|
-
"ID3v2",
|
|
790
|
-
"MP4",
|
|
791
|
-
"Vorbis",
|
|
792
|
-
"WAV"
|
|
793
|
-
],
|
|
794
|
-
mappings: {
|
|
795
|
-
id3v2: { frame: "TSSE" },
|
|
796
|
-
vorbis: "ENCODING",
|
|
797
|
-
mp4: "©too",
|
|
798
|
-
wav: "ISFT"
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
};
|
|
802
|
-
}));
|
|
803
|
-
//#endregion
|
|
804
|
-
//#region src/constants/basic-properties.ts
|
|
805
|
-
var BASIC_PROPERTIES;
|
|
806
|
-
var init_basic_properties = __esmMin((() => {
|
|
807
|
-
BASIC_PROPERTIES = {
|
|
808
|
-
title: {
|
|
809
|
-
key: "TITLE",
|
|
810
|
-
description: "The title of the track",
|
|
811
|
-
type: "string",
|
|
812
|
-
supportedFormats: [
|
|
813
|
-
"ID3v2",
|
|
814
|
-
"MP4",
|
|
815
|
-
"Vorbis",
|
|
816
|
-
"WAV"
|
|
817
|
-
],
|
|
818
|
-
mappings: {
|
|
819
|
-
id3v2: { frame: "TIT2" },
|
|
820
|
-
vorbis: "TITLE",
|
|
821
|
-
mp4: "©nam",
|
|
822
|
-
wav: "INAM"
|
|
823
|
-
}
|
|
824
|
-
},
|
|
825
|
-
artist: {
|
|
826
|
-
key: "ARTIST",
|
|
827
|
-
description: "The primary performer(s) of the track",
|
|
828
|
-
type: "string",
|
|
829
|
-
supportedFormats: [
|
|
830
|
-
"ID3v2",
|
|
831
|
-
"MP4",
|
|
832
|
-
"Vorbis",
|
|
833
|
-
"WAV"
|
|
834
|
-
],
|
|
835
|
-
mappings: {
|
|
836
|
-
id3v2: { frame: "TPE1" },
|
|
837
|
-
vorbis: "ARTIST",
|
|
838
|
-
mp4: "©ART",
|
|
839
|
-
wav: "IART"
|
|
840
|
-
}
|
|
841
|
-
},
|
|
842
|
-
album: {
|
|
843
|
-
key: "ALBUM",
|
|
844
|
-
description: "The album/collection name",
|
|
845
|
-
type: "string",
|
|
846
|
-
supportedFormats: [
|
|
847
|
-
"ID3v2",
|
|
848
|
-
"MP4",
|
|
849
|
-
"Vorbis",
|
|
850
|
-
"WAV"
|
|
851
|
-
],
|
|
852
|
-
mappings: {
|
|
853
|
-
id3v2: { frame: "TALB" },
|
|
854
|
-
vorbis: "ALBUM",
|
|
855
|
-
mp4: "©alb",
|
|
856
|
-
wav: "IPRD"
|
|
857
|
-
}
|
|
858
|
-
},
|
|
859
|
-
date: {
|
|
860
|
-
key: "DATE",
|
|
861
|
-
description: "The date of recording (typically year)",
|
|
862
|
-
type: "string",
|
|
863
|
-
supportedFormats: [
|
|
864
|
-
"ID3v2",
|
|
865
|
-
"MP4",
|
|
866
|
-
"Vorbis",
|
|
867
|
-
"WAV"
|
|
868
|
-
],
|
|
869
|
-
mappings: {
|
|
870
|
-
id3v2: { frame: "TDRC" },
|
|
871
|
-
vorbis: "DATE",
|
|
872
|
-
mp4: "©day",
|
|
873
|
-
wav: "ICRD"
|
|
874
|
-
}
|
|
875
|
-
},
|
|
876
|
-
trackNumber: {
|
|
877
|
-
key: "TRACKNUMBER",
|
|
878
|
-
description: "The track number within the album",
|
|
879
|
-
type: "string",
|
|
880
|
-
supportedFormats: [
|
|
881
|
-
"ID3v2",
|
|
882
|
-
"MP4",
|
|
883
|
-
"Vorbis",
|
|
884
|
-
"WAV"
|
|
885
|
-
],
|
|
886
|
-
mappings: {
|
|
887
|
-
id3v2: { frame: "TRCK" },
|
|
888
|
-
vorbis: "TRACKNUMBER",
|
|
889
|
-
mp4: "trkn",
|
|
890
|
-
wav: "ITRK"
|
|
891
|
-
}
|
|
892
|
-
},
|
|
893
|
-
genre: {
|
|
894
|
-
key: "GENRE",
|
|
895
|
-
description: "The musical genre",
|
|
896
|
-
type: "string",
|
|
897
|
-
supportedFormats: [
|
|
898
|
-
"ID3v2",
|
|
899
|
-
"MP4",
|
|
900
|
-
"Vorbis",
|
|
901
|
-
"WAV"
|
|
902
|
-
],
|
|
903
|
-
mappings: {
|
|
904
|
-
id3v2: { frame: "TCON" },
|
|
905
|
-
vorbis: "GENRE",
|
|
906
|
-
mp4: "©gen",
|
|
907
|
-
wav: "IGNR"
|
|
908
|
-
}
|
|
909
|
-
},
|
|
910
|
-
comment: {
|
|
911
|
-
key: "COMMENT",
|
|
912
|
-
description: "Comments or notes about the track",
|
|
913
|
-
type: "string",
|
|
914
|
-
supportedFormats: [
|
|
915
|
-
"ID3v2",
|
|
916
|
-
"MP4",
|
|
917
|
-
"Vorbis",
|
|
918
|
-
"WAV"
|
|
919
|
-
],
|
|
920
|
-
mappings: {
|
|
921
|
-
id3v2: { frame: "COMM" },
|
|
922
|
-
vorbis: "COMMENT",
|
|
923
|
-
mp4: "©cmt",
|
|
924
|
-
wav: "ICMT"
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
};
|
|
928
|
-
}));
|
|
929
|
-
//#endregion
|
|
930
|
-
//#region src/constants/general-extended-properties.ts
|
|
931
|
-
var GENERAL_EXTENDED_PROPERTIES;
|
|
932
|
-
var init_general_extended_properties = __esmMin((() => {
|
|
933
|
-
GENERAL_EXTENDED_PROPERTIES = {
|
|
934
|
-
albumArtist: {
|
|
935
|
-
key: "ALBUMARTIST",
|
|
936
|
-
description: "The album artist (band/orchestra/ensemble)",
|
|
937
|
-
type: "string",
|
|
938
|
-
supportedFormats: [
|
|
939
|
-
"ID3v2",
|
|
940
|
-
"MP4",
|
|
941
|
-
"Vorbis"
|
|
942
|
-
],
|
|
943
|
-
mappings: {
|
|
944
|
-
id3v2: { frame: "TPE2" },
|
|
945
|
-
vorbis: "ALBUMARTIST",
|
|
946
|
-
mp4: "aART"
|
|
947
|
-
}
|
|
948
|
-
},
|
|
949
|
-
composer: {
|
|
950
|
-
key: "COMPOSER",
|
|
951
|
-
description: "The original composer(s) of the track",
|
|
952
|
-
type: "string",
|
|
953
|
-
supportedFormats: [
|
|
954
|
-
"ID3v2",
|
|
955
|
-
"MP4",
|
|
956
|
-
"Vorbis"
|
|
957
|
-
],
|
|
958
|
-
mappings: {
|
|
959
|
-
id3v2: { frame: "TCOM" },
|
|
960
|
-
vorbis: "COMPOSER",
|
|
961
|
-
mp4: "©wrt"
|
|
962
|
-
}
|
|
963
|
-
},
|
|
964
|
-
copyright: {
|
|
965
|
-
key: "COPYRIGHT",
|
|
966
|
-
description: "Copyright information",
|
|
967
|
-
type: "string",
|
|
968
|
-
supportedFormats: ["ID3v2", "Vorbis"],
|
|
969
|
-
mappings: { vorbis: "COPYRIGHT" }
|
|
970
|
-
},
|
|
971
|
-
encodedBy: {
|
|
972
|
-
key: "ENCODEDBY",
|
|
973
|
-
description: "The encoding software or person",
|
|
974
|
-
type: "string",
|
|
975
|
-
supportedFormats: ["ID3v2", "Vorbis"],
|
|
976
|
-
mappings: { vorbis: "ENCODEDBY" }
|
|
977
|
-
},
|
|
978
|
-
discNumber: {
|
|
979
|
-
key: "DISCNUMBER",
|
|
980
|
-
description: "The disc number for multi-disc sets",
|
|
981
|
-
type: "string",
|
|
982
|
-
supportedFormats: [
|
|
983
|
-
"ID3v2",
|
|
984
|
-
"MP4",
|
|
985
|
-
"Vorbis"
|
|
986
|
-
],
|
|
987
|
-
mappings: {
|
|
988
|
-
id3v2: { frame: "TPOS" },
|
|
989
|
-
vorbis: "DISCNUMBER",
|
|
990
|
-
mp4: "disk"
|
|
991
|
-
}
|
|
992
|
-
},
|
|
993
|
-
bpm: {
|
|
994
|
-
key: "BPM",
|
|
995
|
-
description: "Beats per minute",
|
|
996
|
-
type: "string",
|
|
997
|
-
supportedFormats: [
|
|
998
|
-
"ID3v2",
|
|
999
|
-
"MP4",
|
|
1000
|
-
"Vorbis"
|
|
1001
|
-
],
|
|
1002
|
-
mappings: {
|
|
1003
|
-
id3v2: { frame: "TBPM" },
|
|
1004
|
-
vorbis: "BPM",
|
|
1005
|
-
mp4: "tmpo"
|
|
1006
|
-
}
|
|
1007
|
-
},
|
|
1008
|
-
totalTracks: {
|
|
1009
|
-
key: "TRACKTOTAL",
|
|
1010
|
-
description: "Total number of tracks on the album",
|
|
1011
|
-
type: "string",
|
|
1012
|
-
supportedFormats: [
|
|
1013
|
-
"ID3v2",
|
|
1014
|
-
"MP4",
|
|
1015
|
-
"Vorbis"
|
|
1016
|
-
],
|
|
1017
|
-
mappings: {
|
|
1018
|
-
id3v2: { frame: "TRCK" },
|
|
1019
|
-
vorbis: "TRACKTOTAL",
|
|
1020
|
-
mp4: "trkn"
|
|
1021
|
-
}
|
|
1022
|
-
},
|
|
1023
|
-
totalDiscs: {
|
|
1024
|
-
key: "DISCTOTAL",
|
|
1025
|
-
description: "Total number of discs in the set",
|
|
1026
|
-
type: "string",
|
|
1027
|
-
supportedFormats: [
|
|
1028
|
-
"ID3v2",
|
|
1029
|
-
"MP4",
|
|
1030
|
-
"Vorbis"
|
|
1031
|
-
],
|
|
1032
|
-
mappings: {
|
|
1033
|
-
id3v2: { frame: "TPOS" },
|
|
1034
|
-
vorbis: "DISCTOTAL",
|
|
1035
|
-
mp4: "disk"
|
|
1036
|
-
}
|
|
1037
|
-
},
|
|
1038
|
-
compilation: {
|
|
1039
|
-
key: "COMPILATION",
|
|
1040
|
-
description: "Whether the album is a compilation (various artists)",
|
|
1041
|
-
type: "boolean",
|
|
1042
|
-
supportedFormats: [
|
|
1043
|
-
"ID3v2",
|
|
1044
|
-
"MP4",
|
|
1045
|
-
"Vorbis"
|
|
1046
|
-
],
|
|
1047
|
-
mappings: {
|
|
1048
|
-
id3v2: { frame: "TCMP" },
|
|
1049
|
-
vorbis: "COMPILATION",
|
|
1050
|
-
mp4: "cpil"
|
|
1051
|
-
}
|
|
1052
|
-
},
|
|
1053
|
-
titleSort: {
|
|
1054
|
-
key: "TITLESORT",
|
|
1055
|
-
description: "Sort name for title (for alphabetization)",
|
|
1056
|
-
type: "string",
|
|
1057
|
-
supportedFormats: [
|
|
1058
|
-
"ID3v2",
|
|
1059
|
-
"MP4",
|
|
1060
|
-
"Vorbis"
|
|
1061
|
-
],
|
|
1062
|
-
mappings: {
|
|
1063
|
-
id3v2: { frame: "TSOT" },
|
|
1064
|
-
vorbis: "TITLESORT",
|
|
1065
|
-
mp4: "sonm"
|
|
1066
|
-
}
|
|
1067
|
-
},
|
|
1068
|
-
artistSort: {
|
|
1069
|
-
key: "ARTISTSORT",
|
|
1070
|
-
description: "Sort name for artist (for alphabetization)",
|
|
1071
|
-
type: "string",
|
|
1072
|
-
supportedFormats: [
|
|
1073
|
-
"ID3v2",
|
|
1074
|
-
"MP4",
|
|
1075
|
-
"Vorbis"
|
|
1076
|
-
],
|
|
1077
|
-
mappings: {
|
|
1078
|
-
id3v2: { frame: "TSOP" },
|
|
1079
|
-
vorbis: "ARTISTSORT",
|
|
1080
|
-
mp4: "soar"
|
|
1081
|
-
}
|
|
1082
|
-
},
|
|
1083
|
-
albumSort: {
|
|
1084
|
-
key: "ALBUMSORT",
|
|
1085
|
-
description: "Sort name for album (for alphabetization)",
|
|
1086
|
-
type: "string",
|
|
1087
|
-
supportedFormats: [
|
|
1088
|
-
"ID3v2",
|
|
1089
|
-
"MP4",
|
|
1090
|
-
"Vorbis"
|
|
1091
|
-
],
|
|
1092
|
-
mappings: {
|
|
1093
|
-
id3v2: { frame: "TSOA" },
|
|
1094
|
-
vorbis: "ALBUMSORT",
|
|
1095
|
-
mp4: "soal"
|
|
1096
|
-
}
|
|
1097
|
-
},
|
|
1098
|
-
lyricist: {
|
|
1099
|
-
key: "LYRICIST",
|
|
1100
|
-
description: "The lyrics/text writer(s)",
|
|
1101
|
-
type: "string",
|
|
1102
|
-
supportedFormats: ["Vorbis"],
|
|
1103
|
-
mappings: { vorbis: "LYRICIST" }
|
|
1104
|
-
},
|
|
1105
|
-
conductor: {
|
|
1106
|
-
key: "CONDUCTOR",
|
|
1107
|
-
description: "The conductor",
|
|
1108
|
-
type: "string",
|
|
1109
|
-
supportedFormats: ["Vorbis"],
|
|
1110
|
-
mappings: { vorbis: "CONDUCTOR" }
|
|
1111
|
-
},
|
|
1112
|
-
remixedBy: {
|
|
1113
|
-
key: "REMIXER",
|
|
1114
|
-
description: "Person who remixed the track",
|
|
1115
|
-
type: "string",
|
|
1116
|
-
supportedFormats: [
|
|
1117
|
-
"ID3v2",
|
|
1118
|
-
"MP4",
|
|
1119
|
-
"Vorbis"
|
|
1120
|
-
],
|
|
1121
|
-
mappings: {
|
|
1122
|
-
id3v2: { frame: "TPE4" },
|
|
1123
|
-
vorbis: "REMIXER",
|
|
1124
|
-
mp4: "----:com.apple.iTunes:REMIXER"
|
|
1125
|
-
}
|
|
1126
|
-
},
|
|
1127
|
-
language: {
|
|
1128
|
-
key: "LANGUAGE",
|
|
1129
|
-
description: "Language of vocals/lyrics",
|
|
1130
|
-
type: "string",
|
|
1131
|
-
supportedFormats: ["Vorbis"],
|
|
1132
|
-
mappings: { vorbis: "LANGUAGE" }
|
|
1133
|
-
},
|
|
1134
|
-
publisher: {
|
|
1135
|
-
key: "PUBLISHER",
|
|
1136
|
-
description: "The publisher",
|
|
1137
|
-
type: "string",
|
|
1138
|
-
supportedFormats: ["Vorbis"],
|
|
1139
|
-
mappings: { vorbis: "PUBLISHER" }
|
|
1140
|
-
},
|
|
1141
|
-
mood: {
|
|
1142
|
-
key: "MOOD",
|
|
1143
|
-
description: "The mood/atmosphere of the track",
|
|
1144
|
-
type: "string",
|
|
1145
|
-
supportedFormats: ["Vorbis"],
|
|
1146
|
-
mappings: { vorbis: "MOOD" }
|
|
1147
|
-
},
|
|
1148
|
-
media: {
|
|
1149
|
-
key: "MEDIA",
|
|
1150
|
-
description: "Media type (CD, vinyl, etc.)",
|
|
1151
|
-
type: "string",
|
|
1152
|
-
supportedFormats: ["Vorbis"],
|
|
1153
|
-
mappings: { vorbis: "MEDIA" }
|
|
1154
|
-
},
|
|
1155
|
-
grouping: {
|
|
1156
|
-
key: "GROUPING",
|
|
1157
|
-
description: "Content group/work",
|
|
1158
|
-
type: "string",
|
|
1159
|
-
supportedFormats: ["Vorbis"],
|
|
1160
|
-
mappings: { vorbis: "GROUPING" }
|
|
1161
|
-
},
|
|
1162
|
-
work: {
|
|
1163
|
-
key: "WORK",
|
|
1164
|
-
description: "Work name",
|
|
1165
|
-
type: "string",
|
|
1166
|
-
supportedFormats: ["Vorbis"],
|
|
1167
|
-
mappings: { vorbis: "WORK" }
|
|
1168
|
-
},
|
|
1169
|
-
lyrics: {
|
|
1170
|
-
key: "LYRICS",
|
|
1171
|
-
description: "Lyrics content",
|
|
1172
|
-
type: "string",
|
|
1173
|
-
supportedFormats: ["Vorbis"],
|
|
1174
|
-
mappings: { vorbis: "LYRICS" }
|
|
1175
|
-
},
|
|
1176
|
-
isrc: {
|
|
1177
|
-
key: "ISRC",
|
|
1178
|
-
description: "International Standard Recording Code",
|
|
1179
|
-
type: "string",
|
|
1180
|
-
supportedFormats: ["Vorbis"],
|
|
1181
|
-
mappings: { vorbis: "ISRC" }
|
|
1182
|
-
},
|
|
1183
|
-
catalogNumber: {
|
|
1184
|
-
key: "CATALOGNUMBER",
|
|
1185
|
-
description: "Catalog number",
|
|
1186
|
-
type: "string",
|
|
1187
|
-
supportedFormats: ["Vorbis"],
|
|
1188
|
-
mappings: { vorbis: "CATALOGNUMBER" }
|
|
1189
|
-
},
|
|
1190
|
-
barcode: {
|
|
1191
|
-
key: "BARCODE",
|
|
1192
|
-
description: "Barcode (EAN/UPC)",
|
|
1193
|
-
type: "string",
|
|
1194
|
-
supportedFormats: ["Vorbis"],
|
|
1195
|
-
mappings: { vorbis: "BARCODE" }
|
|
1196
|
-
}
|
|
1197
|
-
};
|
|
1198
|
-
}));
|
|
1199
|
-
//#endregion
|
|
1200
|
-
//#region src/constants/specialized-properties.ts
|
|
1201
|
-
var SPECIALIZED_PROPERTIES;
|
|
1202
|
-
var init_specialized_properties = __esmMin((() => {
|
|
1203
|
-
SPECIALIZED_PROPERTIES = {
|
|
1204
|
-
musicbrainzArtistId: {
|
|
1205
|
-
key: "MUSICBRAINZ_ARTISTID",
|
|
1206
|
-
description: "MusicBrainz Artist ID (UUID)",
|
|
1207
|
-
type: "string",
|
|
1208
|
-
supportedFormats: [
|
|
1209
|
-
"ID3v2",
|
|
1210
|
-
"MP4",
|
|
1211
|
-
"Vorbis"
|
|
1212
|
-
],
|
|
1213
|
-
mappings: {
|
|
1214
|
-
id3v2: {
|
|
1215
|
-
frame: "TXXX",
|
|
1216
|
-
description: "MusicBrainz Artist Id"
|
|
1217
|
-
},
|
|
1218
|
-
vorbis: "MUSICBRAINZ_ARTISTID",
|
|
1219
|
-
mp4: "----:com.apple.iTunes:MusicBrainz Artist Id"
|
|
1220
|
-
}
|
|
1221
|
-
},
|
|
1222
|
-
musicbrainzReleaseId: {
|
|
1223
|
-
key: "MUSICBRAINZ_ALBUMID",
|
|
1224
|
-
description: "MusicBrainz Release ID (UUID)",
|
|
1225
|
-
type: "string",
|
|
1226
|
-
supportedFormats: [
|
|
1227
|
-
"ID3v2",
|
|
1228
|
-
"MP4",
|
|
1229
|
-
"Vorbis"
|
|
1230
|
-
],
|
|
1231
|
-
mappings: {
|
|
1232
|
-
id3v2: {
|
|
1233
|
-
frame: "TXXX",
|
|
1234
|
-
description: "MusicBrainz Album Id"
|
|
1235
|
-
},
|
|
1236
|
-
vorbis: "MUSICBRAINZ_ALBUMID",
|
|
1237
|
-
mp4: "----:com.apple.iTunes:MusicBrainz Album Id"
|
|
1238
|
-
}
|
|
1239
|
-
},
|
|
1240
|
-
musicbrainzTrackId: {
|
|
1241
|
-
key: "MUSICBRAINZ_TRACKID",
|
|
1242
|
-
description: "MusicBrainz Recording ID (UUID)",
|
|
1243
|
-
type: "string",
|
|
1244
|
-
supportedFormats: [
|
|
1245
|
-
"ID3v2",
|
|
1246
|
-
"MP4",
|
|
1247
|
-
"Vorbis"
|
|
1248
|
-
],
|
|
1249
|
-
mappings: {
|
|
1250
|
-
id3v2: {
|
|
1251
|
-
frame: "UFID",
|
|
1252
|
-
description: "http://musicbrainz.org"
|
|
1253
|
-
},
|
|
1254
|
-
vorbis: "MUSICBRAINZ_TRACKID",
|
|
1255
|
-
mp4: "----:com.apple.iTunes:MusicBrainz Track Id"
|
|
1256
|
-
}
|
|
1257
|
-
},
|
|
1258
|
-
musicbrainzReleaseGroupId: {
|
|
1259
|
-
key: "MUSICBRAINZ_RELEASEGROUPID",
|
|
1260
|
-
description: "MusicBrainz Release Group ID (UUID)",
|
|
1261
|
-
type: "string",
|
|
1262
|
-
supportedFormats: [
|
|
1263
|
-
"ID3v2",
|
|
1264
|
-
"MP4",
|
|
1265
|
-
"Vorbis"
|
|
1266
|
-
],
|
|
1267
|
-
mappings: {
|
|
1268
|
-
id3v2: {
|
|
1269
|
-
frame: "TXXX",
|
|
1270
|
-
description: "MusicBrainz Release Group Id"
|
|
1271
|
-
},
|
|
1272
|
-
vorbis: "MUSICBRAINZ_RELEASEGROUPID",
|
|
1273
|
-
mp4: "----:com.apple.iTunes:MusicBrainz Release Group Id"
|
|
1274
|
-
}
|
|
1275
|
-
},
|
|
1276
|
-
releaseType: {
|
|
1277
|
-
key: "RELEASETYPE",
|
|
1278
|
-
description: "Release type (album, single, EP, compilation, ...). Multi-value (e.g. 'album' + 'EP'). TagLib 2.3.2 translates the RELEASETYPE key per format: ID3v2 TXXX 'MUSICBRAINZ ALBUM TYPE' (TagLib's description casing), MP4 freeform atom, APEv2 MUSICBRAINZ_ALBUMTYPE, ASF 'MusicBrainz/Album Type', Vorbis/Matroska raw RELEASETYPE",
|
|
1279
|
-
type: "string",
|
|
1280
|
-
supportedFormats: [
|
|
1281
|
-
"ID3v2",
|
|
1282
|
-
"MP4",
|
|
1283
|
-
"Vorbis",
|
|
1284
|
-
"APE",
|
|
1285
|
-
"ASF",
|
|
1286
|
-
"Matroska"
|
|
1287
|
-
],
|
|
1288
|
-
mappings: {
|
|
1289
|
-
id3v2: {
|
|
1290
|
-
frame: "TXXX",
|
|
1291
|
-
description: "MusicBrainz Album Type"
|
|
1292
|
-
},
|
|
1293
|
-
vorbis: "RELEASETYPE",
|
|
1294
|
-
mp4: "----:com.apple.iTunes:MusicBrainz Album Type"
|
|
1295
|
-
}
|
|
1296
|
-
},
|
|
1297
|
-
releaseCountry: {
|
|
1298
|
-
key: "RELEASECOUNTRY",
|
|
1299
|
-
description: "Release country (ISO 3166-1 code, e.g. 'US'). TagLib 2.3.2 translates the RELEASECOUNTRY key per format: ID3v2 TXXX 'MUSICBRAINZ ALBUM RELEASE COUNTRY' (TagLib's description casing; an uppercase TXXX:RELEASECOUNTRY description also reads back), MP4 freeform atom 'MusicBrainz Album Release Country', APEv2 raw RELEASECOUNTRY, ASF 'MusicBrainz/Album Release Country', WAV ICNT, Vorbis/Matroska raw RELEASECOUNTRY",
|
|
1300
|
-
type: "string",
|
|
1301
|
-
supportedFormats: [
|
|
1302
|
-
"ID3v2",
|
|
1303
|
-
"MP4",
|
|
1304
|
-
"Vorbis",
|
|
1305
|
-
"APE",
|
|
1306
|
-
"ASF",
|
|
1307
|
-
"Matroska",
|
|
1308
|
-
"WAV"
|
|
1309
|
-
],
|
|
1310
|
-
mappings: {
|
|
1311
|
-
id3v2: {
|
|
1312
|
-
frame: "TXXX",
|
|
1313
|
-
description: "MusicBrainz Album Release Country"
|
|
1314
|
-
},
|
|
1315
|
-
vorbis: "RELEASECOUNTRY",
|
|
1316
|
-
mp4: "----:com.apple.iTunes:MusicBrainz Album Release Country"
|
|
1317
|
-
}
|
|
1318
|
-
},
|
|
1319
|
-
itunesAdvisory: {
|
|
1320
|
-
key: "ITUNESADVISORY",
|
|
1321
|
-
description: "Content advisory in the ITUNESADVISORY convention ('1' = explicit, '2' = clean, '0' = unspecified). On MP4 the value is stored in the native rtng atom and surfaced here. The typed tri-state lives on ExtendedTag.advisory; aliases CONTENTADVISORY and EXPLICIT resolve here",
|
|
1322
|
-
type: "string",
|
|
1323
|
-
supportedFormats: [
|
|
1324
|
-
"ID3v2",
|
|
1325
|
-
"MP4",
|
|
1326
|
-
"Vorbis",
|
|
1327
|
-
"APE",
|
|
1328
|
-
"ASF"
|
|
1329
|
-
],
|
|
1330
|
-
mappings: {
|
|
1331
|
-
id3v2: {
|
|
1332
|
-
frame: "TXXX",
|
|
1333
|
-
description: "ITUNESADVISORY"
|
|
1334
|
-
},
|
|
1335
|
-
vorbis: "ITUNESADVISORY",
|
|
1336
|
-
mp4: "----:com.apple.iTunes:ITUNESADVISORY"
|
|
1337
|
-
}
|
|
1338
|
-
},
|
|
1339
|
-
replayGainTrackGain: {
|
|
1340
|
-
key: "REPLAYGAIN_TRACK_GAIN",
|
|
1341
|
-
description: "ReplayGain track gain in dB (e.g., '-6.54 dB')",
|
|
1342
|
-
type: "string",
|
|
1343
|
-
supportedFormats: [
|
|
1344
|
-
"ID3v2",
|
|
1345
|
-
"MP4",
|
|
1346
|
-
"Vorbis"
|
|
1347
|
-
],
|
|
1348
|
-
mappings: {
|
|
1349
|
-
id3v2: {
|
|
1350
|
-
frame: "TXXX",
|
|
1351
|
-
description: "ReplayGain_Track_Gain"
|
|
1352
|
-
},
|
|
1353
|
-
vorbis: "REPLAYGAIN_TRACK_GAIN",
|
|
1354
|
-
mp4: "----:com.apple.iTunes:replaygain_track_gain"
|
|
1355
|
-
}
|
|
1356
|
-
},
|
|
1357
|
-
replayGainTrackPeak: {
|
|
1358
|
-
key: "REPLAYGAIN_TRACK_PEAK",
|
|
1359
|
-
description: "ReplayGain track peak value (0.0-1.0)",
|
|
1360
|
-
type: "string",
|
|
1361
|
-
supportedFormats: [
|
|
1362
|
-
"ID3v2",
|
|
1363
|
-
"MP4",
|
|
1364
|
-
"Vorbis"
|
|
1365
|
-
],
|
|
1366
|
-
mappings: {
|
|
1367
|
-
id3v2: {
|
|
1368
|
-
frame: "TXXX",
|
|
1369
|
-
description: "ReplayGain_Track_Peak"
|
|
1370
|
-
},
|
|
1371
|
-
vorbis: "REPLAYGAIN_TRACK_PEAK",
|
|
1372
|
-
mp4: "----:com.apple.iTunes:replaygain_track_peak"
|
|
1373
|
-
}
|
|
1374
|
-
},
|
|
1375
|
-
replayGainAlbumGain: {
|
|
1376
|
-
key: "REPLAYGAIN_ALBUM_GAIN",
|
|
1377
|
-
description: "ReplayGain album gain in dB",
|
|
1378
|
-
type: "string",
|
|
1379
|
-
supportedFormats: [
|
|
1380
|
-
"ID3v2",
|
|
1381
|
-
"MP4",
|
|
1382
|
-
"Vorbis"
|
|
1383
|
-
],
|
|
1384
|
-
mappings: {
|
|
1385
|
-
id3v2: {
|
|
1386
|
-
frame: "TXXX",
|
|
1387
|
-
description: "ReplayGain_Album_Gain"
|
|
1388
|
-
},
|
|
1389
|
-
vorbis: "REPLAYGAIN_ALBUM_GAIN",
|
|
1390
|
-
mp4: "----:com.apple.iTunes:replaygain_album_gain"
|
|
1391
|
-
}
|
|
1392
|
-
},
|
|
1393
|
-
replayGainAlbumPeak: {
|
|
1394
|
-
key: "REPLAYGAIN_ALBUM_PEAK",
|
|
1395
|
-
description: "ReplayGain album peak value (0.0-1.0)",
|
|
1396
|
-
type: "string",
|
|
1397
|
-
supportedFormats: [
|
|
1398
|
-
"ID3v2",
|
|
1399
|
-
"MP4",
|
|
1400
|
-
"Vorbis"
|
|
1401
|
-
],
|
|
1402
|
-
mappings: {
|
|
1403
|
-
id3v2: {
|
|
1404
|
-
frame: "TXXX",
|
|
1405
|
-
description: "ReplayGain_Album_Peak"
|
|
1406
|
-
},
|
|
1407
|
-
vorbis: "REPLAYGAIN_ALBUM_PEAK",
|
|
1408
|
-
mp4: "----:com.apple.iTunes:replaygain_album_peak"
|
|
1409
|
-
}
|
|
1410
|
-
},
|
|
1411
|
-
r128TrackGain: {
|
|
1412
|
-
key: "R128_TRACK_GAIN",
|
|
1413
|
-
description: "EBU R128 track loudness gain (RFC 7845), raw wire value: signed Q7.8 integer (dB x 256, e.g. '-573' = -2.23828125 dB). readTags() converts to a decibel number (see ExtendedTag.r128TrackGain)",
|
|
1414
|
-
type: "string",
|
|
1415
|
-
supportedFormats: [
|
|
1416
|
-
"ID3v2",
|
|
1417
|
-
"MP4",
|
|
1418
|
-
"Vorbis",
|
|
1419
|
-
"ASF"
|
|
1420
|
-
],
|
|
1421
|
-
mappings: {
|
|
1422
|
-
id3v2: {
|
|
1423
|
-
frame: "TXXX",
|
|
1424
|
-
description: "R128_TRACK_GAIN"
|
|
1425
|
-
},
|
|
1426
|
-
vorbis: "R128_TRACK_GAIN",
|
|
1427
|
-
mp4: "----:com.apple.iTunes:R128_TRACK_GAIN"
|
|
1428
|
-
}
|
|
1429
|
-
},
|
|
1430
|
-
r128AlbumGain: {
|
|
1431
|
-
key: "R128_ALBUM_GAIN",
|
|
1432
|
-
description: "EBU R128 album loudness gain (RFC 7845), raw wire value: signed Q7.8 integer (dB x 256). readTags() converts to a decibel number",
|
|
1433
|
-
type: "string",
|
|
1434
|
-
supportedFormats: [
|
|
1435
|
-
"ID3v2",
|
|
1436
|
-
"MP4",
|
|
1437
|
-
"Vorbis",
|
|
1438
|
-
"ASF"
|
|
1439
|
-
],
|
|
1440
|
-
mappings: {
|
|
1441
|
-
id3v2: {
|
|
1442
|
-
frame: "TXXX",
|
|
1443
|
-
description: "R128_ALBUM_GAIN"
|
|
1444
|
-
},
|
|
1445
|
-
vorbis: "R128_ALBUM_GAIN",
|
|
1446
|
-
mp4: "----:com.apple.iTunes:R128_ALBUM_GAIN"
|
|
1447
|
-
}
|
|
1448
|
-
},
|
|
1449
|
-
acoustidFingerprint: {
|
|
1450
|
-
key: "ACOUSTID_FINGERPRINT",
|
|
1451
|
-
description: "AcoustID fingerprint (Chromaprint)",
|
|
1452
|
-
type: "string",
|
|
1453
|
-
supportedFormats: [
|
|
1454
|
-
"ID3v2",
|
|
1455
|
-
"MP4",
|
|
1456
|
-
"Vorbis"
|
|
1457
|
-
],
|
|
1458
|
-
mappings: {
|
|
1459
|
-
id3v2: {
|
|
1460
|
-
frame: "TXXX",
|
|
1461
|
-
description: "Acoustid Fingerprint"
|
|
1462
|
-
},
|
|
1463
|
-
vorbis: "ACOUSTID_FINGERPRINT",
|
|
1464
|
-
mp4: "----:com.apple.iTunes:Acoustid Fingerprint"
|
|
1465
|
-
}
|
|
1466
|
-
},
|
|
1467
|
-
acoustidId: {
|
|
1468
|
-
key: "ACOUSTID_ID",
|
|
1469
|
-
description: "AcoustID UUID",
|
|
1470
|
-
type: "string",
|
|
1471
|
-
supportedFormats: [
|
|
1472
|
-
"ID3v2",
|
|
1473
|
-
"MP4",
|
|
1474
|
-
"Vorbis"
|
|
1475
|
-
],
|
|
1476
|
-
mappings: {
|
|
1477
|
-
id3v2: {
|
|
1478
|
-
frame: "TXXX",
|
|
1479
|
-
description: "Acoustid Id"
|
|
1480
|
-
},
|
|
1481
|
-
vorbis: "ACOUSTID_ID",
|
|
1482
|
-
mp4: "----:com.apple.iTunes:Acoustid Id"
|
|
1483
|
-
}
|
|
1484
|
-
},
|
|
1485
|
-
appleSoundCheck: {
|
|
1486
|
-
key: "ITUNNORM",
|
|
1487
|
-
description: "Apple Sound Check normalization data",
|
|
1488
|
-
type: "string",
|
|
1489
|
-
supportedFormats: [
|
|
1490
|
-
"ID3v2",
|
|
1491
|
-
"MP4",
|
|
1492
|
-
"Vorbis"
|
|
1493
|
-
],
|
|
1494
|
-
mappings: {
|
|
1495
|
-
id3v2: {
|
|
1496
|
-
frame: "TXXX",
|
|
1497
|
-
description: "iTunNORM"
|
|
1498
|
-
},
|
|
1499
|
-
vorbis: "ITUNNORM",
|
|
1500
|
-
mp4: "----:com.apple.iTunes:iTunNORM"
|
|
1501
|
-
}
|
|
1502
|
-
},
|
|
1503
|
-
appleGaplessInfo: {
|
|
1504
|
-
key: "ITUNSMPB",
|
|
1505
|
-
description: "Apple gapless playback data (encoder delay and padding)",
|
|
1506
|
-
type: "string",
|
|
1507
|
-
supportedFormats: [
|
|
1508
|
-
"ID3v2",
|
|
1509
|
-
"MP4",
|
|
1510
|
-
"Vorbis"
|
|
1511
|
-
],
|
|
1512
|
-
mappings: {
|
|
1513
|
-
id3v2: {
|
|
1514
|
-
frame: "TXXX",
|
|
1515
|
-
description: "iTunSMPB"
|
|
1516
|
-
},
|
|
1517
|
-
vorbis: "ITUNSMPB",
|
|
1518
|
-
mp4: "----:com.apple.iTunes:iTunSMPB"
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
};
|
|
1522
|
-
}));
|
|
1523
|
-
//#endregion
|
|
1524
|
-
//#region src/constants/properties.ts
|
|
1525
|
-
function toTagLibKey(key) {
|
|
1526
|
-
return _toTagLib[key] ?? key;
|
|
1527
|
-
}
|
|
1528
|
-
function mp4AtomWireKey(atom) {
|
|
1529
|
-
return _mp4AtomToWireKey[atom];
|
|
1530
|
-
}
|
|
1531
|
-
function mp4FreeformAtomNames(wireKeys) {
|
|
1532
|
-
const names = [];
|
|
1533
|
-
for (const key of wireKeys) {
|
|
1534
|
-
const atom = _mp4FreeformAtoms[key];
|
|
1535
|
-
if (atom !== void 0) names.push(atom);
|
|
1536
|
-
}
|
|
1537
|
-
return names;
|
|
1538
|
-
}
|
|
1539
|
-
function fromTagLibKey(key) {
|
|
1540
|
-
return _fromTagLib[key] ?? key;
|
|
1541
|
-
}
|
|
1542
|
-
function remapKeysFromTagLib(obj) {
|
|
1543
|
-
const result = {};
|
|
1544
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
1545
|
-
const canonical = READ_ALIASES[key];
|
|
1546
|
-
if (canonical !== void 0 && canonical in obj) continue;
|
|
1547
|
-
result[fromTagLibKey(key)] = value;
|
|
1548
|
-
}
|
|
1549
|
-
return result;
|
|
1550
|
-
}
|
|
1551
|
-
var PROPERTIES, _toTagLib, _fromTagLib, READ_ALIASES, _mp4FreeformAtoms, _mp4AtomToWireKey;
|
|
1552
|
-
var init_properties = __esmMin((() => {
|
|
1553
|
-
init_additional_properties();
|
|
1554
|
-
init_basic_properties();
|
|
1555
|
-
init_general_extended_properties();
|
|
1556
|
-
init_specialized_properties();
|
|
1557
|
-
PROPERTIES = {
|
|
1558
|
-
...BASIC_PROPERTIES,
|
|
1559
|
-
...GENERAL_EXTENDED_PROPERTIES,
|
|
1560
|
-
...SPECIALIZED_PROPERTIES,
|
|
1561
|
-
...ADDITIONAL_PROPERTIES
|
|
1562
|
-
};
|
|
1563
|
-
_toTagLib = {};
|
|
1564
|
-
_fromTagLib = {};
|
|
1565
|
-
for (const [camelKey, meta] of Object.entries(PROPERTIES)) {
|
|
1566
|
-
const wireKey = meta.key;
|
|
1567
|
-
_toTagLib[camelKey] = wireKey;
|
|
1568
|
-
_fromTagLib[wireKey] = camelKey;
|
|
1569
|
-
}
|
|
1570
|
-
_toTagLib["year"] = "DATE";
|
|
1571
|
-
_toTagLib["track"] = "TRACKNUMBER";
|
|
1572
|
-
_fromTagLib["disc"] = "discNumber";
|
|
1573
|
-
READ_ALIASES = {
|
|
1574
|
-
"ALBUM ARTIST": "ALBUMARTIST",
|
|
1575
|
-
ALBUM_ARTIST: "ALBUMARTIST",
|
|
1576
|
-
ORGANIZATION: "LABEL",
|
|
1577
|
-
PUBLISHER: "LABEL",
|
|
1578
|
-
UPC: "BARCODE",
|
|
1579
|
-
EAN: "BARCODE",
|
|
1580
|
-
GTIN: "BARCODE",
|
|
1581
|
-
TOTALTRACKS: "TRACKTOTAL",
|
|
1582
|
-
TOTALDISCS: "DISCTOTAL",
|
|
1583
|
-
MUSICBRAINZ_ALBUMTYPE: "RELEASETYPE",
|
|
1584
|
-
"MusicBrainz Album Type": "RELEASETYPE",
|
|
1585
|
-
CONTENTADVISORY: "ITUNESADVISORY",
|
|
1586
|
-
EXPLICIT: "ITUNESADVISORY"
|
|
1587
|
-
};
|
|
1588
|
-
for (const [alias, canonical] of Object.entries(READ_ALIASES)) if (_fromTagLib[alias] === void 0) _fromTagLib[alias] = _fromTagLib[canonical];
|
|
1589
|
-
_mp4FreeformAtoms = {};
|
|
1590
|
-
for (const meta of Object.values(PROPERTIES)) {
|
|
1591
|
-
const { key, mappings } = meta;
|
|
1592
|
-
const atom = mappings?.mp4;
|
|
1593
|
-
if (typeof atom !== "string" || !atom.startsWith("----:")) continue;
|
|
1594
|
-
const bare = atom.slice(atom.lastIndexOf(":") + 1);
|
|
1595
|
-
if (bare === bare.toUpperCase()) continue;
|
|
1596
|
-
_mp4FreeformAtoms[key] = atom;
|
|
1597
|
-
const readKey = bare.toUpperCase();
|
|
1598
|
-
const camel = _fromTagLib[key];
|
|
1599
|
-
if (camel !== void 0 && _fromTagLib[readKey] === void 0) _fromTagLib[readKey] = camel;
|
|
1600
|
-
}
|
|
1601
|
-
_mp4AtomToWireKey = {};
|
|
1602
|
-
for (const meta of Object.values(PROPERTIES)) {
|
|
1603
|
-
const { key, mappings } = meta;
|
|
1604
|
-
const atom = mappings?.mp4;
|
|
1605
|
-
if (typeof atom !== "string" || atom.startsWith("----:")) continue;
|
|
1606
|
-
if (_mp4AtomToWireKey[atom] === void 0) _mp4AtomToWireKey[atom] = key;
|
|
1607
|
-
}
|
|
1608
|
-
}));
|
|
1609
|
-
//#endregion
|
|
1610
|
-
//#region src/taglib/mp4-item-names.ts
|
|
1611
|
-
var MP4_ITEM_NAMES_KEY;
|
|
1612
|
-
var init_mp4_item_names = __esmMin((() => {
|
|
1613
|
-
MP4_ITEM_NAMES_KEY = "_mp4ItemNames";
|
|
1614
|
-
}));
|
|
1615
|
-
//#endregion
|
|
1616
|
-
//#region src/taglib/mutable-tag-impl.ts
|
|
1617
|
-
function buildMutableTag(handle) {
|
|
1618
|
-
let data = handle.getTagData();
|
|
1619
|
-
const tag = {
|
|
1620
|
-
get title() {
|
|
1621
|
-
return data.title;
|
|
1622
|
-
},
|
|
1623
|
-
get artist() {
|
|
1624
|
-
return data.artist;
|
|
1625
|
-
},
|
|
1626
|
-
get album() {
|
|
1627
|
-
return data.album;
|
|
1628
|
-
},
|
|
1629
|
-
get comment() {
|
|
1630
|
-
return data.comment;
|
|
1631
|
-
},
|
|
1632
|
-
get genre() {
|
|
1633
|
-
return data.genre;
|
|
1634
|
-
},
|
|
1635
|
-
get year() {
|
|
1636
|
-
return data.year;
|
|
1637
|
-
},
|
|
1638
|
-
get track() {
|
|
1639
|
-
return data.track;
|
|
1640
|
-
},
|
|
1641
|
-
get date() {
|
|
1642
|
-
return handle.getProperty("DATE") || void 0;
|
|
1643
|
-
},
|
|
1644
|
-
setTitle: (value) => {
|
|
1645
|
-
handle.setTagData({ title: value });
|
|
1646
|
-
data = handle.getTagData();
|
|
1647
|
-
return tag;
|
|
1648
|
-
},
|
|
1649
|
-
setArtist: (value) => {
|
|
1650
|
-
handle.setTagData({ artist: value });
|
|
1651
|
-
data = handle.getTagData();
|
|
1652
|
-
return tag;
|
|
1653
|
-
},
|
|
1654
|
-
setAlbum: (value) => {
|
|
1655
|
-
handle.setTagData({ album: value });
|
|
1656
|
-
data = handle.getTagData();
|
|
1657
|
-
return tag;
|
|
1658
|
-
},
|
|
1659
|
-
setComment: (value) => {
|
|
1660
|
-
handle.setTagData({ comment: value });
|
|
1661
|
-
data = handle.getTagData();
|
|
1662
|
-
return tag;
|
|
1663
|
-
},
|
|
1664
|
-
setGenre: (value) => {
|
|
1665
|
-
handle.setTagData({ genre: value });
|
|
1666
|
-
data = handle.getTagData();
|
|
1667
|
-
return tag;
|
|
1668
|
-
},
|
|
1669
|
-
setYear: (value) => {
|
|
1670
|
-
handle.setTagData({ year: value });
|
|
1671
|
-
data = handle.getTagData();
|
|
1672
|
-
return tag;
|
|
1673
|
-
},
|
|
1674
|
-
setTrack: (value) => {
|
|
1675
|
-
const existing = value > 0 ? handle.getProperty(RAW_TRACK_WIRE_KEY) : "";
|
|
1676
|
-
const slash = existing.indexOf("/");
|
|
1677
|
-
if (slash !== -1) handle.setProperty(RAW_TRACK_WIRE_KEY, `${value}${existing.slice(slash)}`);
|
|
1678
|
-
else handle.setTagData({ track: value });
|
|
1679
|
-
data = handle.getTagData();
|
|
1680
|
-
return tag;
|
|
1681
|
-
},
|
|
1682
|
-
setDate: (value) => {
|
|
1683
|
-
if (value === "") handle.setTagData({ year: 0 });
|
|
1684
|
-
else handle.setProperty("DATE", value);
|
|
1685
|
-
data = handle.getTagData();
|
|
1686
|
-
return tag;
|
|
1687
|
-
}
|
|
1688
|
-
};
|
|
1689
|
-
return tag;
|
|
1690
|
-
}
|
|
1691
|
-
var RAW_TRACK_WIRE_KEY;
|
|
1692
|
-
var init_mutable_tag_impl = __esmMin((() => {
|
|
1693
|
-
init_properties();
|
|
1694
|
-
RAW_TRACK_WIRE_KEY = toTagLibKey("trackNumber");
|
|
1695
|
-
}));
|
|
1696
|
-
//#endregion
|
|
1697
|
-
//#region src/taglib/auto-dispose.ts
|
|
1698
|
-
function registerAutoDispose(target, handle) {
|
|
1699
|
-
registry.register(target, handle, target);
|
|
1700
|
-
}
|
|
1701
|
-
function unregisterAutoDispose(target) {
|
|
1702
|
-
registry.unregister(target);
|
|
1703
|
-
}
|
|
1704
|
-
var registry;
|
|
1705
|
-
var init_auto_dispose = __esmMin((() => {
|
|
1706
|
-
registry = new FinalizationRegistry((handle) => {
|
|
1707
|
-
handle.destroy();
|
|
1708
|
-
});
|
|
1709
|
-
}));
|
|
1710
|
-
//#endregion
|
|
1711
|
-
//#region \0@oxc-project+runtime@0.152.0/helpers/esm/typeof.js
|
|
1712
|
-
function _typeof(o) {
|
|
1713
|
-
"@babel/helpers - typeof";
|
|
1714
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
1715
|
-
return typeof o;
|
|
1716
|
-
} : function(o) {
|
|
1717
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
1718
|
-
}, _typeof(o);
|
|
1719
|
-
}
|
|
1720
|
-
var init_typeof = __esmMin((() => {}));
|
|
1721
|
-
//#endregion
|
|
1722
|
-
//#region \0@oxc-project+runtime@0.152.0/helpers/esm/toPrimitive.js
|
|
1723
|
-
function toPrimitive(t, r) {
|
|
1724
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
1725
|
-
var e = t[Symbol.toPrimitive];
|
|
1726
|
-
if (void 0 !== e) {
|
|
1727
|
-
var i = e.call(t, r || "default");
|
|
1728
|
-
if ("object" != _typeof(i)) return i;
|
|
1729
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1730
|
-
}
|
|
1731
|
-
return ("string" === r ? String : Number)(t);
|
|
1732
|
-
}
|
|
1733
|
-
var init_toPrimitive = __esmMin((() => {
|
|
1734
|
-
init_typeof();
|
|
1735
|
-
}));
|
|
1736
|
-
//#endregion
|
|
1737
|
-
//#region \0@oxc-project+runtime@0.152.0/helpers/esm/toPropertyKey.js
|
|
1738
|
-
function toPropertyKey(t) {
|
|
1739
|
-
var i = toPrimitive(t, "string");
|
|
1740
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
1741
|
-
}
|
|
1742
|
-
var init_toPropertyKey = __esmMin((() => {
|
|
1743
|
-
init_typeof();
|
|
1744
|
-
init_toPrimitive();
|
|
1745
|
-
}));
|
|
1746
|
-
//#endregion
|
|
1747
|
-
//#region \0@oxc-project+runtime@0.152.0/helpers/esm/defineProperty.js
|
|
1748
|
-
function _defineProperty(e, r, t) {
|
|
1749
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
1750
|
-
value: t,
|
|
1751
|
-
enumerable: !0,
|
|
1752
|
-
configurable: !0,
|
|
1753
|
-
writable: !0
|
|
1754
|
-
}) : e[r] = t, e;
|
|
1755
|
-
}
|
|
1756
|
-
var init_defineProperty = __esmMin((() => {
|
|
1757
|
-
init_toPropertyKey();
|
|
1758
|
-
}));
|
|
1759
|
-
//#endregion
|
|
1760
|
-
//#region src/taglib/audio-file-base.ts
|
|
1761
|
-
var _Symbol$dispose, LYRICS_PROPERTY_KEY, LYRICS_WIRE_KEY, EMPTY_KEY_SET, BaseAudioFileImpl;
|
|
1762
|
-
var init_audio_file_base = __esmMin((() => {
|
|
1763
|
-
init_properties();
|
|
1764
|
-
init_errors();
|
|
1765
|
-
init_mp4_item_names();
|
|
1766
|
-
init_mutable_tag_impl();
|
|
1767
|
-
init_auto_dispose();
|
|
1768
|
-
init_defineProperty();
|
|
1769
|
-
LYRICS_PROPERTY_KEY = "lyrics";
|
|
1770
|
-
LYRICS_WIRE_KEY = toTagLibKey(LYRICS_PROPERTY_KEY);
|
|
1771
|
-
EMPTY_KEY_SET = /* @__PURE__ */ new Set();
|
|
1772
|
-
_Symbol$dispose = Symbol.dispose;
|
|
1773
|
-
BaseAudioFileImpl = class {
|
|
1774
|
-
constructor(module, fileHandle, sourcePath, originalSource, isPartiallyLoaded = false, partialLoadOptions) {
|
|
1775
|
-
this.module = module;
|
|
1776
|
-
_defineProperty(this, "fileHandle", void 0);
|
|
1777
|
-
_defineProperty(this, "cachedAudioProperties", null);
|
|
1778
|
-
_defineProperty(this, "sourcePath", void 0);
|
|
1779
|
-
_defineProperty(this, "originalSource", void 0);
|
|
1780
|
-
_defineProperty(this, "isPartiallyLoaded", false);
|
|
1781
|
-
_defineProperty(this, "partialLoadOptions", void 0);
|
|
1782
|
-
_defineProperty(this, "partialKeysAtLoad", void 0);
|
|
1783
|
-
this.fileHandle = fileHandle;
|
|
1784
|
-
this.sourcePath = sourcePath;
|
|
1785
|
-
this.originalSource = originalSource;
|
|
1786
|
-
this.isPartiallyLoaded = isPartiallyLoaded;
|
|
1787
|
-
this.partialLoadOptions = partialLoadOptions;
|
|
1788
|
-
this.partialKeysAtLoad = isPartiallyLoaded ? new Set(Object.keys(fileHandle.getProperties())) : void 0;
|
|
1789
|
-
registerAutoDispose(this, fileHandle);
|
|
1790
|
-
}
|
|
1791
|
-
partialDeletedPropertyKeys() {
|
|
1792
|
-
if (!this.partialKeysAtLoad) return EMPTY_KEY_SET;
|
|
1793
|
-
const current = new Set(Object.keys(this.handle.getProperties()));
|
|
1794
|
-
const deleted = /* @__PURE__ */ new Set();
|
|
1795
|
-
for (const key of this.partialKeysAtLoad) if (key !== LYRICS_WIRE_KEY && !current.has(key)) deleted.add(key);
|
|
1796
|
-
return deleted;
|
|
1797
|
-
}
|
|
1798
|
-
get handle() {
|
|
1799
|
-
if (!this.fileHandle) throw new MetadataError("read", "File handle has been disposed");
|
|
1800
|
-
return this.fileHandle;
|
|
1801
|
-
}
|
|
1802
|
-
getFormat() {
|
|
1803
|
-
return this.handle.getFormat();
|
|
1804
|
-
}
|
|
1805
|
-
isFormat(format) {
|
|
1806
|
-
return this.getFormat() === format;
|
|
1807
|
-
}
|
|
1808
|
-
tag() {
|
|
1809
|
-
return buildMutableTag(this.handle);
|
|
1810
|
-
}
|
|
1811
|
-
audioProperties() {
|
|
1812
|
-
if (!this.cachedAudioProperties) this.cachedAudioProperties = this.handle.getAudioProperties() ?? null;
|
|
1813
|
-
return this.cachedAudioProperties ?? void 0;
|
|
1814
|
-
}
|
|
1815
|
-
properties() {
|
|
1816
|
-
const remapped = remapKeysFromTagLib(this.handle.getProperties());
|
|
1817
|
-
delete remapped[LYRICS_PROPERTY_KEY];
|
|
1818
|
-
return remapped;
|
|
1819
|
-
}
|
|
1820
|
-
setProperties(properties) {
|
|
1821
|
-
const translated = {};
|
|
1822
|
-
for (const [key, values] of Object.entries(properties)) if (values !== void 0) translated[toTagLibKey(fromTagLibKey(key))] = values;
|
|
1823
|
-
if (!(LYRICS_WIRE_KEY in translated)) {
|
|
1824
|
-
const existing = this.handle.getProperties()[LYRICS_WIRE_KEY];
|
|
1825
|
-
if (existing !== void 0) translated[LYRICS_WIRE_KEY] = existing;
|
|
1826
|
-
}
|
|
1827
|
-
const atomNames = mp4FreeformAtomNames(Object.keys(translated));
|
|
1828
|
-
if (atomNames.length > 0) translated[MP4_ITEM_NAMES_KEY] = atomNames;
|
|
1829
|
-
this.handle.setProperties(translated);
|
|
1830
|
-
}
|
|
1831
|
-
getProperty(key) {
|
|
1832
|
-
const wireKey = toTagLibKey(fromTagLibKey(key));
|
|
1833
|
-
const values = this.handle.getProperties()[wireKey]?.filter((v) => v !== "");
|
|
1834
|
-
if (values !== void 0 && values.length > 0) return values;
|
|
1835
|
-
if (!this.isMP4()) return void 0;
|
|
1836
|
-
const remapped = this.properties()[key]?.filter((v) => v !== "");
|
|
1837
|
-
return remapped !== void 0 && remapped.length > 0 ? remapped : void 0;
|
|
1838
|
-
}
|
|
1839
|
-
setProperty(key, value) {
|
|
1840
|
-
const wireKey = toTagLibKey(fromTagLibKey(key));
|
|
1841
|
-
const atomNames = mp4FreeformAtomNames([wireKey]);
|
|
1842
|
-
if (atomNames.length > 0 && this.isMP4()) {
|
|
1843
|
-
if (value === "") {
|
|
1844
|
-
const prior = this.handle.getMp4ItemRemovals?.() ?? [];
|
|
1845
|
-
this.handle.setMp4ItemRemovals?.([.../* @__PURE__ */ new Set([...prior, ...atomNames])]);
|
|
1846
|
-
if (this.module.isWasi) this.handle.setProperties({
|
|
1847
|
-
...this.handle.getProperties(),
|
|
1848
|
-
[wireKey]: []
|
|
1849
|
-
});
|
|
1850
|
-
else {
|
|
1851
|
-
const rest = { ...this.handle.getProperties() };
|
|
1852
|
-
delete rest[wireKey];
|
|
1853
|
-
this.handle.setProperties(rest);
|
|
1854
|
-
}
|
|
1855
|
-
return;
|
|
1856
|
-
}
|
|
1857
|
-
this.handle.setProperties({
|
|
1858
|
-
...this.handle.getProperties(),
|
|
1859
|
-
[wireKey]: [value],
|
|
1860
|
-
[MP4_ITEM_NAMES_KEY]: atomNames
|
|
1861
|
-
});
|
|
1862
|
-
return;
|
|
1863
|
-
}
|
|
1864
|
-
this.handle.setProperty(wireKey, value);
|
|
1865
|
-
}
|
|
1866
|
-
removeProperty(key) {
|
|
1867
|
-
this.setProperty(key, "");
|
|
1868
|
-
}
|
|
1869
|
-
isMP4() {
|
|
1870
|
-
return this.handle.isMP4();
|
|
1871
|
-
}
|
|
1872
|
-
getMP4Item(key) {
|
|
1873
|
-
if (!this.isMP4()) throw new UnsupportedFormatError(this.getFormat(), ["MP4", "M4A"]);
|
|
1874
|
-
const wireKey = mp4AtomWireKey(key);
|
|
1875
|
-
const value = wireKey !== void 0 ? this.handle.getProperty(wireKey) : this.handle.getMP4Item(key);
|
|
1876
|
-
return value === "" ? void 0 : value;
|
|
1877
|
-
}
|
|
1878
|
-
setMP4Item(key, value) {
|
|
1879
|
-
if (!this.isMP4()) throw new UnsupportedFormatError(this.getFormat(), ["MP4", "M4A"]);
|
|
1880
|
-
const wireKey = mp4AtomWireKey(key);
|
|
1881
|
-
if (wireKey !== void 0) {
|
|
1882
|
-
this.handle.setProperty(wireKey, value);
|
|
1883
|
-
return;
|
|
1884
|
-
}
|
|
1885
|
-
this.handle.setMP4Item(key, value);
|
|
1886
|
-
}
|
|
1887
|
-
removeMP4Item(key) {
|
|
1888
|
-
if (!this.isMP4()) throw new UnsupportedFormatError(this.getFormat(), ["MP4", "M4A"]);
|
|
1889
|
-
this.handle.removeMP4Item(key);
|
|
1890
|
-
}
|
|
1891
|
-
isValid() {
|
|
1892
|
-
return this.handle.isValid();
|
|
1893
|
-
}
|
|
1894
|
-
dispose() {
|
|
1895
|
-
unregisterAutoDispose(this);
|
|
1896
|
-
if (this.fileHandle) {
|
|
1897
|
-
this.fileHandle.destroy();
|
|
1898
|
-
this.fileHandle = null;
|
|
1899
|
-
this.cachedAudioProperties = null;
|
|
1900
|
-
}
|
|
1901
|
-
}
|
|
1902
|
-
[_Symbol$dispose]() {
|
|
1903
|
-
this.dispose();
|
|
1904
|
-
}
|
|
1905
|
-
};
|
|
1906
|
-
}));
|
|
1907
|
-
//#endregion
|
|
1908
|
-
//#region src/taglib/metadata-extent.ts
|
|
1909
|
-
function be32(b, offset) {
|
|
1910
|
-
return (b[offset] << 24 | b[offset + 1] << 16 | b[offset + 2] << 8 | b[offset + 3]) >>> 0;
|
|
1911
|
-
}
|
|
1912
|
-
function startsWith(bytes, magic, at = 0) {
|
|
1913
|
-
if (bytes.length < at + magic.length) return false;
|
|
1914
|
-
for (let i = 0; i < magic.length; i++) if (bytes[at + i] !== magic.charCodeAt(i)) return false;
|
|
1915
|
-
return true;
|
|
1916
|
-
}
|
|
1917
|
-
function id3v2End(bytes) {
|
|
1918
|
-
if (!startsWith(bytes, "ID3") || bytes.length < 10) return void 0;
|
|
1919
|
-
const size = bytes[6] << 21 | bytes[7] << 14 | bytes[8] << 7 | bytes[9];
|
|
1920
|
-
const hasFooter = (bytes[5] & 16) !== 0;
|
|
1921
|
-
return 10 + size + (hasFooter ? 10 : 0);
|
|
1922
|
-
}
|
|
1923
|
-
function flacEnd(bytes, limit, start) {
|
|
1924
|
-
let offset = start + 4;
|
|
1925
|
-
for (;;) {
|
|
1926
|
-
if (offset + 4 > bytes.length) return void 0;
|
|
1927
|
-
const isLast = (bytes[offset] & 128) !== 0;
|
|
1928
|
-
const length = bytes[offset + 1] << 16 | bytes[offset + 2] << 8 | bytes[offset + 3];
|
|
1929
|
-
offset += 4 + length;
|
|
1930
|
-
if (offset > limit) return offset;
|
|
1931
|
-
if (isLast) return offset;
|
|
1932
|
-
}
|
|
1933
|
-
}
|
|
1934
|
-
function flacMarkerOffset(bytes) {
|
|
1935
|
-
const at = startsWith(bytes, "ID3") ? id3v2End(bytes) : 0;
|
|
1936
|
-
if (at === void 0) return void 0;
|
|
1937
|
-
return startsWith(bytes, "fLaC", at) ? at : void 0;
|
|
1938
|
-
}
|
|
1939
|
-
function flacAudioStart(bytes) {
|
|
1940
|
-
const at = flacMarkerOffset(bytes);
|
|
1941
|
-
if (at === void 0) return void 0;
|
|
1942
|
-
return flacEnd(bytes, bytes.length, at);
|
|
1943
|
-
}
|
|
1944
|
-
function mp4MoovEnd(bytes, limit, start) {
|
|
1945
|
-
let offset = start;
|
|
1946
|
-
const readable = Math.min(bytes.length, limit);
|
|
1947
|
-
while (offset + 8 <= readable) {
|
|
1948
|
-
const size = be32(bytes, offset);
|
|
1949
|
-
const type = String.fromCharCode(bytes[offset + 4], bytes[offset + 5], bytes[offset + 6], bytes[offset + 7]);
|
|
1950
|
-
if (size < 8) return void 0;
|
|
1951
|
-
if (type === "moov") return offset + size;
|
|
1952
|
-
offset += size;
|
|
1953
|
-
}
|
|
1954
|
-
}
|
|
1955
|
-
function oggMetadataEnd(bytes, limit, start) {
|
|
1956
|
-
let offset = start;
|
|
1957
|
-
let packetsCompleted = 0;
|
|
1958
|
-
let first = true;
|
|
1959
|
-
for (;;) {
|
|
1960
|
-
if (offset + 27 > bytes.length || !startsWith(bytes, "OggS", offset)) return;
|
|
1961
|
-
const segmentCount = bytes[offset + 26];
|
|
1962
|
-
const tableStart = offset + 27;
|
|
1963
|
-
if (tableStart + segmentCount > bytes.length) return void 0;
|
|
1964
|
-
let payload = 0;
|
|
1965
|
-
for (let i = 0; i < segmentCount; i++) {
|
|
1966
|
-
const segment = bytes[tableStart + i];
|
|
1967
|
-
payload += segment;
|
|
1968
|
-
if (segment < 255) packetsCompleted++;
|
|
1969
|
-
}
|
|
1970
|
-
if (first) {
|
|
1971
|
-
const payloadStart = tableStart + segmentCount;
|
|
1972
|
-
if (payloadStart + 5 > bytes.length) return void 0;
|
|
1973
|
-
if (bytes[payloadStart] === 127 && startsWith(bytes, "FLAC", payloadStart + 1)) return;
|
|
1974
|
-
first = false;
|
|
1975
|
-
}
|
|
1976
|
-
offset = tableStart + segmentCount + payload;
|
|
1977
|
-
if (packetsCompleted >= 2 || offset > limit) return offset;
|
|
1978
|
-
}
|
|
1979
|
-
}
|
|
1980
|
-
function mpegFrameLength(bytes, at) {
|
|
1981
|
-
if (bytes.length < at + 4) return 0;
|
|
1982
|
-
if (bytes[at] !== 255 || (bytes[at + 1] & 224) !== 224) return 0;
|
|
1983
|
-
const version = bytes[at + 1] >> 3 & 3;
|
|
1984
|
-
const layer = bytes[at + 1] >> 1 & 3;
|
|
1985
|
-
if (version === 1 || layer === 0) return 0;
|
|
1986
|
-
const bitrateIndex = bytes[at + 2] >> 4 & 15;
|
|
1987
|
-
const sampleRateIndex = bytes[at + 2] >> 2 & 3;
|
|
1988
|
-
if (bitrateIndex === 0 || bitrateIndex === 15 || sampleRateIndex === 3) return 0;
|
|
1989
|
-
const mpeg1 = version === 3;
|
|
1990
|
-
const layerIndex = layer ^ 3;
|
|
1991
|
-
const bitrate = MPEG_BITRATES[mpeg1 ? 0 : 1][layerIndex][bitrateIndex];
|
|
1992
|
-
const sampleRate = MPEG_SAMPLE_RATES[mpeg1 ? 0 : version === 2 ? 1 : 2][sampleRateIndex];
|
|
1993
|
-
let frameLength = Math.floor((layerIndex === 2 ? mpeg1 ? 1152 : 576 : layerIndex === 1 ? 1152 : 384) * bitrate * 125 / sampleRate);
|
|
1994
|
-
if ((bytes[at + 2] & 2) !== 0) frameLength += layerIndex === 0 ? 4 : 1;
|
|
1995
|
-
return frameLength === 0 ? 0 : frameLength;
|
|
1996
|
-
}
|
|
1997
|
-
function isMpegFrameSync(bytes, at = 0) {
|
|
1998
|
-
const frameLength = mpegFrameLength(bytes, at);
|
|
1999
|
-
if (frameLength === 0) return false;
|
|
2000
|
-
const next = at + frameLength;
|
|
2001
|
-
if (bytes.length < next + 4) return false;
|
|
2002
|
-
const mask = 4294839296;
|
|
2003
|
-
return ((bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3]) >>> 0 & mask) >>> 0 === ((bytes[next] << 24 | bytes[next + 1] << 16 | bytes[next + 2] << 8 | bytes[next + 3]) >>> 0 & mask) >>> 0;
|
|
2004
|
-
}
|
|
2005
|
-
function containerEnd(bytes, at, limit) {
|
|
2006
|
-
if (at >= bytes.length) return bytes.length < limit ? null : void 0;
|
|
2007
|
-
if (at + 8 > bytes.length) return void 0;
|
|
2008
|
-
if (startsWith(bytes, "fLaC", at)) return flacEnd(bytes, limit, at);
|
|
2009
|
-
if (startsWith(bytes, "ftyp", at + 4)) return mp4MoovEnd(bytes, limit, at);
|
|
2010
|
-
if (startsWith(bytes, "OggS", at)) return oggMetadataEnd(bytes, limit, at);
|
|
2011
|
-
return null;
|
|
2012
|
-
}
|
|
2013
|
-
function metadataFitsInHeader(header, limit) {
|
|
2014
|
-
let end;
|
|
2015
|
-
if (startsWith(header, "ID3")) {
|
|
2016
|
-
const tagEnd = id3v2End(header);
|
|
2017
|
-
if (tagEnd === void 0) return false;
|
|
2018
|
-
end = tagEnd;
|
|
2019
|
-
if (tagEnd <= limit) {
|
|
2020
|
-
const behind = containerEnd(header, tagEnd, limit);
|
|
2021
|
-
if (behind === void 0) return false;
|
|
2022
|
-
if (behind !== null) end = behind;
|
|
2023
|
-
}
|
|
2024
|
-
} else {
|
|
2025
|
-
const container = containerEnd(header, 0, limit);
|
|
2026
|
-
if (container === null) end = isMpegFrameSync(header) ? 0 : void 0;
|
|
2027
|
-
else end = container;
|
|
2028
|
-
}
|
|
2029
|
-
if (end === void 0 || end > header.length) return false;
|
|
2030
|
-
return end <= limit;
|
|
2031
|
-
}
|
|
2032
|
-
function trailerFitsInFooter(tail, footerSize) {
|
|
2033
|
-
if (tail.length < Math.min(footerSize, 32)) return false;
|
|
2034
|
-
for (const offsetFromEnd of [32, 160]) {
|
|
2035
|
-
const at = tail.length - offsetFromEnd;
|
|
2036
|
-
if (at < 0 || !startsWith(tail, "APETAGEX", at)) continue;
|
|
2037
|
-
const size = (tail[at + 12] | tail[at + 13] << 8 | tail[at + 14] << 16 | tail[at + 15] << 24) >>> 0;
|
|
2038
|
-
const trailing = offsetFromEnd === 32 ? 0 : 128;
|
|
2039
|
-
if (size + 32 + trailing > footerSize) return false;
|
|
2040
|
-
}
|
|
2041
|
-
return true;
|
|
2042
|
-
}
|
|
2043
|
-
var MPEG_BITRATES, MPEG_SAMPLE_RATES;
|
|
2044
|
-
var init_metadata_extent = __esmMin((() => {
|
|
2045
|
-
MPEG_BITRATES = [[
|
|
2046
|
-
[
|
|
2047
|
-
0,
|
|
2048
|
-
32,
|
|
2049
|
-
64,
|
|
2050
|
-
96,
|
|
2051
|
-
128,
|
|
2052
|
-
160,
|
|
2053
|
-
192,
|
|
2054
|
-
224,
|
|
2055
|
-
256,
|
|
2056
|
-
288,
|
|
2057
|
-
320,
|
|
2058
|
-
352,
|
|
2059
|
-
384,
|
|
2060
|
-
416,
|
|
2061
|
-
448,
|
|
2062
|
-
0
|
|
2063
|
-
],
|
|
2064
|
-
[
|
|
2065
|
-
0,
|
|
2066
|
-
32,
|
|
2067
|
-
48,
|
|
2068
|
-
56,
|
|
2069
|
-
64,
|
|
2070
|
-
80,
|
|
2071
|
-
96,
|
|
2072
|
-
112,
|
|
2073
|
-
128,
|
|
2074
|
-
160,
|
|
2075
|
-
192,
|
|
2076
|
-
224,
|
|
2077
|
-
256,
|
|
2078
|
-
320,
|
|
2079
|
-
384,
|
|
2080
|
-
0
|
|
2081
|
-
],
|
|
2082
|
-
[
|
|
2083
|
-
0,
|
|
2084
|
-
32,
|
|
2085
|
-
40,
|
|
2086
|
-
48,
|
|
2087
|
-
56,
|
|
2088
|
-
64,
|
|
2089
|
-
80,
|
|
2090
|
-
96,
|
|
2091
|
-
112,
|
|
2092
|
-
128,
|
|
2093
|
-
160,
|
|
2094
|
-
192,
|
|
2095
|
-
224,
|
|
2096
|
-
256,
|
|
2097
|
-
320,
|
|
2098
|
-
0
|
|
2099
|
-
]
|
|
2100
|
-
], [
|
|
2101
|
-
[
|
|
2102
|
-
0,
|
|
2103
|
-
32,
|
|
2104
|
-
48,
|
|
2105
|
-
56,
|
|
2106
|
-
64,
|
|
2107
|
-
80,
|
|
2108
|
-
96,
|
|
2109
|
-
112,
|
|
2110
|
-
128,
|
|
2111
|
-
144,
|
|
2112
|
-
160,
|
|
2113
|
-
176,
|
|
2114
|
-
192,
|
|
2115
|
-
224,
|
|
2116
|
-
256,
|
|
2117
|
-
0
|
|
2118
|
-
],
|
|
2119
|
-
[
|
|
2120
|
-
0,
|
|
2121
|
-
8,
|
|
2122
|
-
16,
|
|
2123
|
-
24,
|
|
2124
|
-
32,
|
|
2125
|
-
40,
|
|
2126
|
-
48,
|
|
2127
|
-
56,
|
|
2128
|
-
64,
|
|
2129
|
-
80,
|
|
2130
|
-
96,
|
|
2131
|
-
112,
|
|
2132
|
-
128,
|
|
2133
|
-
144,
|
|
2134
|
-
160,
|
|
2135
|
-
0
|
|
2136
|
-
],
|
|
2137
|
-
[
|
|
2138
|
-
0,
|
|
2139
|
-
8,
|
|
2140
|
-
16,
|
|
2141
|
-
24,
|
|
2142
|
-
32,
|
|
2143
|
-
40,
|
|
2144
|
-
48,
|
|
2145
|
-
56,
|
|
2146
|
-
64,
|
|
2147
|
-
80,
|
|
2148
|
-
96,
|
|
2149
|
-
112,
|
|
2150
|
-
128,
|
|
2151
|
-
144,
|
|
2152
|
-
160,
|
|
2153
|
-
0
|
|
2154
|
-
]
|
|
2155
|
-
]];
|
|
2156
|
-
MPEG_SAMPLE_RATES = [
|
|
2157
|
-
[
|
|
2158
|
-
44100,
|
|
2159
|
-
48e3,
|
|
2160
|
-
32e3
|
|
2161
|
-
],
|
|
2162
|
-
[
|
|
2163
|
-
22050,
|
|
2164
|
-
24e3,
|
|
2165
|
-
16e3
|
|
2166
|
-
],
|
|
2167
|
-
[
|
|
2168
|
-
11025,
|
|
2169
|
-
12e3,
|
|
2170
|
-
8e3
|
|
2171
|
-
]
|
|
2172
|
-
];
|
|
2173
|
-
}));
|
|
2174
|
-
//#endregion
|
|
2175
|
-
//#region src/taglib/media-ranges.ts
|
|
2176
|
-
function adtsFrameLength(bytes, at) {
|
|
2177
|
-
if (bytes.length < at + 7) return 0;
|
|
2178
|
-
if (bytes[at] !== 255 || (bytes[at + 1] & 246) !== 240) return 0;
|
|
2179
|
-
const length = (bytes[at + 3] & 3) << 11 | bytes[at + 4] << 3 | bytes[at + 5] >> 5;
|
|
2180
|
-
return length >= 7 ? length : 0;
|
|
2181
|
-
}
|
|
2182
|
-
function trailingTagStart(bytes, end = bytes.length) {
|
|
2183
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
2184
|
-
let at = Math.max(0, Math.min(end, bytes.length));
|
|
2185
|
-
for (;;) {
|
|
2186
|
-
if (at >= 128 && text(bytes, at - 128, 3) === "TAG") {
|
|
2187
|
-
at -= 128;
|
|
2188
|
-
continue;
|
|
2189
|
-
}
|
|
2190
|
-
if (at >= 32 && text(bytes, at - 32, 8) === "APETAGEX") {
|
|
2191
|
-
const size = view.getUint32(at - 32 + 12, true);
|
|
2192
|
-
const flags = view.getUint32(at - 32 + 20, true);
|
|
2193
|
-
const start = at - size - ((flags & 2147483648) !== 0 ? 32 : 0);
|
|
2194
|
-
if (start < 0 || start >= at) return at;
|
|
2195
|
-
at = start;
|
|
2196
|
-
continue;
|
|
2197
|
-
}
|
|
2198
|
-
return at;
|
|
2199
|
-
}
|
|
2200
|
-
}
|
|
2201
|
-
function firstFrame(bytes) {
|
|
2202
|
-
const from = id3v2End(bytes) ?? 0;
|
|
2203
|
-
const limit = Math.min(bytes.length - 6, from + MPEG_SCAN_LIMIT);
|
|
2204
|
-
for (let o = from; o < limit; o++) {
|
|
2205
|
-
const len = frameLengthAt(bytes, o);
|
|
2206
|
-
if (len > 0 && frameLengthAt(bytes, o + len) > 0) return o;
|
|
2207
|
-
}
|
|
2208
|
-
return -1;
|
|
2209
|
-
}
|
|
2210
|
-
function forwardLastFrame(bytes, from, end) {
|
|
2211
|
-
let o = from;
|
|
2212
|
-
let start = -1;
|
|
2213
|
-
let length = 0;
|
|
2214
|
-
let frames = 0;
|
|
2215
|
-
while (o + 6 <= end) {
|
|
2216
|
-
const len = frameLengthAt(bytes, o);
|
|
2217
|
-
if (len === 0 || o + len > end) break;
|
|
2218
|
-
start = o;
|
|
2219
|
-
length = len;
|
|
2220
|
-
frames++;
|
|
2221
|
-
o += len;
|
|
2222
|
-
}
|
|
2223
|
-
return {
|
|
2224
|
-
start,
|
|
2225
|
-
length,
|
|
2226
|
-
frames
|
|
2227
|
-
};
|
|
2228
|
-
}
|
|
2229
|
-
function walkMpeg(bytes) {
|
|
2230
|
-
const from = firstFrame(bytes);
|
|
2231
|
-
if (from < 0) return fallback("no valid first frame");
|
|
2232
|
-
const last = forwardLastFrame(bytes, from, trailingTagStart(bytes));
|
|
2233
|
-
if (last.start < 0) return fallback("no valid frames");
|
|
2234
|
-
return {
|
|
2235
|
-
kind: "ranges",
|
|
2236
|
-
ranges: [{
|
|
2237
|
-
offset: from,
|
|
2238
|
-
length: last.start + last.length - from
|
|
2239
|
-
}],
|
|
2240
|
-
detail: `first=${from} last=${last.start}+${last.length} frames=${last.frames}`
|
|
2241
|
-
};
|
|
2242
|
-
}
|
|
2243
|
-
function flacStreamInfoMd5(bytes) {
|
|
2244
|
-
const marker = flacMarkerOffset(bytes);
|
|
2245
|
-
if (marker === void 0) return void 0;
|
|
2246
|
-
const header = marker + 4;
|
|
2247
|
-
if (header + 4 > bytes.length) return void 0;
|
|
2248
|
-
if ((bytes[header] & 127) !== 0) return void 0;
|
|
2249
|
-
if ((bytes[header + 1] << 16 | bytes[header + 2] << 8 | bytes[header + 3]) < 34) return void 0;
|
|
2250
|
-
const payload = header + 4;
|
|
2251
|
-
if (payload + 34 > bytes.length) return void 0;
|
|
2252
|
-
let hex = "";
|
|
2253
|
-
for (const byte of bytes.subarray(payload + 18, payload + 34)) hex += byte.toString(16).padStart(2, "0");
|
|
2254
|
-
return hex;
|
|
2255
|
-
}
|
|
2256
|
-
function walkFlac(bytes) {
|
|
2257
|
-
const start = flacAudioStart(bytes);
|
|
2258
|
-
if (start === void 0) return fallback("no fLaC marker");
|
|
2259
|
-
const end = trailingTagStart(bytes);
|
|
2260
|
-
if (end <= start) return fallback("no audio bytes");
|
|
2261
|
-
return {
|
|
2262
|
-
kind: "ranges",
|
|
2263
|
-
ranges: [{
|
|
2264
|
-
offset: start,
|
|
2265
|
-
length: end - start
|
|
2266
|
-
}],
|
|
2267
|
-
detail: `audioStart=${start} end=${end}`
|
|
2268
|
-
};
|
|
2269
|
-
}
|
|
2270
|
-
function atomLength(bytes, view, o) {
|
|
2271
|
-
const size = view.getUint32(o, false);
|
|
2272
|
-
if (size === 0) return {
|
|
2273
|
-
length: bytes.length - o,
|
|
2274
|
-
headerSize: 8
|
|
2275
|
-
};
|
|
2276
|
-
if (size === 1) {
|
|
2277
|
-
if (o + 16 > bytes.length) return void 0;
|
|
2278
|
-
const big = view.getBigUint64(o + 8, false);
|
|
2279
|
-
if (big > BigInt(Number.MAX_SAFE_INTEGER)) return void 0;
|
|
2280
|
-
return {
|
|
2281
|
-
length: Number(big),
|
|
2282
|
-
headerSize: 16
|
|
2283
|
-
};
|
|
2284
|
-
}
|
|
2285
|
-
return {
|
|
2286
|
-
length: size,
|
|
2287
|
-
headerSize: 8
|
|
2288
|
-
};
|
|
2289
|
-
}
|
|
2290
|
-
function walkMp4(bytes) {
|
|
2291
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
2292
|
-
const ranges = [];
|
|
2293
|
-
let o = 0;
|
|
2294
|
-
while (o + 8 <= bytes.length) {
|
|
2295
|
-
const type = text(bytes, o + 4, 4);
|
|
2296
|
-
const atom = atomLength(bytes, view, o);
|
|
2297
|
-
if (atom === void 0) return fallback(`malformed ${type} size`);
|
|
2298
|
-
if (atom.length < atom.headerSize) return fallback(`malformed ${type} size`);
|
|
2299
|
-
if (o + atom.length > bytes.length) return fallback(`oversized ${type}`);
|
|
2300
|
-
if (type === "mdat" && atom.length > atom.headerSize) ranges.push({
|
|
2301
|
-
offset: o + atom.headerSize,
|
|
2302
|
-
length: atom.length - atom.headerSize
|
|
2303
|
-
});
|
|
2304
|
-
o += atom.length;
|
|
2305
|
-
}
|
|
2306
|
-
if (o !== bytes.length) return fallback("trailing bytes after the last atom");
|
|
2307
|
-
if (ranges.length === 0) return fallback("no non-empty mdat");
|
|
2308
|
-
return {
|
|
2309
|
-
kind: "ranges",
|
|
2310
|
-
ranges,
|
|
2311
|
-
detail: `${ranges.length} mdat(s)`
|
|
2312
|
-
};
|
|
2313
|
-
}
|
|
2314
|
-
function walkWav(bytes) {
|
|
2315
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
2316
|
-
if (text(bytes, 0, 4) !== "RIFF") return fallback("not RIFF");
|
|
2317
|
-
if (text(bytes, 8, 4) !== "WAVE") return fallback("not WAVE");
|
|
2318
|
-
const ranges = [];
|
|
2319
|
-
let o = 12;
|
|
2320
|
-
while (o + 8 <= bytes.length) {
|
|
2321
|
-
const id = text(bytes, o, 4);
|
|
2322
|
-
const size = view.getUint32(o + 4, true);
|
|
2323
|
-
const dataStart = o + 8;
|
|
2324
|
-
if (dataStart + size > bytes.length) return fallback(`truncated ${id}`);
|
|
2325
|
-
if (id === "data" && size > 0) ranges.push({
|
|
2326
|
-
offset: dataStart,
|
|
2327
|
-
length: size
|
|
2328
|
-
});
|
|
2329
|
-
o = dataStart + size + size % 2;
|
|
2330
|
-
}
|
|
2331
|
-
if (ranges.length === 0) return fallback("no data chunk");
|
|
2332
|
-
return {
|
|
2333
|
-
kind: "ranges",
|
|
2334
|
-
ranges,
|
|
2335
|
-
detail: `${ranges.length} data chunk(s)`
|
|
2336
|
-
};
|
|
2337
|
-
}
|
|
2338
|
-
function mediaRanges(format, bytes) {
|
|
2339
|
-
const walked = (() => {
|
|
2340
|
-
switch (format.toUpperCase()) {
|
|
2341
|
-
case "MP3":
|
|
2342
|
-
case "AAC": return walkMpeg(bytes);
|
|
2343
|
-
case "FLAC": return walkFlac(bytes);
|
|
2344
|
-
case "MP4":
|
|
2345
|
-
case "M4A": return walkMp4(bytes);
|
|
2346
|
-
case "WAV": return walkWav(bytes);
|
|
2347
|
-
default: return {
|
|
2348
|
-
kind: "fallback",
|
|
2349
|
-
ranges: [],
|
|
2350
|
-
detail: "format not covered"
|
|
2351
|
-
};
|
|
2352
|
-
}
|
|
2353
|
-
})();
|
|
2354
|
-
if (walked.kind === "fallback") return {
|
|
2355
|
-
kind: "fallback",
|
|
2356
|
-
ranges: [{
|
|
2357
|
-
offset: 0,
|
|
2358
|
-
length: bytes.length
|
|
2359
|
-
}],
|
|
2360
|
-
detail: `${walked.detail} → whole file`
|
|
2361
|
-
};
|
|
2362
|
-
return walked;
|
|
2363
|
-
}
|
|
2364
|
-
var decoder, text, fallback, frameLengthAt, MPEG_SCAN_LIMIT;
|
|
2365
|
-
var init_media_ranges = __esmMin((() => {
|
|
2366
|
-
init_metadata_extent();
|
|
2367
|
-
decoder = new TextDecoder();
|
|
2368
|
-
text = (b, o, n) => decoder.decode(b.subarray(o, o + n));
|
|
2369
|
-
fallback = (detail) => ({
|
|
2370
|
-
kind: "fallback",
|
|
2371
|
-
ranges: [],
|
|
2372
|
-
detail
|
|
2373
|
-
});
|
|
2374
|
-
frameLengthAt = (bytes, at) => mpegFrameLength(bytes, at) || adtsFrameLength(bytes, at);
|
|
2375
|
-
MPEG_SCAN_LIMIT = 65536;
|
|
2376
|
-
}));
|
|
2377
|
-
//#endregion
|
|
2378
|
-
//#region src/taglib/audio-file-checksum.ts
|
|
2379
|
-
async function fileBytes(source, io) {
|
|
2380
|
-
if (source.path) return await io.readFile(source.path);
|
|
2381
|
-
if (source.blob) return new Uint8Array(await source.blob.arrayBuffer());
|
|
2382
|
-
if (!source.partiallyLoaded && source.bytes.length > 0) return source.bytes;
|
|
2383
|
-
throw new MetadataError("read", "the handle holds no file bytes and has no readable source; a partial handle that has been saved drops its source — checksum the saved path instead");
|
|
2384
|
-
}
|
|
2385
|
-
function joinRanges(bytes, ranges) {
|
|
2386
|
-
const total = ranges.reduce((n, r) => n + r.length, 0);
|
|
2387
|
-
const overrun = ranges.find((r) => r.offset + r.length > bytes.length);
|
|
2388
|
-
if (overrun || total > bytes.length) throw new MetadataError("read", `range walk overran the buffer (${overrun ? `range ${overrun.offset}+${overrun.length}` : `${total} bytes`} past the ${bytes.length}-byte buffer)`);
|
|
2389
|
-
if (ranges.length === 1) {
|
|
2390
|
-
const only = ranges[0];
|
|
2391
|
-
const view = bytes.subarray(only.offset, only.offset + only.length);
|
|
2392
|
-
return view.buffer instanceof ArrayBuffer ? view : new Uint8Array(view);
|
|
2393
|
-
}
|
|
2394
|
-
const out = new Uint8Array(total);
|
|
2395
|
-
let at = 0;
|
|
2396
|
-
for (const r of ranges) {
|
|
2397
|
-
out.set(bytes.subarray(r.offset, r.offset + r.length), at);
|
|
2398
|
-
at += r.length;
|
|
2399
|
-
}
|
|
2400
|
-
return out;
|
|
2401
|
-
}
|
|
2402
|
-
async function mediaChecksum(source, format, io, options = {}) {
|
|
2403
|
-
if (options.basis === "pcm") {
|
|
2404
|
-
if (format.toUpperCase() !== "FLAC") throw new UnsupportedFormatError(format, ["FLAC"], { operation: "media checksum (basis: pcm)" });
|
|
2405
|
-
const windowed = source.bytes.length > 0 ? source.bytes : source.path && io.readPartial ? await io.readPartial(source.path, STREAMINFO_WINDOW, 0) : void 0;
|
|
2406
|
-
let md5 = windowed === void 0 ? void 0 : flacStreamInfoMd5(windowed);
|
|
2407
|
-
if (md5 === void 0 && windowed !== source.bytes) md5 = flacStreamInfoMd5(await fileBytes(source, io));
|
|
2408
|
-
if (md5 === void 0) throw new MetadataError("read", "STREAMINFO digest unavailable");
|
|
2409
|
-
return {
|
|
2410
|
-
source: "flac-streaminfo-md5",
|
|
2411
|
-
algorithm: "md5",
|
|
2412
|
-
hex: md5,
|
|
2413
|
-
bytesHashed: 16
|
|
2414
|
-
};
|
|
2415
|
-
}
|
|
2416
|
-
const bytes = await fileBytes(source, io);
|
|
2417
|
-
const walk = mediaRanges(format, bytes);
|
|
2418
|
-
const payload = joinRanges(bytes, walk.ranges);
|
|
2419
|
-
const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", payload));
|
|
2420
|
-
let hex = "";
|
|
2421
|
-
for (const byte of digest) hex += byte.toString(16).padStart(2, "0");
|
|
2422
|
-
return {
|
|
2423
|
-
source: walk.kind === "ranges" ? "audio-payload" : "file",
|
|
2424
|
-
algorithm: "sha256",
|
|
2425
|
-
hex,
|
|
2426
|
-
bytesHashed: payload.length
|
|
2427
|
-
};
|
|
2428
|
-
}
|
|
2429
|
-
var STREAMINFO_WINDOW;
|
|
2430
|
-
var init_audio_file_checksum = __esmMin((() => {
|
|
2431
|
-
init_media_ranges();
|
|
2432
|
-
init_errors();
|
|
2433
|
-
STREAMINFO_WINDOW = 65536;
|
|
2434
|
-
}));
|
|
2435
|
-
//#endregion
|
|
2436
|
-
//#region src/utils/file.ts
|
|
2437
|
-
async function readFileData(file) {
|
|
2438
|
-
if (file instanceof Uint8Array) return file;
|
|
2439
|
-
if (file instanceof ArrayBuffer) return new Uint8Array(file);
|
|
2440
|
-
if (typeof File !== "undefined" && file instanceof File) return new Uint8Array(await file.arrayBuffer());
|
|
2441
|
-
if (typeof file === "string") try {
|
|
2442
|
-
return await getPlatformIO().readFile(file);
|
|
2443
|
-
} catch (error) {
|
|
2444
|
-
if (error instanceof EnvironmentError) throw error;
|
|
2445
|
-
throw new FileOperationError("read", error.message, file);
|
|
2446
|
-
}
|
|
2447
|
-
const inputType = Object.prototype.toString.call(file);
|
|
2448
|
-
throw new FileOperationError("read", `Invalid file input type: ${inputType}. Expected string path, Uint8Array, ArrayBuffer, or File object.`);
|
|
2449
|
-
}
|
|
2450
|
-
async function getFileSize(path) {
|
|
2451
|
-
try {
|
|
2452
|
-
return (await getPlatformIO().stat(path)).size;
|
|
2453
|
-
} catch (error) {
|
|
2454
|
-
if (error instanceof EnvironmentError) throw error;
|
|
2455
|
-
throw new FileOperationError("stat", error.message, path);
|
|
2456
|
-
}
|
|
2457
|
-
}
|
|
2458
|
-
async function readPartialFileData(path, headerSize, footerSize) {
|
|
2459
|
-
const io = getPlatformIO();
|
|
2460
|
-
if (!io.readPartial) throw new EnvironmentError("current runtime", "does not support partial file reading", "filesystem access with seek support");
|
|
2461
|
-
try {
|
|
2462
|
-
return await io.readPartial(path, headerSize, footerSize);
|
|
2463
|
-
} catch (error) {
|
|
2464
|
-
if (error instanceof EnvironmentError) throw error;
|
|
2465
|
-
throw new FileOperationError("read", error.message, path);
|
|
2466
|
-
}
|
|
2467
|
-
}
|
|
2468
|
-
var init_file = __esmMin((() => {
|
|
2469
|
-
init_errors();
|
|
2470
|
-
init__taglib_platform_io_stub();
|
|
2471
|
-
}));
|
|
2472
|
-
//#endregion
|
|
2473
|
-
//#region src/taglib/embind-adapter.ts
|
|
2474
|
-
function isValidBitrateMode(value) {
|
|
2475
|
-
return value === "CBR" || value === "VBR" || value === "ABR";
|
|
2476
|
-
}
|
|
2477
|
-
function wrapEmbindHandle(raw) {
|
|
2478
|
-
const stagedId3v2Frames = {};
|
|
2479
|
-
let destroyed = false;
|
|
2480
|
-
const overrides = {
|
|
2481
|
-
getTagData() {
|
|
2482
|
-
const tw = raw.getTag();
|
|
2483
|
-
return {
|
|
2484
|
-
title: tw.title(),
|
|
2485
|
-
artist: tw.artist(),
|
|
2486
|
-
album: tw.album(),
|
|
2487
|
-
comment: tw.comment(),
|
|
2488
|
-
genre: tw.genre(),
|
|
2489
|
-
year: tw.year(),
|
|
2490
|
-
track: tw.track()
|
|
2491
|
-
};
|
|
2492
|
-
},
|
|
2493
|
-
setTagData(data) {
|
|
2494
|
-
const tw = raw.getTag();
|
|
2495
|
-
if (data.title !== void 0) tw.setTitle(data.title);
|
|
2496
|
-
if (data.artist !== void 0) tw.setArtist(data.artist);
|
|
2497
|
-
if (data.album !== void 0) tw.setAlbum(data.album);
|
|
2498
|
-
if (data.comment !== void 0) tw.setComment(data.comment);
|
|
2499
|
-
if (data.genre !== void 0) tw.setGenre(data.genre);
|
|
2500
|
-
if (data.year !== void 0) tw.setYear(data.year);
|
|
2501
|
-
if (data.track !== void 0) tw.setTrack(data.track);
|
|
2502
|
-
},
|
|
2503
|
-
getBextData() {
|
|
2504
|
-
const v = raw.getBextData();
|
|
2505
|
-
if (v === void 0 || v === null) return void 0;
|
|
2506
|
-
const u8 = v instanceof Uint8Array ? v : new Uint8Array(v);
|
|
2507
|
-
return u8.length > 0 ? u8 : void 0;
|
|
2508
|
-
},
|
|
2509
|
-
setBextData(data) {
|
|
2510
|
-
raw.setBextData(data ?? null);
|
|
2511
|
-
},
|
|
2512
|
-
getIxml() {
|
|
2513
|
-
const v = raw.getIxml();
|
|
2514
|
-
return typeof v === "string" && v.length > 0 ? v : void 0;
|
|
2515
|
-
},
|
|
2516
|
-
setIxml(data) {
|
|
2517
|
-
raw.setIxml(data ?? null);
|
|
2518
|
-
},
|
|
2519
|
-
getLyrics() {
|
|
2520
|
-
return (raw.getProperties()["LYRICS"] ?? []).map((text) => ({
|
|
2521
|
-
text,
|
|
2522
|
-
description: "",
|
|
2523
|
-
language: ""
|
|
2524
|
-
}));
|
|
2525
|
-
},
|
|
2526
|
-
setLyrics(lyrics) {
|
|
2527
|
-
const handle = raw;
|
|
2528
|
-
const props = handle.getProperties();
|
|
2529
|
-
if (lyrics.length > 0) props["LYRICS"] = lyrics.map((l) => l.text);
|
|
2530
|
-
else delete props["LYRICS"];
|
|
2531
|
-
handle.setProperties(props);
|
|
2532
|
-
},
|
|
2533
|
-
setId3v2Frames(id, data) {
|
|
2534
|
-
stagedId3v2Frames[id] = data.map((d) => new Uint8Array(d));
|
|
2535
|
-
raw.setId3v2Frames(id, data);
|
|
2536
|
-
},
|
|
2537
|
-
removeId3v2Frames(id) {
|
|
2538
|
-
stagedId3v2Frames[id] = [];
|
|
2539
|
-
raw.removeId3v2Frames(id);
|
|
2540
|
-
},
|
|
2541
|
-
getStagedId3v2Frames() {
|
|
2542
|
-
return Object.keys(stagedId3v2Frames).length > 0 ? { ...stagedId3v2Frames } : void 0;
|
|
2543
|
-
},
|
|
2544
|
-
hasId3Tags() {
|
|
2545
|
-
const v = raw.hasId3Tags();
|
|
2546
|
-
if (!v || typeof v !== "object") return {
|
|
2547
|
-
v1: false,
|
|
2548
|
-
v2: false
|
|
2549
|
-
};
|
|
2550
|
-
const o = v;
|
|
2551
|
-
return {
|
|
2552
|
-
v1: o.v1 === true,
|
|
2553
|
-
v2: o.v2 === true
|
|
2554
|
-
};
|
|
2555
|
-
},
|
|
2556
|
-
stripId3Tags(opts) {
|
|
2557
|
-
raw.stripId3Tags(opts);
|
|
2558
|
-
},
|
|
2559
|
-
destroy() {
|
|
2560
|
-
if (destroyed) return;
|
|
2561
|
-
destroyed = true;
|
|
2562
|
-
raw.destroy();
|
|
2563
|
-
},
|
|
2564
|
-
get destroyed() {
|
|
2565
|
-
return destroyed;
|
|
2566
|
-
},
|
|
2567
|
-
setMp4ItemRemovals(removals) {
|
|
2568
|
-
const handle = raw;
|
|
2569
|
-
for (const name of removals) handle.removeMP4Item(name);
|
|
2570
|
-
},
|
|
2571
|
-
getAudioProperties() {
|
|
2572
|
-
const pw = raw.getAudioProperties();
|
|
2573
|
-
if (!pw) return null;
|
|
2574
|
-
const containerFormat = pw.containerFormat() || "unknown";
|
|
2575
|
-
const codec = pw.codec() || "unknown";
|
|
2576
|
-
const mpegVersion = pw.mpegVersion();
|
|
2577
|
-
const formatVersion = pw.formatVersion();
|
|
2578
|
-
const bitrateMode = pw.bitrateMode();
|
|
2579
|
-
const isEncrypted = pw.isEncrypted();
|
|
2580
|
-
return {
|
|
2581
|
-
duration: pw.lengthInSeconds(),
|
|
2582
|
-
durationMs: pw.lengthInMilliseconds(),
|
|
2583
|
-
bitrate: pw.bitrate(),
|
|
2584
|
-
sampleRate: pw.sampleRate(),
|
|
2585
|
-
channels: pw.channels(),
|
|
2586
|
-
bitsPerSample: pw.bitsPerSample(),
|
|
2587
|
-
codec,
|
|
2588
|
-
containerFormat,
|
|
2589
|
-
isLossless: pw.isLossless(),
|
|
2590
|
-
...mpegVersion > 0 ? {
|
|
2591
|
-
mpegVersion,
|
|
2592
|
-
mpegLayer: pw.mpegLayer()
|
|
2593
|
-
} : {},
|
|
2594
|
-
...isEncrypted || containerFormat === "MP4" || containerFormat === "ASF" ? { isEncrypted } : {},
|
|
2595
|
-
...formatVersion > 0 ? { formatVersion } : {},
|
|
2596
|
-
...isValidBitrateMode(bitrateMode) ? { bitrateMode } : {},
|
|
2597
|
-
...containerFormat === "OGG" && codec === "Opus" ? { outputGainDb: pw.outputGainDb() } : {}
|
|
2598
|
-
};
|
|
2599
|
-
}
|
|
2600
|
-
};
|
|
2601
|
-
return new Proxy(raw, { get(target, prop, receiver) {
|
|
2602
|
-
if (prop in overrides) return overrides[prop];
|
|
2603
|
-
const value = Reflect.get(target, prop, receiver);
|
|
2604
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
2605
|
-
} });
|
|
2606
|
-
}
|
|
2607
|
-
var init_embind_adapter = __esmMin((() => {}));
|
|
2608
|
-
//#endregion
|
|
2609
|
-
//#region src/taglib/extra-state-registry.ts
|
|
2610
|
-
function chapterStyle(chapters) {
|
|
2611
|
-
const s = chapters[0]?.source;
|
|
2612
|
-
return s === "nero" || s === "both" ? s : "quicktime";
|
|
2613
|
-
}
|
|
2614
|
-
function copyExtraState(target, source, sourceComplete) {
|
|
2615
|
-
for (const field of EXTRA_FIELDS) field.copy(target, source, sourceComplete);
|
|
2616
|
-
}
|
|
2617
|
-
var EXTRA_FIELDS;
|
|
2618
|
-
var init_extra_state_registry = __esmMin((() => {
|
|
2619
|
-
EXTRA_FIELDS = [
|
|
2620
|
-
{
|
|
2621
|
-
name: "pictures",
|
|
2622
|
-
copy(target, source, complete) {
|
|
2623
|
-
const v = source.getPictures();
|
|
2624
|
-
if (complete || v.length > 0) target.setPictures(v);
|
|
2625
|
-
}
|
|
2626
|
-
},
|
|
2627
|
-
{
|
|
2628
|
-
name: "ratings",
|
|
2629
|
-
copy(target, source, complete) {
|
|
2630
|
-
const v = source.getRatings();
|
|
2631
|
-
if (complete || v.length > 0) target.setRatings(v);
|
|
2632
|
-
}
|
|
2633
|
-
},
|
|
2634
|
-
{
|
|
2635
|
-
name: "lyrics",
|
|
2636
|
-
copy(target, source, complete) {
|
|
2637
|
-
const v = source.getLyrics();
|
|
2638
|
-
if (complete || v.length > 0) target.setLyrics(v);
|
|
2639
|
-
}
|
|
2640
|
-
},
|
|
2641
|
-
{
|
|
2642
|
-
name: "chapters",
|
|
2643
|
-
copy(target, source, complete) {
|
|
2644
|
-
const v = source.getChapters();
|
|
2645
|
-
if (complete || v.length > 0) target.setChapters(v, chapterStyle(v));
|
|
2646
|
-
}
|
|
2647
|
-
},
|
|
2648
|
-
{
|
|
2649
|
-
name: "bextData",
|
|
2650
|
-
copy(target, source, complete) {
|
|
2651
|
-
const v = source.getBextData();
|
|
2652
|
-
if (v !== void 0) target.setBextData(v);
|
|
2653
|
-
else if (complete) target.setBextData(null);
|
|
2654
|
-
}
|
|
2655
|
-
},
|
|
2656
|
-
{
|
|
2657
|
-
name: "ixml",
|
|
2658
|
-
copy(target, source, complete) {
|
|
2659
|
-
const v = source.getIxml();
|
|
2660
|
-
if (v !== void 0) target.setIxml(v);
|
|
2661
|
-
else if (complete) target.setIxml(null);
|
|
2662
|
-
}
|
|
2663
|
-
},
|
|
2664
|
-
{
|
|
2665
|
-
name: "_mp4ItemRemovals",
|
|
2666
|
-
copy(target, source, complete) {
|
|
2667
|
-
const v = source.getMp4ItemRemovals?.();
|
|
2668
|
-
if (complete || v !== void 0 && v.length > 0) target.setMp4ItemRemovals?.(v ?? []);
|
|
2669
|
-
}
|
|
2670
|
-
},
|
|
2671
|
-
{
|
|
2672
|
-
name: "id3v2Frames",
|
|
2673
|
-
copy(target, source) {
|
|
2674
|
-
const staged = source.getStagedId3v2Frames?.();
|
|
2675
|
-
if (!staged) return;
|
|
2676
|
-
for (const [id, bodies] of Object.entries(staged)) target.setId3v2Frames(id, bodies);
|
|
2677
|
-
}
|
|
2678
|
-
}
|
|
2679
|
-
];
|
|
2680
|
-
}));
|
|
2681
|
-
//#endregion
|
|
2682
|
-
//#region src/taglib/save-reconstruct.ts
|
|
2683
|
-
function copyEditedState(target, source, sourceComplete, deletedKeys) {
|
|
2684
|
-
target.setTagData(source.getTagData());
|
|
2685
|
-
const merged = sourceComplete ? source.getProperties() : {
|
|
2686
|
-
...target.getProperties(),
|
|
2687
|
-
...source.getProperties()
|
|
2688
|
-
};
|
|
2689
|
-
for (const key of deletedKeys) delete merged[key];
|
|
2690
|
-
const atomNames = mp4FreeformAtomNames(Object.keys(merged));
|
|
2691
|
-
if (atomNames.length > 0) merged[MP4_ITEM_NAMES_KEY] = atomNames;
|
|
2692
|
-
target.setProperties(merged);
|
|
2693
|
-
copyExtraState(target, source, sourceComplete);
|
|
2694
|
-
}
|
|
2695
|
-
async function saveViaFreshHandle(module, editing, source, targetPath, sourceComplete, deletedKeys = /* @__PURE__ */ new Set()) {
|
|
2696
|
-
const rawFullHandle = module.createFileHandle();
|
|
2697
|
-
const fullFileHandle = module.isWasi ? rawFullHandle : wrapEmbindHandle(rawFullHandle);
|
|
2698
|
-
try {
|
|
2699
|
-
{
|
|
2700
|
-
const data = await readFileData(source);
|
|
2701
|
-
if (!fullFileHandle.loadFromBuffer(data)) throw new InvalidFormatError("Failed to load full audio file for saving");
|
|
2702
|
-
}
|
|
2703
|
-
copyEditedState(fullFileHandle, editing, sourceComplete, deletedKeys);
|
|
2704
|
-
if (!fullFileHandle.save()) throw new FileOperationError("save", "Failed to save changes to full file");
|
|
2705
|
-
await writeFileData(targetPath, fullFileHandle.getBuffer());
|
|
2706
|
-
} finally {
|
|
2707
|
-
fullFileHandle.destroy();
|
|
2708
|
-
}
|
|
2709
|
-
}
|
|
2710
|
-
var init_save_reconstruct = __esmMin((() => {
|
|
2711
|
-
init_errors();
|
|
2712
|
-
init_file();
|
|
2713
|
-
init_write();
|
|
2714
|
-
init_embind_adapter();
|
|
2715
|
-
init_extra_state_registry();
|
|
2716
|
-
init_properties();
|
|
2717
|
-
init_mp4_item_names();
|
|
2718
|
-
}));
|
|
2719
|
-
//#endregion
|
|
2720
|
-
//#region src/taglib/audio-file-impl.ts
|
|
2721
|
-
function sortChapters(list) {
|
|
2722
|
-
return [...list].sort((a, b) => a.startTimeMs - b.startTimeMs);
|
|
2723
|
-
}
|
|
2724
|
-
function inferEndTimeMs(sorted, index, trackEndMs) {
|
|
2725
|
-
const own = sorted[index].endTimeMs;
|
|
2726
|
-
if (own !== void 0) return own;
|
|
2727
|
-
const next = sorted[index + 1];
|
|
2728
|
-
return next ? next.startTimeMs : trackEndMs;
|
|
2729
|
-
}
|
|
2730
|
-
function readFileSync(path) {
|
|
2731
|
-
if (isDeno()) return Deno.readFileSync(path);
|
|
2732
|
-
const fs = getNodeFsSync();
|
|
2733
|
-
if (fs) return new Uint8Array(fs.readFileSync(path));
|
|
2734
|
-
throw new FileOperationError("read", "node:fs is unavailable in this runtime: cannot read file data from disk", path);
|
|
2735
|
-
}
|
|
2736
|
-
var AudioFileImpl;
|
|
2737
|
-
var init_audio_file_impl = __esmMin((() => {
|
|
2738
|
-
init_types();
|
|
2739
|
-
init_audio_file_bwf();
|
|
2740
|
-
init_id3v2_frames();
|
|
2741
|
-
init_errors();
|
|
2742
|
-
init_write();
|
|
2743
|
-
init__taglib_node_fs_stub();
|
|
2744
|
-
init_rating();
|
|
2745
|
-
init_detector();
|
|
2746
|
-
init_audio_file_base();
|
|
2747
|
-
init_audio_file_checksum();
|
|
2748
|
-
init__taglib_platform_io_stub();
|
|
2749
|
-
init_save_reconstruct();
|
|
2750
|
-
init_defineProperty();
|
|
2751
|
-
AudioFileImpl = class extends BaseAudioFileImpl {
|
|
2752
|
-
constructor(module, fileHandle, sourcePath, originalSource, isPartiallyLoaded = false, partialLoadOptions) {
|
|
2753
|
-
super(module, fileHandle, sourcePath, originalSource, isPartiallyLoaded, partialLoadOptions);
|
|
2754
|
-
_defineProperty(this, "pathModeBuffer", null);
|
|
2755
|
-
_defineProperty(this, "partiallyLoadedAtConstruction", void 0);
|
|
2756
|
-
this.partiallyLoadedAtConstruction = isPartiallyLoaded;
|
|
2757
|
-
}
|
|
2758
|
-
save() {
|
|
2759
|
-
if (this.isPartiallyLoaded && this.originalSource) throw new FileOperationError("save", "Cannot save partially loaded file directly. Use saveToFile() instead");
|
|
2760
|
-
this.cachedAudioProperties = null;
|
|
2761
|
-
this.pathModeBuffer = null;
|
|
2762
|
-
return this.handle.save();
|
|
2763
|
-
}
|
|
2764
|
-
getFileBuffer() {
|
|
2765
|
-
const buffer = this.handle.getBuffer();
|
|
2766
|
-
if (buffer.length > 0) return buffer;
|
|
2767
|
-
if (this.pathModeBuffer) return this.pathModeBuffer;
|
|
2768
|
-
if (this.sourcePath) try {
|
|
2769
|
-
this.pathModeBuffer = readFileSync(this.sourcePath);
|
|
2770
|
-
return this.pathModeBuffer;
|
|
2771
|
-
} catch (error) {
|
|
2772
|
-
if (error instanceof FileOperationError) throw error;
|
|
2773
|
-
throw new FileOperationError("read", `Cannot return file data: ${errorMessage(error)}`, this.sourcePath, { cause: error });
|
|
2774
|
-
}
|
|
2775
|
-
throw new FileOperationError("read", "No file data available: in-memory buffer is empty and no source path is set");
|
|
2776
|
-
}
|
|
2777
|
-
mediaChecksum(options) {
|
|
2778
|
-
return mediaChecksum({
|
|
2779
|
-
bytes: this.handle.getBuffer(),
|
|
2780
|
-
...this.sourcePath !== void 0 ? { path: this.sourcePath } : {},
|
|
2781
|
-
...this.originalSource instanceof Blob ? { blob: this.originalSource } : {},
|
|
2782
|
-
partiallyLoaded: this.partiallyLoadedAtConstruction
|
|
2783
|
-
}, this.getFormat(), getPlatformIO(), options);
|
|
2784
|
-
}
|
|
2785
|
-
async saveToFile(path) {
|
|
2786
|
-
const targetPath = path ?? this.sourcePath;
|
|
2787
|
-
if (!targetPath) throw new FileOperationError("save", "No file path available. Provide a path or open the file from a path");
|
|
2788
|
-
if (this.isPartiallyLoaded && this.originalSource) {
|
|
2789
|
-
await saveViaFreshHandle(this.module, this.handle, this.originalSource, targetPath, false, this.partialDeletedPropertyKeys());
|
|
2790
|
-
this.isPartiallyLoaded = false;
|
|
2791
|
-
this.originalSource = void 0;
|
|
2792
|
-
} else if (this.module.isWasi && this.sourcePath && targetPath !== this.sourcePath) await saveViaFreshHandle(this.module, this.handle, this.sourcePath, targetPath, true);
|
|
2793
|
-
else {
|
|
2794
|
-
if (!this.save()) throw new FileOperationError("save", "Failed to save changes to in-memory buffer");
|
|
2795
|
-
const buffer = this.handle.getBuffer();
|
|
2796
|
-
if (buffer.length > 0) await writeFileData(targetPath, buffer);
|
|
2797
|
-
}
|
|
2798
|
-
this.pathModeBuffer = null;
|
|
2799
|
-
}
|
|
2800
|
-
getPictures() {
|
|
2801
|
-
return this.handle.getPictures().map((pic) => ({
|
|
2802
|
-
mimeType: pic.mimeType,
|
|
2803
|
-
data: pic.data,
|
|
2804
|
-
type: PICTURE_TYPE_NAMES[pic.type] ?? "Other",
|
|
2805
|
-
...pic.description !== void 0 ? { description: pic.description } : {}
|
|
2806
|
-
}));
|
|
2807
|
-
}
|
|
2808
|
-
setPictures(pictures) {
|
|
2809
|
-
this.handle.setPictures(pictures.map((pic) => ({
|
|
2810
|
-
mimeType: pic.mimeType,
|
|
2811
|
-
data: pic.data,
|
|
2812
|
-
type: PICTURE_TYPE_VALUES[pic.type] ?? 0,
|
|
2813
|
-
description: pic.description ?? ""
|
|
2814
|
-
})));
|
|
2815
|
-
}
|
|
2816
|
-
addPicture(picture) {
|
|
2817
|
-
this.handle.addPicture({
|
|
2818
|
-
mimeType: picture.mimeType,
|
|
2819
|
-
data: picture.data,
|
|
2820
|
-
type: PICTURE_TYPE_VALUES[picture.type] ?? 0,
|
|
2821
|
-
description: picture.description ?? ""
|
|
2822
|
-
});
|
|
2823
|
-
}
|
|
2824
|
-
removePictures() {
|
|
2825
|
-
this.handle.removePictures();
|
|
2826
|
-
}
|
|
2827
|
-
getChapters() {
|
|
2828
|
-
const sorted = sortChapters(this.handle.getChapters());
|
|
2829
|
-
const trackEndMs = this.audioProperties()?.durationMs;
|
|
2830
|
-
return sorted.map((c, i) => {
|
|
2831
|
-
const endTimeMs = inferEndTimeMs(sorted, i, trackEndMs);
|
|
2832
|
-
return {
|
|
2833
|
-
startTimeMs: c.startTimeMs,
|
|
2834
|
-
...endTimeMs !== void 0 ? { endTimeMs } : {},
|
|
2835
|
-
...c.title ? { title: c.title } : {},
|
|
2836
|
-
...c.id ? { id: c.id } : {},
|
|
2837
|
-
...c.source !== void 0 ? { source: c.source } : {}
|
|
2838
|
-
};
|
|
2839
|
-
});
|
|
2840
|
-
}
|
|
2841
|
-
setChapters(chapters, options) {
|
|
2842
|
-
const fmt = this.getFormat();
|
|
2843
|
-
if (fmt !== "MP3" && fmt !== "AAC" && fmt !== "MP4") throw new UnsupportedFormatError(fmt, [
|
|
2844
|
-
"MP3",
|
|
2845
|
-
"AAC",
|
|
2846
|
-
"MP4"
|
|
2847
|
-
], { operation: "setChapters" });
|
|
2848
|
-
const sorted = sortChapters(chapters);
|
|
2849
|
-
const trackEndMs = this.audioProperties()?.durationMs;
|
|
2850
|
-
const style = options?.mp4ChapterStyle ?? "quicktime";
|
|
2851
|
-
const source = fmt === "MP4" ? style : "id3";
|
|
2852
|
-
const raw = sorted.map((c, i) => ({
|
|
2853
|
-
...c.id !== void 0 ? { id: c.id } : {},
|
|
2854
|
-
startTimeMs: c.startTimeMs,
|
|
2855
|
-
endTimeMs: inferEndTimeMs(sorted, i, trackEndMs) ?? c.startTimeMs,
|
|
2856
|
-
...c.title !== void 0 ? { title: c.title } : {},
|
|
2857
|
-
source
|
|
2858
|
-
}));
|
|
2859
|
-
this.handle.setChapters(raw, style);
|
|
2860
|
-
}
|
|
2861
|
-
getBext() {
|
|
2862
|
-
return getBext(this.handle);
|
|
2863
|
-
}
|
|
2864
|
-
setBext(bext) {
|
|
2865
|
-
setBext(this.handle, this.getFormat(), bext);
|
|
2866
|
-
}
|
|
2867
|
-
getBextData() {
|
|
2868
|
-
return getBextData(this.handle);
|
|
2869
|
-
}
|
|
2870
|
-
setBextData(data) {
|
|
2871
|
-
setBextData(this.handle, this.getFormat(), data);
|
|
2872
|
-
}
|
|
2873
|
-
getIxml() {
|
|
2874
|
-
return getIxml(this.handle);
|
|
2875
|
-
}
|
|
2876
|
-
setIxml(data) {
|
|
2877
|
-
setIxml(this.handle, this.getFormat(), data);
|
|
2878
|
-
}
|
|
2879
|
-
getRatings() {
|
|
2880
|
-
return this.handle.getRatings().map((r) => ({
|
|
2881
|
-
rating: r.rating,
|
|
2882
|
-
...r.email !== void 0 && r.email !== "" ? { email: r.email } : {},
|
|
2883
|
-
...r.counter !== 0 ? { counter: r.counter } : {}
|
|
2884
|
-
}));
|
|
2885
|
-
}
|
|
2886
|
-
setRatings(ratings) {
|
|
2887
|
-
this.handle.setRatings(ratings.map((r) => ({
|
|
2888
|
-
rating: r.rating,
|
|
2889
|
-
email: r.email ?? "",
|
|
2890
|
-
counter: r.counter ?? 0
|
|
2891
|
-
})));
|
|
2892
|
-
}
|
|
2893
|
-
getLyrics() {
|
|
2894
|
-
return this.handle.getLyrics().map((l) => {
|
|
2895
|
-
const out = { text: l.text };
|
|
2896
|
-
if (l.description) out.description = l.description;
|
|
2897
|
-
if (l.language) out.language = l.language;
|
|
2898
|
-
return out;
|
|
2899
|
-
});
|
|
2900
|
-
}
|
|
2901
|
-
setLyrics(lyrics) {
|
|
2902
|
-
this.handle.setLyrics(lyrics.map((l) => ({
|
|
2903
|
-
text: l.text,
|
|
2904
|
-
description: l.description ?? "",
|
|
2905
|
-
language: l.language ?? ""
|
|
2906
|
-
})));
|
|
2907
|
-
}
|
|
2908
|
-
getRating() {
|
|
2909
|
-
const ratings = this.getRatings();
|
|
2910
|
-
return ratings.length > 0 ? normalized(ratings[0].rating) : void 0;
|
|
2911
|
-
}
|
|
2912
|
-
setRating(rating, email) {
|
|
2913
|
-
this.setRatings([{
|
|
2914
|
-
rating,
|
|
2915
|
-
...email !== void 0 ? { email } : {},
|
|
2916
|
-
counter: 0
|
|
2917
|
-
}]);
|
|
2918
|
-
}
|
|
2919
|
-
getId3v2Frames(id) {
|
|
2920
|
-
assertMp3(this.getFormat());
|
|
2921
|
-
if (id !== void 0) assertFrameId(id, "read");
|
|
2922
|
-
return this.handle.getId3v2Frames(id ?? "").map(toPublicFrame);
|
|
2923
|
-
}
|
|
2924
|
-
setId3v2Frames(id, data) {
|
|
2925
|
-
assertMp3(this.getFormat());
|
|
2926
|
-
assertFrameId(id, "write");
|
|
2927
|
-
assertFrameBodies(id, data);
|
|
2928
|
-
this.handle.setId3v2Frames(id, data);
|
|
2929
|
-
}
|
|
2930
|
-
removeId3v2Frames(id) {
|
|
2931
|
-
assertMp3(this.getFormat());
|
|
2932
|
-
assertFrameId(id, "write");
|
|
2933
|
-
this.handle.removeId3v2Frames(id);
|
|
2934
|
-
}
|
|
2935
|
-
hasId3Tags() {
|
|
2936
|
-
return this.handle.hasId3Tags();
|
|
2937
|
-
}
|
|
2938
|
-
stripId3Tags(opts) {
|
|
2939
|
-
this.handle.stripId3Tags({
|
|
2940
|
-
v1: opts?.v1 ?? true,
|
|
2941
|
-
v2: opts?.v2 ?? true
|
|
2942
|
-
});
|
|
2943
|
-
}
|
|
2944
|
-
};
|
|
2945
|
-
}));
|
|
2946
|
-
//#endregion
|
|
2947
|
-
//#region src/taglib/load-audio-data.ts
|
|
2948
|
-
async function loadAudioData(input, opts) {
|
|
2949
|
-
if (opts.partial && typeof File !== "undefined" && input instanceof File) {
|
|
2950
|
-
const headerSize = Math.min(opts.maxHeaderSize, input.size);
|
|
2951
|
-
const footerSize = Math.min(opts.maxFooterSize, input.size);
|
|
2952
|
-
if (input.size <= headerSize + footerSize) return {
|
|
2953
|
-
data: await readFileData(input),
|
|
2954
|
-
isPartiallyLoaded: false
|
|
2955
|
-
};
|
|
2956
|
-
const header = new Uint8Array(await input.slice(0, headerSize).arrayBuffer());
|
|
2957
|
-
if (!metadataFitsInHeader(header, headerSize)) return {
|
|
2958
|
-
data: await readFileData(input),
|
|
2959
|
-
isPartiallyLoaded: false
|
|
2960
|
-
};
|
|
2961
|
-
const footerStart = Math.max(0, input.size - footerSize);
|
|
2962
|
-
const footer = new Uint8Array(await input.slice(footerStart).arrayBuffer());
|
|
2963
|
-
if (!trailerFitsInFooter(footer, footerSize)) return {
|
|
2964
|
-
data: await readFileData(input),
|
|
2965
|
-
isPartiallyLoaded: false
|
|
2966
|
-
};
|
|
2967
|
-
const combined = new Uint8Array(header.byteLength + footer.byteLength);
|
|
2968
|
-
combined.set(header, 0);
|
|
2969
|
-
combined.set(footer, header.byteLength);
|
|
2970
|
-
return {
|
|
2971
|
-
data: combined,
|
|
2972
|
-
isPartiallyLoaded: true
|
|
2973
|
-
};
|
|
2974
|
-
}
|
|
2975
|
-
if (opts.partial && typeof input === "string") {
|
|
2976
|
-
if (await getFileSize(input) > opts.maxHeaderSize + opts.maxFooterSize) {
|
|
2977
|
-
const data = await readPartialFileData(input, opts.maxHeaderSize, opts.maxFooterSize);
|
|
2978
|
-
if (metadataFitsInHeader(data, opts.maxHeaderSize) && trailerFitsInFooter(data, opts.maxFooterSize)) return {
|
|
2979
|
-
data,
|
|
2980
|
-
isPartiallyLoaded: true
|
|
2981
|
-
};
|
|
2982
|
-
}
|
|
2983
|
-
return {
|
|
2984
|
-
data: await readFileData(input),
|
|
2985
|
-
isPartiallyLoaded: false
|
|
2986
|
-
};
|
|
2987
|
-
}
|
|
2988
|
-
return {
|
|
2989
|
-
data: await readFileData(input),
|
|
2990
|
-
isPartiallyLoaded: false
|
|
2991
|
-
};
|
|
2992
|
-
}
|
|
2993
|
-
var init_load_audio_data = __esmMin((() => {
|
|
2994
|
-
init_file();
|
|
2995
|
-
init_metadata_extent();
|
|
2996
|
-
}));
|
|
2997
|
-
//#endregion
|
|
2998
|
-
//#region src/utils/tag-mapping.ts
|
|
2999
|
-
function mergeTagUpdatesInto(currentProps, tags) {
|
|
3000
|
-
const newProps = normalizeTagInput(tags);
|
|
3001
|
-
reconcilePairFields(currentProps, newProps, tags);
|
|
3002
|
-
if (newProps.date !== void 0 || newProps.year !== void 0) currentProps.YEAR = [];
|
|
3003
|
-
return {
|
|
3004
|
-
...currentProps,
|
|
3005
|
-
...newProps
|
|
3006
|
-
};
|
|
3007
|
-
}
|
|
3008
|
-
function mergeTagUpdates(file, tags) {
|
|
3009
|
-
file.setProperties(mergeTagUpdatesInto(file.properties(), tags));
|
|
3010
|
-
}
|
|
3011
|
-
function reconcilePairFields(currentProps, newProps, input) {
|
|
3012
|
-
for (const [rawKey, totalKey, numericKey] of [[
|
|
3013
|
-
"trackNumber",
|
|
3014
|
-
"totalTracks",
|
|
3015
|
-
"track"
|
|
3016
|
-
], [
|
|
3017
|
-
"discNumber",
|
|
3018
|
-
"totalDiscs",
|
|
3019
|
-
"discNumber"
|
|
3020
|
-
]]) {
|
|
3021
|
-
const incoming = newProps[rawKey]?.[0];
|
|
3022
|
-
if (incoming?.includes("/")) {
|
|
3023
|
-
newProps[totalKey] = [];
|
|
3024
|
-
continue;
|
|
3025
|
-
}
|
|
3026
|
-
if (!(input[numericKey] !== void 0 && input[rawKey] === void 0) || incoming === void 0) continue;
|
|
3027
|
-
const existing = currentProps[rawKey]?.[0];
|
|
3028
|
-
const slash = existing?.indexOf("/") ?? -1;
|
|
3029
|
-
if (existing !== void 0 && slash !== -1) newProps[rawKey] = [`${incoming}${existing.slice(slash)}`];
|
|
3030
|
-
}
|
|
3031
|
-
}
|
|
3032
|
-
function normalizeTagInput(input) {
|
|
3033
|
-
const props = {};
|
|
3034
|
-
for (const field of [
|
|
3035
|
-
"title",
|
|
3036
|
-
"artist",
|
|
3037
|
-
"album",
|
|
3038
|
-
"comment",
|
|
3039
|
-
"genre"
|
|
3040
|
-
]) {
|
|
3041
|
-
const val = input[field];
|
|
3042
|
-
if (val === void 0) continue;
|
|
3043
|
-
props[field] = Array.isArray(val) ? val : [val];
|
|
3044
|
-
}
|
|
3045
|
-
if (input.year !== void 0) props.date = [String(input.year)];
|
|
3046
|
-
if (input.date !== void 0) props.date = Array.isArray(input.date) ? input.date : [input.date];
|
|
3047
|
-
if (input.track !== void 0) props.trackNumber = [String(input.track)];
|
|
3048
|
-
if (input.trackNumber !== void 0) props.trackNumber = Array.isArray(input.trackNumber) ? input.trackNumber : [input.trackNumber];
|
|
3049
|
-
for (const [field, val] of Object.entries(input)) {
|
|
3050
|
-
if (BASIC_FIELDS.has(field) || val === void 0) continue;
|
|
3051
|
-
if (field === "extraProperties") continue;
|
|
3052
|
-
if (field === "compilation") props[field] = [val ? "1" : "0"];
|
|
3053
|
-
else if (field === "advisory") {
|
|
3054
|
-
if (val === "explicit") props.itunesAdvisory = ["1"];
|
|
3055
|
-
else if (val === "clean") props.itunesAdvisory = ["2"];
|
|
3056
|
-
else if (val === "unspecified") props.itunesAdvisory = [];
|
|
3057
|
-
} else if (field === "bpm") props[field] = [String(Math.trunc(val))];
|
|
3058
|
-
else if (NUMERIC_FIELDS.has(field)) props[field] = [String(val)];
|
|
3059
|
-
else if (field === "r128TrackGain" || field === "r128AlbumGain") props[field] = Array.isArray(val) ? val : [String(Math.round(val * 256))];
|
|
3060
|
-
else if (typeof val === "string") props[field] = [val];
|
|
3061
|
-
else if (Array.isArray(val)) props[field] = val;
|
|
3062
|
-
}
|
|
3063
|
-
for (const [rawField, totalField] of [["trackNumber", "totalTracks"], ["discNumber", "totalDiscs"]]) if (props[rawField]?.[0]?.includes("/")) delete props[totalField];
|
|
3064
|
-
return props;
|
|
3065
|
-
}
|
|
3066
|
-
var BASIC_FIELDS, NUMERIC_FIELDS;
|
|
3067
|
-
var init_tag_mapping = __esmMin((() => {
|
|
3068
|
-
BASIC_FIELDS = /* @__PURE__ */ new Set([
|
|
3069
|
-
"title",
|
|
3070
|
-
"artist",
|
|
3071
|
-
"album",
|
|
3072
|
-
"comment",
|
|
3073
|
-
"genre",
|
|
3074
|
-
"year",
|
|
3075
|
-
"date",
|
|
3076
|
-
"track",
|
|
3077
|
-
"trackNumber"
|
|
3078
|
-
]);
|
|
3079
|
-
NUMERIC_FIELDS = /* @__PURE__ */ new Set([
|
|
3080
|
-
"year",
|
|
3081
|
-
"track",
|
|
3082
|
-
"discNumber",
|
|
3083
|
-
"totalTracks",
|
|
3084
|
-
"totalDiscs",
|
|
3085
|
-
"bpm"
|
|
3086
|
-
]);
|
|
3087
|
-
}));
|
|
3088
|
-
//#endregion
|
|
3089
|
-
//#region src/version.ts
|
|
3090
|
-
var VERSION;
|
|
3091
|
-
var init_version = __esmMin((() => {
|
|
3092
|
-
VERSION = "2.4.0";
|
|
3093
|
-
}));
|
|
3094
|
-
//#endregion
|
|
3095
|
-
//#region src/runtime/module-loader-browser.ts
|
|
3096
|
-
var module_loader_browser_exports = /* @__PURE__ */ __exportAll({ loadTagLibModule: () => loadTagLibModule });
|
|
3097
|
-
async function loadTagLibModule(options) {
|
|
3098
|
-
let createTagLibModule;
|
|
3099
|
-
try {
|
|
3100
|
-
createTagLibModule = (await import("./taglib-wrapper.js")).default;
|
|
3101
|
-
} catch {
|
|
3102
|
-
try {
|
|
3103
|
-
createTagLibModule = (await import("./taglib-wrapper.js")).default;
|
|
3104
|
-
} catch {
|
|
3105
|
-
throw new TagLibInitializationError("Could not load taglib-wrapper.js. Ensure it is co-located with the browser bundle.");
|
|
3106
|
-
}
|
|
3107
|
-
}
|
|
3108
|
-
const moduleConfig = {};
|
|
3109
|
-
if (options?.wasmBinary) moduleConfig.wasmBinary = options.wasmBinary;
|
|
3110
|
-
if (options?.wasmUrl) moduleConfig.locateFile = (path) => {
|
|
3111
|
-
if (path.endsWith(".wasm")) return options.wasmUrl;
|
|
3112
|
-
return path;
|
|
3113
|
-
};
|
|
3114
|
-
else if (!options?.wasmBinary) {
|
|
3115
|
-
const wasmUrl = new URL("./taglib-web.wasm", import.meta.url);
|
|
3116
|
-
moduleConfig.locateFile = (path) => path.endsWith(".wasm") ? wasmUrl.href : path;
|
|
3117
|
-
}
|
|
3118
|
-
return await createTagLibModule(moduleConfig);
|
|
3119
|
-
}
|
|
3120
|
-
var init_module_loader_browser = __esmMin((() => {
|
|
3121
|
-
init_classes();
|
|
3122
|
-
}));
|
|
3123
|
-
//#endregion
|
|
3124
|
-
//#region src/taglib/taglib-class.ts
|
|
3125
|
-
function toWasiPath(osPath) {
|
|
3126
|
-
if (osPath.startsWith("\\\\") || osPath.startsWith("//")) throw new FileOperationError("read", `UNC paths are not supported. Path: ${osPath}`);
|
|
3127
|
-
let p = osPath;
|
|
3128
|
-
if (!p.startsWith("/") && !/^[A-Za-z]:/.test(p)) {
|
|
3129
|
-
const g = globalThis;
|
|
3130
|
-
const cwd = isDeno() ? Deno.cwd() : g.process?.cwd?.();
|
|
3131
|
-
if (cwd) p = cwd.replace(/[/\\]+$/, "") + "/" + p;
|
|
3132
|
-
}
|
|
3133
|
-
p = p.replaceAll("\\", "/");
|
|
3134
|
-
const driveMatch = p.match(/^([A-Za-z]):\//);
|
|
3135
|
-
if (driveMatch) p = `/${driveMatch[1].toUpperCase()}${p.slice(2)}`;
|
|
3136
|
-
p = p.replace(/\/\.\//g, "/").replace(/\/+/g, "/");
|
|
3137
|
-
if (!p.startsWith("/")) p = "/" + p;
|
|
3138
|
-
return p;
|
|
3139
|
-
}
|
|
3140
|
-
async function createTagLib(module) {
|
|
3141
|
-
return new TagLib(module);
|
|
3142
|
-
}
|
|
3143
|
-
var TagLib;
|
|
3144
|
-
var init_taglib_class = __esmMin((() => {
|
|
3145
|
-
init_audio_formats();
|
|
3146
|
-
init_errors();
|
|
3147
|
-
init_detector();
|
|
3148
|
-
init_audio_file_impl();
|
|
3149
|
-
init_load_audio_data();
|
|
3150
|
-
init_tag_mapping();
|
|
3151
|
-
init_version();
|
|
3152
|
-
init_embind_adapter();
|
|
3153
|
-
init_defineProperty();
|
|
3154
|
-
TagLib = class TagLib {
|
|
3155
|
-
constructor(module) {
|
|
3156
|
-
_defineProperty(this, "module", void 0);
|
|
3157
|
-
this.module = module;
|
|
3158
|
-
}
|
|
3159
|
-
static async initialize(options) {
|
|
3160
|
-
const { loadTagLibModule } = await Promise.resolve().then(() => (init_module_loader_browser(), module_loader_browser_exports));
|
|
3161
|
-
const module = await loadTagLibModule(options);
|
|
3162
|
-
return new TagLib(module);
|
|
3163
|
-
}
|
|
3164
|
-
async open(input, options) {
|
|
3165
|
-
if (!this.module.createFileHandle) throw new TagLibInitializationError("TagLib module not properly initialized: createFileHandle not found. Make sure the module is fully loaded before calling open.");
|
|
3166
|
-
const actualInput = isNamedAudioInput(input) ? input.data : input;
|
|
3167
|
-
const sourcePath = typeof actualInput === "string" ? actualInput : void 0;
|
|
3168
|
-
if (typeof actualInput === "string" && this.module.isWasi) {
|
|
3169
|
-
const wasiPath = toWasiPath(actualInput);
|
|
3170
|
-
if (this.module.loadAudioPath) {
|
|
3171
|
-
const fileHandle = await this.module.loadAudioPath(wasiPath, actualInput);
|
|
3172
|
-
return new AudioFileImpl(this.module, fileHandle, sourcePath, actualInput, false);
|
|
3173
|
-
}
|
|
3174
|
-
}
|
|
3175
|
-
const opts = {
|
|
3176
|
-
partial: true,
|
|
3177
|
-
maxHeaderSize: 1048576,
|
|
3178
|
-
maxFooterSize: 131072,
|
|
3179
|
-
...options
|
|
3180
|
-
};
|
|
3181
|
-
const { data: audioData, isPartiallyLoaded } = await loadAudioData(actualInput, opts);
|
|
3182
|
-
const uint8Array = actualInput instanceof Uint8Array && audioData.buffer === actualInput.buffer ? new Uint8Array(audioData.buffer.slice(audioData.byteOffset, audioData.byteOffset + audioData.byteLength)) : audioData;
|
|
3183
|
-
const rawHandle = this.module.createFileHandle();
|
|
3184
|
-
const fileHandle = this.module.isWasi ? rawHandle : wrapEmbindHandle(rawHandle);
|
|
3185
|
-
try {
|
|
3186
|
-
if (!fileHandle.loadFromBuffer(uint8Array)) throw new InvalidFormatError("Failed to load audio file. File may be corrupted or in an unsupported format", uint8Array.byteLength);
|
|
3187
|
-
return new AudioFileImpl(this.module, fileHandle, sourcePath, actualInput, isPartiallyLoaded, opts);
|
|
3188
|
-
} catch (error) {
|
|
3189
|
-
if (typeof fileHandle.destroy === "function") fileHandle.destroy();
|
|
3190
|
-
throw error;
|
|
3191
|
-
}
|
|
3192
|
-
}
|
|
3193
|
-
async edit(input, fn) {
|
|
3194
|
-
const file = await this.open(input);
|
|
3195
|
-
try {
|
|
3196
|
-
await fn(file);
|
|
3197
|
-
if (typeof input === "string") await file.saveToFile();
|
|
3198
|
-
else {
|
|
3199
|
-
file.save();
|
|
3200
|
-
return file.getFileBuffer();
|
|
3201
|
-
}
|
|
3202
|
-
} finally {
|
|
3203
|
-
file.dispose();
|
|
3204
|
-
}
|
|
3205
|
-
}
|
|
3206
|
-
async updateFile(path, tags) {
|
|
3207
|
-
const file = await this.open(path);
|
|
3208
|
-
try {
|
|
3209
|
-
mergeTagUpdates(file, tags);
|
|
3210
|
-
await file.saveToFile();
|
|
3211
|
-
} finally {
|
|
3212
|
-
file.dispose();
|
|
3213
|
-
}
|
|
3214
|
-
}
|
|
3215
|
-
async copyWithTags(sourcePath, destPath, tags) {
|
|
3216
|
-
const file = await this.open(sourcePath);
|
|
3217
|
-
try {
|
|
3218
|
-
mergeTagUpdates(file, tags);
|
|
3219
|
-
await file.saveToFile(destPath);
|
|
3220
|
-
} finally {
|
|
3221
|
-
file.dispose();
|
|
3222
|
-
}
|
|
3223
|
-
}
|
|
3224
|
-
version() {
|
|
3225
|
-
return `${VERSION} (TagLib ${this.taglibVersion()})`;
|
|
3226
|
-
}
|
|
3227
|
-
taglibVersion() {
|
|
3228
|
-
if (this.module.getVersion) return this.module.getVersion();
|
|
3229
|
-
if (this.module.version) return this.module.version();
|
|
3230
|
-
return "unknown";
|
|
3231
|
-
}
|
|
3232
|
-
};
|
|
3233
|
-
}));
|
|
3234
|
-
//#endregion
|
|
3235
|
-
//#region src/taglib/index.ts
|
|
3236
|
-
var init_taglib$1 = __esmMin((() => {
|
|
3237
|
-
init_audio_file_impl();
|
|
3238
|
-
init_taglib_class();
|
|
3239
|
-
init_errors();
|
|
3240
|
-
}));
|
|
3241
|
-
//#endregion
|
|
3242
|
-
//#region src/taglib.ts
|
|
3243
|
-
var taglib_exports = /* @__PURE__ */ __exportAll({
|
|
3244
|
-
AudioFileImpl: () => AudioFileImpl,
|
|
3245
|
-
EnvironmentError: () => EnvironmentError,
|
|
3246
|
-
FileOperationError: () => FileOperationError,
|
|
3247
|
-
InvalidFormatError: () => InvalidFormatError,
|
|
3248
|
-
MemoryError: () => MemoryError,
|
|
3249
|
-
MetadataError: () => MetadataError,
|
|
3250
|
-
SUPPORTED_FORMATS: () => SUPPORTED_FORMATS,
|
|
3251
|
-
TagLib: () => TagLib,
|
|
3252
|
-
TagLibError: () => TagLibError,
|
|
3253
|
-
TagLibInitializationError: () => TagLibInitializationError,
|
|
3254
|
-
UnsupportedFormatError: () => UnsupportedFormatError,
|
|
3255
|
-
createTagLib: () => createTagLib,
|
|
3256
|
-
isEnvironmentError: () => isEnvironmentError,
|
|
3257
|
-
isFileOperationError: () => isFileOperationError,
|
|
3258
|
-
isInvalidFormatError: () => isInvalidFormatError,
|
|
3259
|
-
isMemoryError: () => isMemoryError,
|
|
3260
|
-
isMetadataError: () => isMetadataError,
|
|
3261
|
-
isTagLibError: () => isTagLibError,
|
|
3262
|
-
isUnsupportedFormatError: () => isUnsupportedFormatError
|
|
3263
|
-
});
|
|
3264
|
-
var init_taglib = __esmMin((() => {
|
|
3265
|
-
init_taglib$1();
|
|
3266
|
-
}));
|
|
3267
|
-
//#endregion
|
|
3268
|
-
//#region src/simple/config.ts
|
|
3269
|
-
let cachedTagLib = null;
|
|
3270
|
-
async function getTagLib() {
|
|
3271
|
-
if (!cachedTagLib) {
|
|
3272
|
-
const { TagLib } = await Promise.resolve().then(() => (init_taglib(), taglib_exports));
|
|
3273
|
-
cachedTagLib = await TagLib.initialize(void 0);
|
|
3274
|
-
}
|
|
3275
|
-
return cachedTagLib;
|
|
3276
|
-
}
|
|
3277
|
-
//#endregion
|
|
3278
|
-
//#region src/simple/with-audio-file.ts
|
|
3279
|
-
init_errors();
|
|
3280
|
-
async function withAudioFile(file, fn, options) {
|
|
3281
|
-
const audioFile = await (await getTagLib()).open(file, options);
|
|
3282
|
-
try {
|
|
3283
|
-
if (!audioFile.isValid()) throw new InvalidFormatError("File may be corrupted or in an unsupported format");
|
|
3284
|
-
return await fn(audioFile);
|
|
3285
|
-
} finally {
|
|
3286
|
-
audioFile.dispose();
|
|
3287
|
-
}
|
|
3288
|
-
}
|
|
3289
|
-
async function withAudioFileSave(file, fn) {
|
|
3290
|
-
return withAudioFile(file, (audioFile) => {
|
|
3291
|
-
fn(audioFile);
|
|
3292
|
-
if (!audioFile.save()) throw new FileOperationError("save", "Failed to save metadata changes. The file may be read-only or corrupted.");
|
|
3293
|
-
return audioFile.getFileBuffer();
|
|
3294
|
-
}, { partial: false });
|
|
3295
|
-
}
|
|
3296
|
-
//#endregion
|
|
3297
|
-
//#region src/simple/picture-operations.ts
|
|
3298
|
-
async function readPictures(file) {
|
|
3299
|
-
return withAudioFile(file, (audioFile) => audioFile.getPictures());
|
|
3300
|
-
}
|
|
3301
|
-
async function applyPictures(file, pictures) {
|
|
3302
|
-
return withAudioFileSave(file, (audioFile) => {
|
|
3303
|
-
audioFile.setPictures(pictures);
|
|
3304
|
-
});
|
|
3305
|
-
}
|
|
3306
|
-
//#endregion
|
|
3307
|
-
//#region src/web-utils/canvas.ts
|
|
3308
|
-
async function setCoverArtFromCanvas(file, canvas, options = {}) {
|
|
3309
|
-
const { format = "image/jpeg", quality = .92, type = "FrontCover", description = "Front Cover" } = options;
|
|
3310
|
-
return applyPictures(file, [dataURLToPicture(canvas.toDataURL(format, quality), type, description)]);
|
|
3311
|
-
}
|
|
3312
|
-
async function canvasToPicture(canvas, options = {}) {
|
|
3313
|
-
const { format = "image/jpeg", quality = .92, type = "FrontCover", description } = options;
|
|
3314
|
-
return new Promise((resolve, reject) => {
|
|
3315
|
-
canvas.toBlob((blob) => {
|
|
3316
|
-
if (!blob) {
|
|
3317
|
-
reject(/* @__PURE__ */ new Error("Failed to convert canvas to blob"));
|
|
3318
|
-
return;
|
|
3319
|
-
}
|
|
3320
|
-
blob.arrayBuffer().then((arrayBuffer) => {
|
|
3321
|
-
const data = new Uint8Array(arrayBuffer);
|
|
3322
|
-
resolve({
|
|
3323
|
-
mimeType: format,
|
|
3324
|
-
data,
|
|
3325
|
-
type,
|
|
3326
|
-
...description !== void 0 ? { description } : {}
|
|
3327
|
-
});
|
|
3328
|
-
}, reject);
|
|
3329
|
-
}, format, quality);
|
|
3330
|
-
});
|
|
3331
|
-
}
|
|
3332
|
-
async function imageFileToPicture(file, type = "FrontCover", description) {
|
|
3333
|
-
const arrayBuffer = await file.arrayBuffer();
|
|
3334
|
-
const data = new Uint8Array(arrayBuffer);
|
|
3335
|
-
return {
|
|
3336
|
-
mimeType: file.type,
|
|
3337
|
-
data,
|
|
3338
|
-
type,
|
|
3339
|
-
description: description ?? file.name
|
|
3340
|
-
};
|
|
3341
|
-
}
|
|
3342
|
-
//#endregion
|
|
3343
|
-
//#region src/web-utils/dom-integration.ts
|
|
3344
|
-
function ensureArrayBufferBacked(data) {
|
|
3345
|
-
if (data.buffer instanceof ArrayBuffer) return data;
|
|
3346
|
-
const copy = new Uint8Array(data.length);
|
|
3347
|
-
copy.set(data);
|
|
3348
|
-
return copy;
|
|
3349
|
-
}
|
|
3350
|
-
function displayPicture(picture, imgElement) {
|
|
3351
|
-
if (imgElement.src.startsWith("blob:")) URL.revokeObjectURL(imgElement.src);
|
|
3352
|
-
const data = ensureArrayBufferBacked(picture.data);
|
|
3353
|
-
const blob = new Blob([data], { type: picture.mimeType });
|
|
3354
|
-
const objectURL = URL.createObjectURL(blob);
|
|
3355
|
-
imgElement.src = objectURL;
|
|
3356
|
-
imgElement.addEventListener("load", () => {
|
|
3357
|
-
setTimeout(() => URL.revokeObjectURL(objectURL), 100);
|
|
3358
|
-
}, { once: true });
|
|
3359
|
-
}
|
|
3360
|
-
function createPictureDownloadURL(picture, filename = "cover") {
|
|
3361
|
-
const data = ensureArrayBufferBacked(picture.data);
|
|
3362
|
-
const blob = new Blob([data], { type: picture.mimeType });
|
|
3363
|
-
return URL.createObjectURL(blob);
|
|
3364
|
-
}
|
|
3365
|
-
async function createPictureGallery(file, container, options = {}) {
|
|
3366
|
-
const pictures = await readPictures(file);
|
|
3367
|
-
container.innerHTML = "";
|
|
3368
|
-
pictures.forEach((picture, index) => {
|
|
3369
|
-
const wrapper = document.createElement("div");
|
|
3370
|
-
wrapper.className = options.className ?? "picture-item";
|
|
3371
|
-
const img = document.createElement("img");
|
|
3372
|
-
displayPicture(picture, img);
|
|
3373
|
-
img.alt = picture.description ?? `Picture ${index + 1}`;
|
|
3374
|
-
if (options.onClick) {
|
|
3375
|
-
img.style.cursor = "pointer";
|
|
3376
|
-
img.addEventListener("click", () => options.onClick(picture, index));
|
|
3377
|
-
}
|
|
3378
|
-
wrapper.appendChild(img);
|
|
3379
|
-
if (options.includeDescription && picture.description) {
|
|
3380
|
-
const caption = document.createElement("p");
|
|
3381
|
-
caption.textContent = picture.description;
|
|
3382
|
-
wrapper.appendChild(caption);
|
|
3383
|
-
}
|
|
3384
|
-
container.appendChild(wrapper);
|
|
3385
|
-
});
|
|
3386
|
-
}
|
|
3387
|
-
//#endregion
|
|
3388
|
-
export { canvasToPicture, createPictureDownloadURL, createPictureGallery, dataURLToPicture, displayPicture, imageFileToPicture, pictureToDataURL, setCoverArtFromCanvas };
|
|
1
|
+
var __defProp=Object.defineProperty;var __esmMin=(fn,res,err)=>()=>{if(err)throw err[0];try{return fn&&(res=fn(fn=0)),res}catch(e){throw err=[e],e}};var __exportAll=(all,no_symbols)=>{let target={};for(var name in all){__defProp(target,name,{get:all[name],enumerable:true})}if(!no_symbols){__defProp(target,Symbol.toStringTag,{value:`Module`})}return target};var SUPPORTED_FORMATS,TagLibError;var init_base=__esmMin((()=>{SUPPORTED_FORMATS=[`MP3`,`AAC`,`MP4`,`M4A`,`FLAC`,`OGG`,`OPUS`,`OggFLAC`,`SPEEX`,`WAV`,`AIFF`,`ASF`,`APE`,`DSF`,`DSDIFF`,`WV`,`MPC`,`TTA`,`SHN`,`MOD`,`S3M`,`IT`,`XM`,`MATROSKA`,`MKA`];TagLibError=class TagLibError extends Error{constructor(code,message,details){super(message);this.code=code;this.details=details;this.name=`TagLibError`;Object.setPrototypeOf(this,TagLibError.prototype)}}}));function errorMessage(error){return error instanceof Error?error.message:String(error)}function createErrorMessage(prefix,details){return`${prefix}: ${details}`}function formatFileSize(bytes){if(bytes<1024)return`${bytes} bytes`;if(bytes<1048576)return`${(bytes/1024).toFixed(1)} KB`;return`${(bytes/1048576).toFixed(1)} MB`}var TagLibInitializationError,InvalidFormatError,UnsupportedFormatError,FileOperationError,MetadataError,MemoryError,EnvironmentError;var init_classes=__esmMin((()=>{init_base();TagLibInitializationError=class TagLibInitializationError extends TagLibError{constructor(message,details){super(`INITIALIZATION`,createErrorMessage(`Failed to initialize TagLib Wasm module`,message),details);this.name=`TagLibInitializationError`;Object.setPrototypeOf(this,TagLibInitializationError.prototype)}};InvalidFormatError=class InvalidFormatError extends TagLibError{constructor(message,bufferSize,details){const errorDetails=[`Invalid audio file format: ${message}`];if(bufferSize!==void 0){errorDetails.push(`Buffer size: ${formatFileSize(bufferSize)}`);if(bufferSize<1024)errorDetails.push(`Audio files must be at least 1KB to contain valid headers.`)}super(`INVALID_FORMAT`,errorDetails.join(`. `),{...details,bufferSize});this.bufferSize=bufferSize;this.name=`InvalidFormatError`;Object.setPrototypeOf(this,InvalidFormatError.prototype)}};UnsupportedFormatError=class UnsupportedFormatError extends TagLibError{constructor(format,supportedFormats=SUPPORTED_FORMATS,details){super(`UNSUPPORTED_FORMAT`,`Unsupported audio format: ${format}. Supported formats: ${supportedFormats.join(`, `)}`,{...details,format,supportedFormats});this.format=format;this.supportedFormats=supportedFormats;this.name=`UnsupportedFormatError`;Object.setPrototypeOf(this,UnsupportedFormatError.prototype)}};FileOperationError=class FileOperationError extends TagLibError{constructor(operation,message,path,details){const errorDetails=[`Failed to ${operation} file`];if(path)errorDetails.push(`Path: ${path}`);errorDetails.push(message);super(`FILE_OPERATION`,errorDetails.join(`. `),{...details,operation,path});this.operation=operation;this.path=path;this.name=`FileOperationError`;Object.setPrototypeOf(this,FileOperationError.prototype)}};MetadataError=class MetadataError extends TagLibError{constructor(operation,message,field,details){const errorDetails=[`Failed to ${operation} metadata`];if(field)errorDetails.push(`Field: ${field}`);errorDetails.push(message);super(`METADATA`,errorDetails.join(`. `),{...details,operation,field});this.operation=operation;this.field=field;this.name=`MetadataError`;Object.setPrototypeOf(this,MetadataError.prototype)}};MemoryError=class MemoryError extends TagLibError{constructor(message,details){super(`MEMORY`,createErrorMessage(`Memory allocation failed`,message),details);this.name=`MemoryError`;Object.setPrototypeOf(this,MemoryError.prototype)}};EnvironmentError=class EnvironmentError extends TagLibError{constructor(environment,reason,requiredFeature){const message=requiredFeature?`Environment '${environment}' ${reason}. Required feature: ${requiredFeature}.`:`Environment '${environment}' ${reason}.`;super(`ENVIRONMENT`,message);this.environment=environment;this.reason=reason;this.requiredFeature=requiredFeature;this.name=`EnvironmentError`;Object.setPrototypeOf(this,EnvironmentError.prototype)}}}));init_classes();function pictureToDataURL(picture){const data=picture.data;const CHUNK=32768;let binary=``;for(let i=0;i<data.length;i+=CHUNK)binary+=String.fromCodePoint(...data.subarray(i,i+CHUNK));const base64=btoa(binary);return`data:${picture.mimeType};base64,${base64}`}function dataURLToPicture(dataURL,type=`FrontCover`,description){const matches=/^data:([^;]+);base64,(.+)$/.exec(dataURL);if(!matches)throw new InvalidFormatError(`Invalid data URL format`);const[,mimeType,base64]=matches;const binaryString=atob(base64);const data=new Uint8Array(binaryString.length);for(let i=0;i<binaryString.length;i++)data[i]=binaryString.codePointAt(i);return{mimeType,data,type,...description!==void 0?{description}:{}}}function isNamedAudioInput(input){return typeof input===`object`&&input!==null&&`name`in input&&`data`in input&&!(input instanceof File)&&!(input instanceof Uint8Array)&&!(input instanceof ArrayBuffer)}var init_audio_formats=__esmMin((()=>{}));var init_tags=__esmMin((()=>{}));var init_metadata_mappings=__esmMin((()=>{}));var PICTURE_TYPE_VALUES,PICTURE_TYPE_NAMES;var init_pictures=__esmMin((()=>{PICTURE_TYPE_VALUES={Other:0,FileIcon:1,OtherFileIcon:2,FrontCover:3,BackCover:4,LeafletPage:5,Media:6,LeadArtist:7,Artist:8,Conductor:9,Band:10,Composer:11,Lyricist:12,RecordingLocation:13,DuringRecording:14,DuringPerformance:15,MovieScreenCapture:16,ColouredFish:17,Illustration:18,BandLogo:19,PublisherLogo:20};PICTURE_TYPE_NAMES={0:`Other`,1:`FileIcon`,2:`OtherFileIcon`,3:`FrontCover`,4:`BackCover`,5:`LeafletPage`,6:`Media`,7:`LeadArtist`,8:`Artist`,9:`Conductor`,10:`Band`,11:`Composer`,12:`Lyricist`,13:`RecordingLocation`,14:`DuringRecording`,15:`DuringPerformance`,16:`MovieScreenCapture`,17:`ColouredFish`,18:`Illustration`,19:`BandLogo`,20:`PublisherLogo`}}));var init_chapters=__esmMin((()=>{}));var init_bwf=__esmMin((()=>{}));var init_config=__esmMin((()=>{}));var init_format_property_keys=__esmMin((()=>{}));var init_types$1=__esmMin((()=>{init_audio_formats();init_tags();init_metadata_mappings();init_pictures();init_chapters();init_bwf();init_config();init_format_property_keys()}));var init_types=__esmMin((()=>{init_types$1()}));function readFixedString(bytes,offset,len){let end=offset;const max=Math.min(offset+len,bytes.length);while(end<max&&bytes[end]!==0)end++;let s=``;for(let i=offset;i<end;i++)s+=String.fromCodePoint(bytes[i]);return s}function writeFixedString(bytes,offset,len,value){for(let i=0;i<len;i++)bytes[offset+i]=i<value.length?(value.codePointAt(i)??0)&255:0}function clampInt16(n){return Math.max(-32768,Math.min(32767,Math.round(n)))}function loudnessRaw(v){return v===void 0?LOUDNESS_UNSET:clampInt16(v*100)}function loudnessFromRaw(raw){return raw===LOUDNESS_UNSET?void 0:raw/100}function bytesToHex(bytes){let s=``;for(const b of bytes)s+=b.toString(16).padStart(2,`0`);return s}function hexToBytes(hex,outLen){const clean=hex.replace(/[^0-9a-fA-F]/g,``);const out=new Uint8Array(outLen);for(let i=0;i+1<clean.length+1&&i/2<outLen;i+=2){const pair=clean.slice(i,i+2);if(pair.length===2)out[i/2]=Number.parseInt(pair,16)}return out}function decodeLoudnessFields(dv){const result={};for(const[field,offset]of LOUDNESS_FIELDS){const value=loudnessFromRaw(dv.getInt16(LOUDNESS_OFFSET+offset,true));if(value!==void 0)result[field]=value}return result}function decodeBext(bytes){if(bytes.length<348)return void 0;const dv=new DataView(bytes.buffer,bytes.byteOffset,bytes.byteLength);const timeRefLow=dv.getUint32(338,true);const timeRefHigh=dv.getUint32(342,true);const version=dv.getUint16(VERSION_OFFSET,true);const result={description:readFixedString(bytes,0,256),originator:readFixedString(bytes,256,32),originatorReference:readFixedString(bytes,288,32),originationDate:readFixedString(bytes,320,10),originationTime:readFixedString(bytes,330,8),timeReferenceSamples:BigInt(timeRefHigh)<<32n|BigInt(timeRefLow),version,codingHistory:bytes.length>FIXED_PREFIX_LEN?readFixedString(bytes,FIXED_PREFIX_LEN,bytes.length-FIXED_PREFIX_LEN):``};if(version>=1&&bytes.length>=412)result.umid=bytesToHex(bytes.subarray(UMID_OFFSET,412));if(version>=2&&bytes.length>=422)Object.assign(result,decodeLoudnessFields(dv));return result}function encodeBext(b){const codingHistory=b.codingHistory??``;const bytes=new Uint8Array(FIXED_PREFIX_LEN+codingHistory.length);const dv=new DataView(bytes.buffer);const hasLoudness=b.loudnessValueDb!==void 0||b.loudnessRangeDb!==void 0||b.maxTruePeakLevelDbtp!==void 0||b.maxMomentaryLoudnessDb!==void 0||b.maxShortTermLoudnessDb!==void 0;let version;if(Number.isInteger(b.version))version=b.version;else if(hasLoudness)version=2;else if(b.umid)version=1;else version=0;writeFixedString(bytes,0,256,b.description??``);writeFixedString(bytes,256,32,b.originator??``);writeFixedString(bytes,288,32,b.originatorReference??``);writeFixedString(bytes,320,10,b.originationDate??``);writeFixedString(bytes,330,8,b.originationTime??``);const tr=b.timeReferenceSamples??0n;dv.setUint32(338,Number(tr&4294967295n),true);dv.setUint32(342,Number(tr>>32n&4294967295n),true);dv.setUint16(VERSION_OFFSET,version,true);if(version>=1&&b.umid)bytes.set(hexToBytes(b.umid,UMID_LEN),UMID_OFFSET);if(version>=2){dv.setInt16(LOUDNESS_OFFSET,loudnessRaw(b.loudnessValueDb),true);dv.setInt16(414,loudnessRaw(b.loudnessRangeDb),true);dv.setInt16(416,loudnessRaw(b.maxTruePeakLevelDbtp),true);dv.setInt16(418,loudnessRaw(b.maxMomentaryLoudnessDb),true);dv.setInt16(420,loudnessRaw(b.maxShortTermLoudnessDb),true)}writeFixedString(bytes,FIXED_PREFIX_LEN,codingHistory.length,codingHistory);return bytes}var FIXED_PREFIX_LEN,VERSION_OFFSET,UMID_OFFSET,UMID_LEN,LOUDNESS_OFFSET,LOUDNESS_UNSET,LOUDNESS_FIELDS;var init_bext=__esmMin((()=>{FIXED_PREFIX_LEN=602;VERSION_OFFSET=346;UMID_OFFSET=348;UMID_LEN=64;LOUDNESS_OFFSET=412;LOUDNESS_UNSET=32767;LOUDNESS_FIELDS=[[`loudnessValueDb`,0],[`loudnessRangeDb`,2],[`maxTruePeakLevelDbtp`,4],[`maxMomentaryLoudnessDb`,6],[`maxShortTermLoudnessDb`,8]]}));function isTagLibError(error){return error instanceof TagLibError}function isInvalidFormatError(error){return error instanceof InvalidFormatError}function isUnsupportedFormatError(error){return error instanceof UnsupportedFormatError}function isFileOperationError(error){return error instanceof FileOperationError}function isMetadataError(error){return error instanceof MetadataError}function isMemoryError(error){return error instanceof MemoryError}function isEnvironmentError(error){return error instanceof EnvironmentError}var init_guards=__esmMin((()=>{init_base();init_classes()}));var init_errors$1=__esmMin((()=>{init_base();init_classes();init_guards()}));var init_errors=__esmMin((()=>{init_errors$1()}));function requireBwf(format){if(!BWF_FORMATS.has(format))throw new UnsupportedFormatError(format,[`WAV`,`FLAC`],{operation:`BWF metadata`})}function getBextData(handle){const raw=handle.getBextData();return raw&&raw.length>0?raw:void 0}function setBextData(handle,format,data){requireBwf(format);handle.setBextData(data)}function getBext(handle){const raw=handle.getBextData();return raw&&raw.length>0?decodeBext(raw):void 0}function setBext(handle,format,bext){requireBwf(format);handle.setBextData(encodeBext(bext))}function getIxml(handle){return handle.getIxml()}function setIxml(handle,format,data){requireBwf(format);handle.setIxml(data)}var BWF_FORMATS;var init_audio_file_bwf=__esmMin((()=>{init_bext();init_errors();BWF_FORMATS=/* @__PURE__ */ new Set([`WAV`,`FLAC`])}));function assertMp3(format){if(format!==`MP3`&&format!==`AAC`)throw new UnsupportedFormatError(format,[`MP3`,`AAC`],{operation:`id3v2Frames`})}function assertFrameId(id,operation){if(!FRAME_ID_PATTERN.test(id))throw new MetadataError(operation,`Invalid ID3v2 frame ID: "${id}". Frame IDs must match [A-Z0-9]{4}`,id)}function assertFrameBodies(id,data){for(const body of data)if(body.length===0)throw new MetadataError(`write`,`Frame data must not be empty: zero-size ID3v2 frames are invalid`,id)}function toPublicFrame(frame){return{id:frame.id,data:frame.data,...frame.flags?{flags:frame.flags}:{}}}var FRAME_ID_PATTERN;var init_id3v2_frames=__esmMin((()=>{init_classes();FRAME_ID_PATTERN=/^[A-Z0-9]{4}$/}));function getPlatformIO(){throw new Error(`Filesystem operations are not available in the browser.`)}var init__taglib_platform_io_stub=__esmMin((()=>{}));async function writeFileData(path,data){try{await getPlatformIO().writeFile(path,data)}catch(error){if(error instanceof EnvironmentError)throw error;throw new FileOperationError(`write`,error.message,path)}}var init_write=__esmMin((()=>{init_errors();init__taglib_platform_io_stub()}));function getNodeFsSync(){return null}var init__taglib_node_fs_stub=__esmMin((()=>{}));function normalized(value){return value}var init_rating=__esmMin((()=>{}));function isDeno(){return g.Deno!==void 0}var g,EXNREF_PROBE;var init_detector=__esmMin((()=>{g=globalThis;EXNREF_PROBE=new Uint8Array([0,97,115,109,1,0,0,0,6,6,1,105,0,208,105,11])}));function freeformTypeFromCode(code){return CODE_TO_TYPE[code]??`other`}function freeformCode(type,typeCode){if(type===`other`){if(typeCode===void 0||!Number.isInteger(typeCode)||typeCode<0||typeCode>255)throw new MetadataError(`write`,`MP4 freeform type "other" requires typeCode 0..255`);return typeCode}return TYPE_TO_CODE[type]}function validateAtomPart(label,value){if(value.length===0)throw new MetadataError(`write`,`MP4 freeform ${label} must not be empty`);if(value.includes(`:`))throw new MetadataError(`write`,`MP4 freeform ${label} must not contain ":"`)}function encodeFreeformValue(type,value){if(type===`utf8`){if(typeof value!==`string`)throw new MetadataError(`write`,`MP4 freeform type "utf8" requires a string value`);return new TextEncoder().encode(value)}if(type===`integer`){if(typeof value!==`number`||!Number.isInteger(value)||value<INT32_MIN||value>INT32_MAX)throw new MetadataError(`write`,`MP4 freeform type "integer" requires an int32 value`);const bytes=/* @__PURE__ */ new Uint8Array(4);new DataView(bytes.buffer).setInt32(0,value,false);return bytes}if(!(value instanceof Uint8Array))throw new MetadataError(`write`,`MP4 freeform type "${type}" requires a Uint8Array value`);return new Uint8Array(value)}function decodeFreeformValue(type,bytes){if(type===`utf8`)return new TextDecoder().decode(bytes);if(type===`integer`&&bytes.byteLength===4)return new DataView(bytes.buffer,bytes.byteOffset,4).getInt32(0,false);return new Uint8Array(bytes)}function validateFreeformItems(items){const types=/* @__PURE__ */ new Map;for(const item of items){const atom=`${item.mean}\u0000${item.name}`;const signature=item.type===`other`?`other:${item.typeCode??`missing`}`:item.type;const previous=types.get(atom);if(previous!==void 0&&previous!==signature)throw new MetadataError(`write`,`MP4 freeform atom "${item.mean}:${item.name}" cannot mix types "${previous}" and "${signature}"`);types.set(atom,signature)}}function toRawFreeformItem(item){validateAtomPart(`mean`,item.mean);validateAtomPart(`name`,item.name);return{mean:item.mean,name:item.name,type:freeformCode(item.type,item.typeCode),value:encodeFreeformValue(item.type,item.value)}}function fromRawFreeformItem(raw){const type=freeformTypeFromCode(raw.type);if(type===`integer`&&raw.value.byteLength!==4)return{mean:raw.mean,name:raw.name,type:`other`,typeCode:raw.type,value:new Uint8Array(raw.value)};const value=decodeFreeformValue(type,raw.value);return type===`other`?{mean:raw.mean,name:raw.name,type,typeCode:raw.type,value}:{mean:raw.mean,name:raw.name,type,value}}var TYPE_TO_CODE,CODE_TO_TYPE,INT32_MIN,INT32_MAX;var init_mp4_freeform=__esmMin((()=>{init_errors();TYPE_TO_CODE={implicit:0,utf8:1,utf16:2,jpeg:13,png:14,integer:21,bmp:27,undefined:255};CODE_TO_TYPE={0:`implicit`,1:`utf8`,2:`utf16`,13:`jpeg`,14:`png`,21:`integer`,27:`bmp`,255:`undefined`};INT32_MIN=-2147483648;INT32_MAX=2147483647}));var ADDITIONAL_PROPERTIES;var init_additional_properties=__esmMin((()=>{ADDITIONAL_PROPERTIES={albumArtistSort:{key:`ALBUMARTISTSORT`,description:`Sort name for album artist (for alphabetization)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TSO2`},vorbis:`ALBUMARTISTSORT`,mp4:`soaa`}},composerSort:{key:`COMPOSERSORT`,description:`Sort name for composer (for alphabetization)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TSOC`},vorbis:`COMPOSERSORT`,mp4:`soco`}},subtitle:{key:`SUBTITLE`,description:`Subtitle or description refinement`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TIT3`},vorbis:`SUBTITLE`,mp4:`----:com.apple.iTunes:SUBTITLE`}},label:{key:`LABEL`,description:`Record label name`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`,`WAV`],mappings:{id3v2:{frame:`TPUB`},vorbis:`LABEL`,mp4:`----:com.apple.iTunes:LABEL`,wav:`IPUB`}},producer:{key:`PRODUCER`,description:`Producer of the recording`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TXXX`,description:`PRODUCER`},vorbis:`PRODUCER`,mp4:`----:com.apple.iTunes:PRODUCER`}},radioStationOwner:{key:`RADIOSTATIONOWNER`,description:`Owner of the radio station`,type:`string`,supportedFormats:[`ID3v2`],mappings:{id3v2:{frame:`TRSO`}}},asin:{key:`ASIN`,description:`Amazon Standard Identification Number`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TXXX`,description:`ASIN`},vorbis:`ASIN`,mp4:`----:com.apple.iTunes:ASIN`}},musicbrainzReleaseArtistId:{key:`MUSICBRAINZ_ALBUMARTISTID`,description:`MusicBrainz Release Artist ID (UUID)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TXXX`,description:`MusicBrainz Album Artist Id`},vorbis:`MUSICBRAINZ_ALBUMARTISTID`,mp4:`----:com.apple.iTunes:MusicBrainz Album Artist Id`}},musicbrainzWorkId:{key:`MUSICBRAINZ_WORKID`,description:`MusicBrainz Work ID (UUID)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TXXX`,description:`MusicBrainz Work Id`},vorbis:`MUSICBRAINZ_WORKID`,mp4:`----:com.apple.iTunes:MusicBrainz Work Id`}},musicbrainzReleaseTrackId:{key:`MUSICBRAINZ_RELEASETRACKID`,description:`MusicBrainz Release Track ID (UUID)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TXXX`,description:`MusicBrainz Release Track Id`},vorbis:`MUSICBRAINZ_RELEASETRACKID`,mp4:`----:com.apple.iTunes:MusicBrainz Release Track Id`}},podcastId:{key:`PODCASTID`,description:`Podcast episode identifier`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TGID`},vorbis:`PODCASTID`,mp4:`egid`}},podcastUrl:{key:`PODCASTURL`,description:`Podcast feed URL`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`WFED`},vorbis:`PODCASTURL`,mp4:`purl`}},originalArtist:{key:`ORIGINALARTIST`,description:`Original artist of a cover or remix`,type:`string`,supportedFormats:[`ID3v2`,`Vorbis`],mappings:{id3v2:{frame:`TOPE`},vorbis:`ORIGINALARTIST`}},originalAlbum:{key:`ORIGINALALBUM`,description:`Original album of a cover or remix`,type:`string`,supportedFormats:[`ID3v2`,`Vorbis`],mappings:{id3v2:{frame:`TOAL`},vorbis:`ORIGINALALBUM`}},originalDate:{key:`ORIGINALDATE`,description:`Original release date`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TDOR`},vorbis:`ORIGINALDATE`,mp4:`----:com.apple.iTunes:ORIGINALDATE`}},script:{key:`SCRIPT`,description:`Writing script used for text (e.g., Latn, Jpan)`,type:`string`,supportedFormats:[`MP4`,`Vorbis`],mappings:{vorbis:`SCRIPT`,mp4:`----:com.apple.iTunes:SCRIPT`}},involvedPeople:{key:`INVOLVEDPEOPLE`,description:`List of involved people and their roles`,type:`string`,supportedFormats:[`ID3v2`],mappings:{id3v2:{frame:`TIPL`}}},encoding:{key:`ENCODING`,description:`Encoding software or settings`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`,`WAV`],mappings:{id3v2:{frame:`TSSE`},vorbis:`ENCODING`,mp4:`©too`,wav:`ISFT`}}}}));var BASIC_PROPERTIES;var init_basic_properties=__esmMin((()=>{BASIC_PROPERTIES={title:{key:`TITLE`,description:`The title of the track`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`,`WAV`],mappings:{id3v2:{frame:`TIT2`},vorbis:`TITLE`,mp4:`©nam`,wav:`INAM`}},artist:{key:`ARTIST`,description:`The primary performer(s) of the track`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`,`WAV`],mappings:{id3v2:{frame:`TPE1`},vorbis:`ARTIST`,mp4:`©ART`,wav:`IART`}},album:{key:`ALBUM`,description:`The album/collection name`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`,`WAV`],mappings:{id3v2:{frame:`TALB`},vorbis:`ALBUM`,mp4:`©alb`,wav:`IPRD`}},date:{key:`DATE`,description:`The date of recording (typically year)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`,`WAV`],mappings:{id3v2:{frame:`TDRC`},vorbis:`DATE`,mp4:`©day`,wav:`ICRD`}},trackNumber:{key:`TRACKNUMBER`,description:`The track number within the album`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`,`WAV`],mappings:{id3v2:{frame:`TRCK`},vorbis:`TRACKNUMBER`,mp4:`trkn`,wav:`ITRK`}},genre:{key:`GENRE`,description:`The musical genre`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`,`WAV`],mappings:{id3v2:{frame:`TCON`},vorbis:`GENRE`,mp4:`©gen`,wav:`IGNR`}},comment:{key:`COMMENT`,description:`Comments or notes about the track`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`,`WAV`],mappings:{id3v2:{frame:`COMM`},vorbis:`COMMENT`,mp4:`©cmt`,wav:`ICMT`}}}}));var GENERAL_EXTENDED_PROPERTIES;var init_general_extended_properties=__esmMin((()=>{GENERAL_EXTENDED_PROPERTIES={albumArtist:{key:`ALBUMARTIST`,description:`The album artist (band/orchestra/ensemble)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TPE2`},vorbis:`ALBUMARTIST`,mp4:`aART`}},composer:{key:`COMPOSER`,description:`The original composer(s) of the track`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TCOM`},vorbis:`COMPOSER`,mp4:`©wrt`}},copyright:{key:`COPYRIGHT`,description:`Copyright information`,type:`string`,supportedFormats:[`ID3v2`,`Vorbis`],mappings:{vorbis:`COPYRIGHT`}},encodedBy:{key:`ENCODEDBY`,description:`The encoding software or person`,type:`string`,supportedFormats:[`ID3v2`,`Vorbis`],mappings:{vorbis:`ENCODEDBY`}},discNumber:{key:`DISCNUMBER`,description:`The disc number for multi-disc sets`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TPOS`},vorbis:`DISCNUMBER`,mp4:`disk`}},bpm:{key:`BPM`,description:`Beats per minute`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TBPM`},vorbis:`BPM`,mp4:`tmpo`}},totalTracks:{key:`TRACKTOTAL`,description:`Total number of tracks on the album`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TRCK`},vorbis:`TRACKTOTAL`,mp4:`trkn`}},totalDiscs:{key:`DISCTOTAL`,description:`Total number of discs in the set`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TPOS`},vorbis:`DISCTOTAL`,mp4:`disk`}},compilation:{key:`COMPILATION`,description:`Whether the album is a compilation (various artists)`,type:`boolean`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TCMP`},vorbis:`COMPILATION`,mp4:`cpil`}},titleSort:{key:`TITLESORT`,description:`Sort name for title (for alphabetization)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TSOT`},vorbis:`TITLESORT`,mp4:`sonm`}},artistSort:{key:`ARTISTSORT`,description:`Sort name for artist (for alphabetization)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TSOP`},vorbis:`ARTISTSORT`,mp4:`soar`}},albumSort:{key:`ALBUMSORT`,description:`Sort name for album (for alphabetization)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TSOA`},vorbis:`ALBUMSORT`,mp4:`soal`}},lyricist:{key:`LYRICIST`,description:`The lyrics/text writer(s)`,type:`string`,supportedFormats:[`Vorbis`],mappings:{vorbis:`LYRICIST`}},conductor:{key:`CONDUCTOR`,description:`The conductor`,type:`string`,supportedFormats:[`Vorbis`],mappings:{vorbis:`CONDUCTOR`}},remixedBy:{key:`REMIXER`,description:`Person who remixed the track`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TPE4`},vorbis:`REMIXER`,mp4:`----:com.apple.iTunes:REMIXER`}},language:{key:`LANGUAGE`,description:`Language of vocals/lyrics`,type:`string`,supportedFormats:[`Vorbis`],mappings:{vorbis:`LANGUAGE`}},publisher:{key:`PUBLISHER`,description:`The publisher`,type:`string`,supportedFormats:[`Vorbis`],mappings:{vorbis:`PUBLISHER`}},mood:{key:`MOOD`,description:`The mood/atmosphere of the track`,type:`string`,supportedFormats:[`Vorbis`],mappings:{vorbis:`MOOD`}},media:{key:`MEDIA`,description:`Media type (CD, vinyl, etc.)`,type:`string`,supportedFormats:[`Vorbis`],mappings:{vorbis:`MEDIA`}},grouping:{key:`GROUPING`,description:`Content group/work`,type:`string`,supportedFormats:[`MP4`,`Vorbis`],mappings:{vorbis:`GROUPING`,mp4:`©grp`}},work:{key:`WORK`,description:`Work name`,type:`string`,supportedFormats:[`Vorbis`],mappings:{vorbis:`WORK`}},lyrics:{key:`LYRICS`,description:`Lyrics content`,type:`string`,supportedFormats:[`Vorbis`],mappings:{vorbis:`LYRICS`}},isrc:{key:`ISRC`,description:`International Standard Recording Code`,type:`string`,supportedFormats:[`Vorbis`],mappings:{vorbis:`ISRC`}},catalogNumber:{key:`CATALOGNUMBER`,description:`Catalog number`,type:`string`,supportedFormats:[`Vorbis`],mappings:{vorbis:`CATALOGNUMBER`}},barcode:{key:`BARCODE`,description:`Barcode (EAN/UPC)`,type:`string`,supportedFormats:[`Vorbis`],mappings:{vorbis:`BARCODE`}}}}));var SPECIALIZED_PROPERTIES;var init_specialized_properties=__esmMin((()=>{SPECIALIZED_PROPERTIES={musicbrainzArtistId:{key:`MUSICBRAINZ_ARTISTID`,description:`MusicBrainz Artist ID (UUID)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TXXX`,description:`MusicBrainz Artist Id`},vorbis:`MUSICBRAINZ_ARTISTID`,mp4:`----:com.apple.iTunes:MusicBrainz Artist Id`}},musicbrainzReleaseId:{key:`MUSICBRAINZ_ALBUMID`,description:`MusicBrainz Release ID (UUID)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TXXX`,description:`MusicBrainz Album Id`},vorbis:`MUSICBRAINZ_ALBUMID`,mp4:`----:com.apple.iTunes:MusicBrainz Album Id`}},musicbrainzTrackId:{key:`MUSICBRAINZ_TRACKID`,description:`MusicBrainz Recording ID (UUID)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`UFID`,description:`http://musicbrainz.org`},vorbis:`MUSICBRAINZ_TRACKID`,mp4:`----:com.apple.iTunes:MusicBrainz Track Id`}},musicbrainzReleaseGroupId:{key:`MUSICBRAINZ_RELEASEGROUPID`,description:`MusicBrainz Release Group ID (UUID)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TXXX`,description:`MusicBrainz Release Group Id`},vorbis:`MUSICBRAINZ_RELEASEGROUPID`,mp4:`----:com.apple.iTunes:MusicBrainz Release Group Id`}},releaseType:{key:`RELEASETYPE`,description:`Release type (album, single, EP, compilation, ...). Multi-value (e.g. 'album' + 'EP'). TagLib 2.3.2 translates the RELEASETYPE key per format: ID3v2 TXXX 'MUSICBRAINZ ALBUM TYPE' (TagLib's description casing), MP4 freeform atom, APEv2 MUSICBRAINZ_ALBUMTYPE, ASF 'MusicBrainz/Album Type', Vorbis/Matroska raw RELEASETYPE`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`,`APE`,`ASF`,`Matroska`],mappings:{id3v2:{frame:`TXXX`,description:`MusicBrainz Album Type`},vorbis:`RELEASETYPE`,mp4:`----:com.apple.iTunes:MusicBrainz Album Type`}},releaseCountry:{key:`RELEASECOUNTRY`,description:`Release country (ISO 3166-1 code, e.g. 'US'). TagLib 2.3.2 translates the RELEASECOUNTRY key per format: ID3v2 TXXX 'MUSICBRAINZ ALBUM RELEASE COUNTRY' (TagLib's description casing; an uppercase TXXX:RELEASECOUNTRY description also reads back), MP4 freeform atom 'MusicBrainz Album Release Country', APEv2 raw RELEASECOUNTRY, ASF 'MusicBrainz/Album Release Country', WAV ICNT, Vorbis/Matroska raw RELEASECOUNTRY`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`,`APE`,`ASF`,`Matroska`,`WAV`],mappings:{id3v2:{frame:`TXXX`,description:`MusicBrainz Album Release Country`},vorbis:`RELEASECOUNTRY`,mp4:`----:com.apple.iTunes:MusicBrainz Album Release Country`}},releaseStatus:{key:`RELEASESTATUS`,description:`Release status (official, promotion, bootleg, ...). TagLib 2.3.2 translates the RELEASESTATUS key per format: ID3v2 TXXX 'MUSICBRAINZ ALBUM STATUS' (TagLib's description casing), MP4 freeform atom 'MusicBrainz Album Status', APEv2 MUSICBRAINZ_ALBUMSTATUS, ASF 'MusicBrainz/Album Status', Vorbis/Matroska raw RELEASESTATUS`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`,`APE`,`ASF`,`Matroska`],mappings:{id3v2:{frame:`TXXX`,description:`MusicBrainz Album Status`},vorbis:`RELEASESTATUS`,mp4:`----:com.apple.iTunes:MusicBrainz Album Status`}},itunesAdvisory:{key:`ITUNESADVISORY`,description:`Content advisory in the ITUNESADVISORY convention ('1' = explicit, '2' = clean, '0' = unspecified). On MP4 the value is stored in the native rtng atom and surfaced here. The typed tri-state lives on ExtendedTag.advisory; aliases CONTENTADVISORY and EXPLICIT resolve here`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`,`APE`,`ASF`],mappings:{id3v2:{frame:`TXXX`,description:`ITUNESADVISORY`},vorbis:`ITUNESADVISORY`,mp4:`----:com.apple.iTunes:ITUNESADVISORY`}},replayGainTrackGain:{key:`REPLAYGAIN_TRACK_GAIN`,description:`ReplayGain track gain in dB (e.g., '-6.54 dB')`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TXXX`,description:`ReplayGain_Track_Gain`},vorbis:`REPLAYGAIN_TRACK_GAIN`,mp4:`----:com.apple.iTunes:replaygain_track_gain`}},replayGainTrackPeak:{key:`REPLAYGAIN_TRACK_PEAK`,description:`ReplayGain track peak value (0.0-1.0)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TXXX`,description:`ReplayGain_Track_Peak`},vorbis:`REPLAYGAIN_TRACK_PEAK`,mp4:`----:com.apple.iTunes:replaygain_track_peak`}},replayGainAlbumGain:{key:`REPLAYGAIN_ALBUM_GAIN`,description:`ReplayGain album gain in dB`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TXXX`,description:`ReplayGain_Album_Gain`},vorbis:`REPLAYGAIN_ALBUM_GAIN`,mp4:`----:com.apple.iTunes:replaygain_album_gain`}},replayGainAlbumPeak:{key:`REPLAYGAIN_ALBUM_PEAK`,description:`ReplayGain album peak value (0.0-1.0)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TXXX`,description:`ReplayGain_Album_Peak`},vorbis:`REPLAYGAIN_ALBUM_PEAK`,mp4:`----:com.apple.iTunes:replaygain_album_peak`}},r128TrackGain:{key:`R128_TRACK_GAIN`,description:`EBU R128 track loudness gain (RFC 7845), raw wire value: signed Q7.8 integer (dB x 256, e.g. '-573' = -2.23828125 dB). readTags() converts to a decibel number (see ExtendedTag.r128TrackGain)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`,`ASF`],mappings:{id3v2:{frame:`TXXX`,description:`R128_TRACK_GAIN`},vorbis:`R128_TRACK_GAIN`,mp4:`----:com.apple.iTunes:R128_TRACK_GAIN`}},r128AlbumGain:{key:`R128_ALBUM_GAIN`,description:`EBU R128 album loudness gain (RFC 7845), raw wire value: signed Q7.8 integer (dB x 256). readTags() converts to a decibel number`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`,`ASF`],mappings:{id3v2:{frame:`TXXX`,description:`R128_ALBUM_GAIN`},vorbis:`R128_ALBUM_GAIN`,mp4:`----:com.apple.iTunes:R128_ALBUM_GAIN`}},acoustidFingerprint:{key:`ACOUSTID_FINGERPRINT`,description:`AcoustID fingerprint (Chromaprint)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TXXX`,description:`Acoustid Fingerprint`},vorbis:`ACOUSTID_FINGERPRINT`,mp4:`----:com.apple.iTunes:Acoustid Fingerprint`}},acoustidId:{key:`ACOUSTID_ID`,description:`AcoustID UUID`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TXXX`,description:`Acoustid Id`},vorbis:`ACOUSTID_ID`,mp4:`----:com.apple.iTunes:Acoustid Id`}},appleSoundCheck:{key:`ITUNNORM`,description:`Apple Sound Check normalization data`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TXXX`,description:`iTunNORM`},vorbis:`ITUNNORM`,mp4:`----:com.apple.iTunes:iTunNORM`}},appleGaplessInfo:{key:`ITUNSMPB`,description:`Apple gapless playback data (encoder delay and padding)`,type:`string`,supportedFormats:[`ID3v2`,`MP4`,`Vorbis`],mappings:{id3v2:{frame:`TXXX`,description:`iTunSMPB`},vorbis:`ITUNSMPB`,mp4:`----:com.apple.iTunes:iTunSMPB`}}}}));function toTagLibKey(key){return _toTagLib[key]??key}function mp4AtomWireKey(atom){return _mp4AtomToWireKey[atom]}function mp4FreeformAtomNames(wireKeys){const names=[];for(const key of wireKeys){const atom=_mp4FreeformAtoms[key];if(atom!==void 0)names.push(atom)}return names}function fromTagLibKey(key){return _fromTagLib[key]??key}function remapKeysFromTagLib(obj){const result={};for(const[key,value]of Object.entries(obj)){const canonical=READ_ALIASES[key];if(canonical!==void 0&&canonical in obj)continue;result[fromTagLibKey(key)]=value}return result}var PROPERTIES,_toTagLib,_fromTagLib,READ_ALIASES,_mp4FreeformAtoms,_mp4AtomToWireKey;var init_properties=__esmMin((()=>{init_additional_properties();init_basic_properties();init_general_extended_properties();init_specialized_properties();PROPERTIES={...BASIC_PROPERTIES,...GENERAL_EXTENDED_PROPERTIES,...SPECIALIZED_PROPERTIES,...ADDITIONAL_PROPERTIES};_toTagLib={};_fromTagLib={};for(const[camelKey,meta]of Object.entries(PROPERTIES)){const wireKey=meta.key;_toTagLib[camelKey]=wireKey;_fromTagLib[wireKey]=camelKey}_toTagLib[`year`]=`DATE`;_toTagLib[`track`]=`TRACKNUMBER`;_fromTagLib[`disc`]=`discNumber`;READ_ALIASES={"ALBUM ARTIST":`ALBUMARTIST`,ALBUM_ARTIST:`ALBUMARTIST`,ORGANIZATION:`LABEL`,PUBLISHER:`LABEL`,UPC:`BARCODE`,EAN:`BARCODE`,GTIN:`BARCODE`,TOTALTRACKS:`TRACKTOTAL`,TOTALDISCS:`DISCTOTAL`,MUSICBRAINZ_ALBUMTYPE:`RELEASETYPE`,"MusicBrainz Album Type":`RELEASETYPE`,MUSICBRAINZ_ALBUMSTATUS:`RELEASESTATUS`,"MusicBrainz Album Status":`RELEASESTATUS`,CONTENTADVISORY:`ITUNESADVISORY`,EXPLICIT:`ITUNESADVISORY`};for(const[alias,canonical]of Object.entries(READ_ALIASES))_fromTagLib[alias]??(_fromTagLib[alias]=_fromTagLib[canonical]);_mp4FreeformAtoms={};for(const meta of Object.values(PROPERTIES)){const{key,mappings}=meta;const atom=mappings?.mp4;if(typeof atom!==`string`||!atom.startsWith(`----:`))continue;const bare=atom.slice(atom.lastIndexOf(`:`)+1);if(bare===bare.toUpperCase())continue;_mp4FreeformAtoms[key]=atom;const readKey=bare.toUpperCase();const camel=_fromTagLib[key];if(camel!==void 0&&_fromTagLib[readKey]===void 0)_fromTagLib[readKey]=camel}_mp4AtomToWireKey={};for(const meta of Object.values(PROPERTIES)){const{key,mappings}=meta;const atom=mappings?.mp4;if(typeof atom!==`string`||atom.startsWith(`----:`))continue;_mp4AtomToWireKey[atom]??(_mp4AtomToWireKey[atom]=key)}}));var MP4_ITEM_NAMES_KEY;var init_mp4_item_names=__esmMin((()=>{MP4_ITEM_NAMES_KEY=`_mp4ItemNames`}));function buildGetters(state,handle){const tag={};for(const field of TAG_GETTER_FIELDS)Object.defineProperty(tag,field,{enumerable:true,configurable:true,get:()=>state.data[field]});Object.defineProperties(tag,{year:{enumerable:true,configurable:true,get:()=>state.data.year},track:{enumerable:true,configurable:true,get:()=>state.data.track},date:{enumerable:true,configurable:true,get:()=>handle.getProperty(`DATE`)||void 0}});return tag}function stageTrackWrite(handle,value){const existing=value>0?handle.getProperty(RAW_TRACK_WIRE_KEY):``;const slash=existing.indexOf(`/`);if(slash!==-1)handle.setProperty(RAW_TRACK_WIRE_KEY,`${value}${existing.slice(slash)}`);else handle.setTagData({track:value})}function stageDateWrite(handle,value){if(value===``)handle.setTagData({year:0});else handle.setProperty(`DATE`,value)}function buildMutableTag(handle){const state={data:handle.getTagData()};const tag=buildGetters(state,handle);const refresh=()=>{state.data=handle.getTagData();return tag};const setBasic=(field,value)=>{handle.setTagData({[field]:value});return refresh()};tag.setTitle=value=>setBasic(`title`,value);tag.setArtist=value=>setBasic(`artist`,value);tag.setAlbum=value=>setBasic(`album`,value);tag.setComment=value=>setBasic(`comment`,value);tag.setGenre=value=>setBasic(`genre`,value);tag.setYear=value=>setBasic(`year`,value);tag.setTrack=value=>{stageTrackWrite(handle,value);return refresh()};tag.setDate=value=>{stageDateWrite(handle,value);return refresh()};return tag}var RAW_TRACK_WIRE_KEY,TAG_GETTER_FIELDS;var init_mutable_tag_impl=__esmMin((()=>{init_properties();RAW_TRACK_WIRE_KEY=toTagLibKey(`trackNumber`);TAG_GETTER_FIELDS=[`title`,`artist`,`album`,`comment`,`genre`]}));function registerAutoDispose(target,handle){registry.register(target,handle,target)}function unregisterAutoDispose(target){registry.unregister(target)}var registry;var init_auto_dispose=__esmMin((()=>{registry=new FinalizationRegistry(handle=>{handle.destroy()})}));function _typeof(o){"@babel/helpers - typeof";return _typeof=`function`==typeof Symbol&&`symbol`==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&`function`==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?`symbol`:typeof o},_typeof(o)}var init_typeof=__esmMin((()=>{}));function toPrimitive(t,r){if(`object`!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||`default`);if(`object`!=_typeof(i))return i;throw new TypeError(`@@toPrimitive must return a primitive value.`)}return(`string`===r?String:Number)(t)}var init_toPrimitive=__esmMin((()=>{init_typeof()}));function toPropertyKey(t){var i=toPrimitive(t,`string`);return`symbol`==_typeof(i)?i:i+``}var init_toPropertyKey=__esmMin((()=>{init_typeof();init_toPrimitive()}));function _defineProperty(e,r,t){return(r=toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var init_defineProperty=__esmMin((()=>{init_toPropertyKey()}));var _Symbol$dispose,LYRICS_PROPERTY_KEY,LYRICS_WIRE_KEY,EMPTY_KEY_SET,BaseAudioFileImpl;var init_audio_file_base=__esmMin((()=>{init_mp4_freeform();init_properties();init_errors();init_mp4_item_names();init_mutable_tag_impl();init_auto_dispose();init_defineProperty();;LYRICS_PROPERTY_KEY=`lyrics`;LYRICS_WIRE_KEY=toTagLibKey(LYRICS_PROPERTY_KEY);EMPTY_KEY_SET=/* @__PURE__ */ new Set;_Symbol$dispose=Symbol.dispose;BaseAudioFileImpl=class{constructor(module,fileHandle,sourcePath,originalSource,isPartiallyLoaded=false,partialLoadOptions){this.module=module;_defineProperty(this,`fileHandle`,void 0);_defineProperty(this,`cachedAudioProperties`,null);_defineProperty(this,`sourcePath`,void 0);_defineProperty(this,`originalSource`,void 0);_defineProperty(this,`isPartiallyLoaded`,false);_defineProperty(this,`partialLoadOptions`,void 0);_defineProperty(this,`partialKeysAtLoad`,void 0);this.fileHandle=fileHandle;this.sourcePath=sourcePath;this.originalSource=originalSource;this.isPartiallyLoaded=isPartiallyLoaded;this.partialLoadOptions=partialLoadOptions;this.partialKeysAtLoad=isPartiallyLoaded?new Set(Object.keys(fileHandle.getProperties())):void 0;registerAutoDispose(this,fileHandle)}partialDeletedPropertyKeys(){if(!this.partialKeysAtLoad)return EMPTY_KEY_SET;const current=new Set(Object.keys(this.handle.getProperties()));const deleted=/* @__PURE__ */ new Set;for(const key of this.partialKeysAtLoad)if(key!==LYRICS_WIRE_KEY&&!current.has(key))deleted.add(key);return deleted}get handle(){if(!this.fileHandle)throw new MetadataError(`read`,`File handle has been disposed`);return this.fileHandle}getFormat(){return this.handle.getFormat()}isFormat(format){return this.getFormat()===format}tag(){return buildMutableTag(this.handle)}audioProperties(){this.cachedAudioProperties??(this.cachedAudioProperties=this.handle.getAudioProperties()??null);return this.cachedAudioProperties??void 0}properties(){const remapped=remapKeysFromTagLib(this.handle.getProperties());delete remapped[LYRICS_PROPERTY_KEY];return remapped}setProperties(properties){const translated={};for(const[key,values]of Object.entries(properties))if(values!==void 0){const wireKey=toTagLibKey(fromTagLibKey(key));const emptyTotal=(wireKey===`TRACKTOTAL`||wireKey===`DISCTOTAL`)&&values.every(v=>v===``);if(emptyTotal&&!this.module.isWasi)continue;translated[wireKey]=emptyTotal?[]:values}if(!(LYRICS_WIRE_KEY in translated)){const existing=this.handle.getProperties()[LYRICS_WIRE_KEY];if(existing!==void 0)translated[LYRICS_WIRE_KEY]=existing}const atomNames=mp4FreeformAtomNames(Object.keys(translated));if(atomNames.length>0)translated[MP4_ITEM_NAMES_KEY]=atomNames;this.handle.setProperties(translated)}getProperty(key){const wireKey=toTagLibKey(fromTagLibKey(key));const values=this.handle.getProperties()[wireKey]?.filter(v=>v!==``);if(values!==void 0&&values.length>0)return values;if(!this.isMP4())return void 0;const remapped=this.properties()[key]?.filter(v=>v!==``);return remapped!==void 0&&remapped.length>0?remapped:void 0}setProperty(key,value){const wireKey=toTagLibKey(fromTagLibKey(key));if((wireKey===`TRACKTOTAL`||wireKey===`DISCTOTAL`)&&value===``){this.clearTotal(wireKey);return}const nextValue=this.preserveIntPairTotal(wireKey,value);const atomNames=mp4FreeformAtomNames([wireKey]);if(atomNames.length>0&&this.isMP4()){this.writeMp4FreeformProperty(wireKey,value,atomNames);return}this.handle.setProperty(wireKey,nextValue)}clearTotal(wireKey){const rest={...this.handle.getProperties()};if(this.module.isWasi)rest[wireKey]=[];else delete rest[wireKey];this.handle.setProperties(rest)}preserveIntPairTotal(wireKey,value){if(wireKey!==`TRACKNUMBER`&&wireKey!==`DISCNUMBER`||value===``||value.includes(`/`))return value;const existing=this.handle.getProperty(wireKey);const slash=existing.indexOf(`/`);return slash===-1?value:`${value}${existing.slice(slash)}`}writeMp4FreeformProperty(wireKey,value,atomNames){if(value===``){const prior=this.handle.getMp4ItemRemovals?.()??[];this.handle.setMp4ItemRemovals?.([.../* @__PURE__ */ new Set([...prior,...atomNames])]);if(this.module.isWasi)this.handle.setProperties({...this.handle.getProperties(),[wireKey]:[]});else{const rest={...this.handle.getProperties()};delete rest[wireKey];this.handle.setProperties(rest)}return}this.handle.setProperties({...this.handle.getProperties(),[wireKey]:[value],[MP4_ITEM_NAMES_KEY]:[...atomNames]})}removeProperty(key){this.setProperty(key,``)}isMP4(){return this.handle.isMP4()}getMP4Item(key){if(!this.isMP4())throw new UnsupportedFormatError(this.getFormat(),[`MP4`,`M4A`]);const wireKey=mp4AtomWireKey(key);const value=wireKey!==void 0?this.handle.getProperty(wireKey):this.handle.getMP4Item(key);return value===``?void 0:value}setMP4Item(key,value){if(!this.isMP4())throw new UnsupportedFormatError(this.getFormat(),[`MP4`,`M4A`]);const wireKey=mp4AtomWireKey(key);if(wireKey!==void 0){this.handle.setProperty(wireKey,value);return}if(value===``){this.handle.removeMP4Item(key);return}this.handle.setMP4Item(key,value)}removeMP4Item(key){if(!this.isMP4())throw new UnsupportedFormatError(this.getFormat(),[`MP4`,`M4A`]);this.handle.removeMP4Item(key)}getMP4FreeformItems(){if(!this.isMP4())throw new UnsupportedFormatError(this.getFormat(),[`MP4`,`M4A`]);if(!this.handle.getMP4FreeformItems)throw new MetadataError(`read`,`MP4 freeform items are unavailable on this backend`);return this.handle.getMP4FreeformItems().map(fromRawFreeformItem)}setMP4FreeformItems(items){if(!this.isMP4())throw new UnsupportedFormatError(this.getFormat(),[`MP4`,`M4A`]);if(!this.handle.setMP4FreeformItems)throw new MetadataError(`write`,`MP4 freeform items are unavailable on this backend`);validateFreeformItems(items);this.handle.setMP4FreeformItems(items.map(toRawFreeformItem))}isValid(){return this.handle.isValid()}dispose(){unregisterAutoDispose(this);if(this.fileHandle){this.fileHandle.destroy();this.fileHandle=null;this.cachedAudioProperties=null}}[_Symbol$dispose](){this.dispose()}}}));function be32(b,offset){return(b[offset]<<24|b[offset+1]<<16|b[offset+2]<<8|b[offset+3])>>>0}function startsWith(bytes,magic,at=0){if(bytes.length<at+magic.length)return false;for(let i=0;i<magic.length;i++)if(bytes[at+i]!==magic.codePointAt(i))return false;return true}function id3v2End(bytes){if(!startsWith(bytes,`ID3`)||bytes.length<10)return void 0;const size=bytes[6]<<21|bytes[7]<<14|bytes[8]<<7|bytes[9];const hasFooter=(bytes[5]&16)!==0;return 10+size+(hasFooter?10:0)}function flacEnd(bytes,limit,start){let offset=start+4;for(;;){if(offset+4>bytes.length)return void 0;const isLast=(bytes[offset]&128)!==0;const length=bytes[offset+1]<<16|bytes[offset+2]<<8|bytes[offset+3];offset+=4+length;if(offset>limit)return offset;if(isLast)return offset}}function flacMarkerOffset(bytes){const at=startsWith(bytes,`ID3`)?id3v2End(bytes):0;if(at===void 0)return void 0;return startsWith(bytes,`fLaC`,at)?at:void 0}function flacAudioStart(bytes){const at=flacMarkerOffset(bytes);if(at===void 0)return void 0;return flacEnd(bytes,bytes.length,at)}function mp4MoovEnd(bytes,limit,start){let offset=start;const readable=Math.min(bytes.length,limit);while(offset+8<=readable){const size=be32(bytes,offset);const type=String.fromCodePoint(bytes[offset+4],bytes[offset+5],bytes[offset+6],bytes[offset+7]);if(size<8)return void 0;if(type===`moov`)return offset+size;offset+=size}}function oggMetadataEnd(bytes,limit,start){let offset=start;let packetsCompleted=0;let first=true;for(;;){if(offset+27>bytes.length||!startsWith(bytes,`OggS`,offset))return;const segmentCount=bytes[offset+26];const tableStart=offset+27;if(tableStart+segmentCount>bytes.length)return void 0;let payload=0;for(let i=0;i<segmentCount;i++){const segment=bytes[tableStart+i];payload+=segment;if(segment<255)packetsCompleted++}if(first){const payloadStart=tableStart+segmentCount;if(payloadStart+5>bytes.length)return void 0;if(bytes[payloadStart]===127&&startsWith(bytes,`FLAC`,payloadStart+1))return;first=false}offset=tableStart+segmentCount+payload;if(packetsCompleted>=2||offset>limit)return offset}}function parseMpegFrameHeader(bytes,at){if(bytes.length<at+4)return void 0;if(bytes[at]!==255||(bytes[at+1]&224)!==224)return void 0;const version=bytes[at+1]>>3&3;const layer=bytes[at+1]>>1&3;if(version===1||layer===0)return void 0;const bitrateIndex=bytes[at+2]>>4&15;const sampleRateIndex=bytes[at+2]>>2&3;if(bitrateIndex===0||bitrateIndex===15||sampleRateIndex===3)return;let sampleRateTable=2;if(version===3)sampleRateTable=0;else if(version===2)sampleRateTable=1;return{mpeg1:version===3,layerIndex:layer^3,bitrateIndex,sampleRateIndex,sampleRateTable}}function mpegFrameLength(bytes,at){const header=parseMpegFrameHeader(bytes,at);if(!header)return 0;const{mpeg1,layerIndex,bitrateIndex,sampleRateIndex,sampleRateTable}=header;const bitrate=MPEG_BITRATES[mpeg1?0:1][layerIndex][bitrateIndex];const sampleRate=MPEG_SAMPLE_RATES[sampleRateTable][sampleRateIndex];let samplesPerFrame;if(layerIndex===2)samplesPerFrame=mpeg1?1152:576;else if(layerIndex===1)samplesPerFrame=1152;else samplesPerFrame=384;let frameLength=Math.floor(samplesPerFrame*bitrate*125/sampleRate);if((bytes[at+2]&2)!==0)frameLength+=layerIndex===0?4:1;return frameLength===0?0:frameLength}function isMpegFrameSync(bytes,at=0){const frameLength=mpegFrameLength(bytes,at);if(frameLength===0)return false;const next=at+frameLength;if(bytes.length<next+4)return false;const mask=4294839296;return((bytes[at]<<24|bytes[at+1]<<16|bytes[at+2]<<8|bytes[at+3])>>>0&mask)>>>0===((bytes[next]<<24|bytes[next+1]<<16|bytes[next+2]<<8|bytes[next+3])>>>0&mask)>>>0}function containerEnd(bytes,at,limit){if(at>=bytes.length)return bytes.length<limit?null:void 0;if(at+8>bytes.length)return void 0;if(startsWith(bytes,`fLaC`,at))return flacEnd(bytes,limit,at);if(startsWith(bytes,`ftyp`,at+4))return mp4MoovEnd(bytes,limit,at);if(startsWith(bytes,`OggS`,at))return oggMetadataEnd(bytes,limit,at);return null}function id3MetadataEnd(header,limit){const tagEnd=id3v2End(header);if(tagEnd===void 0)return void 0;if(tagEnd>limit)return tagEnd;const behind=containerEnd(header,tagEnd,limit);if(behind===void 0)return void 0;return behind??tagEnd}function headerMetadataEnd(header,limit){if(startsWith(header,`ID3`))return id3MetadataEnd(header,limit);const container=containerEnd(header,0,limit);if(container!==null)return container;return isMpegFrameSync(header)?0:void 0}function metadataFitsInHeader(header,limit){const end=headerMetadataEnd(header,limit);if(end===void 0||end>header.length)return false;return end<=limit}function apeFooterSize(tail,at){if(at<0||!startsWith(tail,`APETAGEX`,at))return void 0;return(tail[at+12]|tail[at+13]<<8|tail[at+14]<<16|tail[at+15]<<24)>>>0}function trailerFitsInFooter(tail,footerSize){if(tail.length<Math.min(footerSize,32))return false;for(const offsetFromEnd of[32,160]){const size=apeFooterSize(tail,tail.length-offsetFromEnd);if(size===void 0)continue;const trailing=offsetFromEnd===32?0:128;if(size+32+trailing>footerSize)return false}return true}var MPEG_BITRATES,MPEG_SAMPLE_RATES;var init_metadata_extent=__esmMin((()=>{MPEG_BITRATES=[[[0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,0],[0,32,48,56,64,80,96,112,128,160,192,224,256,320,384,0],[0,32,40,48,56,64,80,96,112,128,160,192,224,256,320,0]],[[0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,0],[0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,0],[0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,0]]];MPEG_SAMPLE_RATES=[[44100,48e3,32e3],[22050,24e3,16e3],[11025,12e3,8e3]]}));function adtsFrameLength(bytes,at){if(bytes.length<at+7)return 0;if(bytes[at]!==255||(bytes[at+1]&246)!==240)return 0;const length=(bytes[at+3]&3)<<11|bytes[at+4]<<3|bytes[at+5]>>5;return length>=7?length:0}function trailingTagStart(bytes,end=bytes.length){const view=new DataView(bytes.buffer,bytes.byteOffset,bytes.byteLength);let at=Math.max(0,Math.min(end,bytes.length));for(;;){if(at>=128&&text(bytes,at-128,3)===`TAG`){at-=128;continue}if(at>=32&&text(bytes,at-32,8)===`APETAGEX`){const size=view.getUint32(at-32+12,true);const flags=view.getUint32(at-32+20,true);const start=at-size-((flags&2147483648)!==0?32:0);if(start<0||start>=at)return at;at=start;continue}return at}}function firstFrame(bytes){const from=id3v2End(bytes)??0;const limit=Math.min(bytes.length-6,from+MPEG_SCAN_LIMIT);for(let o=from;o<limit;o++){const len=frameLengthAt(bytes,o);if(len>0&&frameLengthAt(bytes,o+len)>0)return o}return-1}function forwardLastFrame(bytes,from,end){let o=from;let start=-1;let length=0;let frames=0;while(o+6<=end){const len=frameLengthAt(bytes,o);if(len===0||o+len>end)break;start=o;length=len;frames++;o+=len}return{start,length,frames}}function walkMpeg(bytes){const from=firstFrame(bytes);if(from<0)return fallback(`no valid first frame`);const last=forwardLastFrame(bytes,from,trailingTagStart(bytes));if(last.start<0)return fallback(`no valid frames`);return{kind:`ranges`,ranges:[{offset:from,length:last.start+last.length-from}],detail:`first=${from} last=${last.start}+${last.length} frames=${last.frames}`}}function flacStreamInfoMd5(bytes){const marker=flacMarkerOffset(bytes);if(marker===void 0)return void 0;const header=marker+4;if(header+4>bytes.length)return void 0;if((bytes[header]&127)!==0)return void 0;if((bytes[header+1]<<16|bytes[header+2]<<8|bytes[header+3])<34)return void 0;const payload=header+4;if(payload+34>bytes.length)return void 0;let hex=``;for(const byte of bytes.subarray(payload+18,payload+34))hex+=byte.toString(16).padStart(2,`0`);return hex}function walkFlac(bytes){const start=flacAudioStart(bytes);if(start===void 0)return fallback(`no fLaC marker`);const end=trailingTagStart(bytes);if(end<=start)return fallback(`no audio bytes`);return{kind:`ranges`,ranges:[{offset:start,length:end-start}],detail:`audioStart=${start} end=${end}`}}function atomLength(bytes,view,o){const size=view.getUint32(o,false);if(size===0)return{length:bytes.length-o,headerSize:8};if(size===1){if(o+16>bytes.length)return void 0;const big=view.getBigUint64(o+8,false);if(big>BigInt(Number.MAX_SAFE_INTEGER))return void 0;return{length:Number(big),headerSize:16}}return{length:size,headerSize:8}}function walkMp4(bytes){const view=new DataView(bytes.buffer,bytes.byteOffset,bytes.byteLength);const ranges=[];let o=0;while(o+8<=bytes.length){const type=text(bytes,o+4,4);const atom=atomLength(bytes,view,o);if(atom===void 0)return fallback(`malformed ${type} size`);if(atom.length<atom.headerSize)return fallback(`malformed ${type} size`);if(o+atom.length>bytes.length)return fallback(`oversized ${type}`);if(type===`mdat`&&atom.length>atom.headerSize)ranges.push({offset:o+atom.headerSize,length:atom.length-atom.headerSize});o+=atom.length}if(o!==bytes.length)return fallback(`trailing bytes after the last atom`);if(ranges.length===0)return fallback(`no non-empty mdat`);return{kind:`ranges`,ranges,detail:`${ranges.length} mdat(s)`}}function walkWav(bytes){const view=new DataView(bytes.buffer,bytes.byteOffset,bytes.byteLength);if(text(bytes,0,4)!==`RIFF`)return fallback(`not RIFF`);if(text(bytes,8,4)!==`WAVE`)return fallback(`not WAVE`);const ranges=[];let o=12;while(o+8<=bytes.length){const id=text(bytes,o,4);const size=view.getUint32(o+4,true);const dataStart=o+8;if(dataStart+size>bytes.length)return fallback(`truncated ${id}`);if(id===`data`&&size>0)ranges.push({offset:dataStart,length:size});o=dataStart+size+size%2}if(ranges.length===0)return fallback(`no data chunk`);return{kind:`ranges`,ranges,detail:`${ranges.length} data chunk(s)`}}function mediaRanges(format,bytes){const walked=(()=>{switch(format.toUpperCase()){case`MP3`:case`AAC`:return walkMpeg(bytes);case`FLAC`:return walkFlac(bytes);case`MP4`:case`M4A`:return walkMp4(bytes);case`WAV`:return walkWav(bytes);default:return{kind:`fallback`,ranges:[],detail:`format not covered`}}})();if(walked.kind===`fallback`)return{kind:`fallback`,ranges:[{offset:0,length:bytes.length}],detail:`${walked.detail} → whole file`};return walked}var decoder,text,fallback,frameLengthAt,MPEG_SCAN_LIMIT;var init_media_ranges=__esmMin((()=>{init_metadata_extent();decoder=new TextDecoder;text=(b,o,n)=>decoder.decode(b.subarray(o,o+n));fallback=detail=>({kind:`fallback`,ranges:[],detail});frameLengthAt=(bytes,at)=>mpegFrameLength(bytes,at)||adtsFrameLength(bytes,at);MPEG_SCAN_LIMIT=65536}));async function fileBytes(source,io){if(source.path)return await io.readFile(source.path);if(source.blob)return new Uint8Array(await source.blob.arrayBuffer());if(!source.partiallyLoaded&&source.bytes.length>0)return source.bytes;throw new MetadataError(`read`,`the handle holds no file bytes and has no readable source; a partial handle that has been saved drops its source — checksum the saved path instead`)}function joinRanges(bytes,ranges){const total=ranges.reduce((n,r)=>n+r.length,0);const overrun=ranges.find(r=>r.offset+r.length>bytes.length);if(overrun||total>bytes.length)throw new MetadataError(`read`,`range walk overran the buffer (${overrun?`range ${overrun.offset}+${overrun.length}`:`${total} bytes`} past the ${bytes.length}-byte buffer)`);if(ranges.length===1){const only=ranges[0];const view=bytes.subarray(only.offset,only.offset+only.length);return view.buffer instanceof ArrayBuffer?view:new Uint8Array(view)}const out=new Uint8Array(total);let at=0;for(const r of ranges){out.set(bytes.subarray(r.offset,r.offset+r.length),at);at+=r.length}return out}async function pcmChecksum(source,format,io){if(format.toUpperCase()!==`FLAC`)throw new UnsupportedFormatError(format,[`FLAC`],{operation:`media checksum (basis: pcm)`});let windowed;if(source.bytes.length>0)windowed=source.bytes;else if(source.path&&io.readPartial)windowed=await io.readPartial(source.path,STREAMINFO_WINDOW,0);let md5=windowed===void 0?void 0:flacStreamInfoMd5(windowed);if(md5===void 0&&windowed!==source.bytes)md5=flacStreamInfoMd5(await fileBytes(source,io));if(md5===void 0)throw new MetadataError(`read`,`STREAMINFO digest unavailable`);return{source:`flac-streaminfo-md5`,algorithm:`md5`,hex:md5,bytesHashed:16}}async function mediaChecksum(source,format,io,options={}){if(options.basis===`pcm`)return pcmChecksum(source,format,io);const bytes=await fileBytes(source,io);const walk=mediaRanges(format,bytes);const payload=joinRanges(bytes,walk.ranges);const digest=new Uint8Array(await crypto.subtle.digest(`SHA-256`,payload));let hex=``;for(const byte of digest)hex+=byte.toString(16).padStart(2,`0`);return{source:walk.kind===`ranges`?`audio-payload`:`file`,algorithm:`sha256`,hex,bytesHashed:payload.length}}var STREAMINFO_WINDOW;var init_audio_file_checksum=__esmMin((()=>{init_media_ranges();init_errors();STREAMINFO_WINDOW=65536}));async function readFileData(file){if(file instanceof Uint8Array)return file;if(file instanceof ArrayBuffer)return new Uint8Array(file);if(typeof File!==`undefined`&&file instanceof File)return new Uint8Array(await file.arrayBuffer());if(typeof file===`string`)try{return await getPlatformIO().readFile(file)}catch(error){if(error instanceof EnvironmentError)throw error;throw new FileOperationError(`read`,error.message,file)}const inputType=Object.prototype.toString.call(file);throw new FileOperationError(`read`,`Invalid file input type: ${inputType}. Expected string path, Uint8Array, ArrayBuffer, or File object.`)}async function getFileSize(path){try{return(await getPlatformIO().stat(path)).size}catch(error){if(error instanceof EnvironmentError)throw error;throw new FileOperationError(`stat`,error.message,path)}}async function readPartialFileData(path,headerSize,footerSize){const io=getPlatformIO();if(!io.readPartial)throw new EnvironmentError(`current runtime`,`does not support partial file reading`,`filesystem access with seek support`);try{return await io.readPartial(path,headerSize,footerSize)}catch(error){if(error instanceof EnvironmentError)throw error;throw new FileOperationError(`read`,error.message,path)}}var init_file=__esmMin((()=>{init_errors();init__taglib_platform_io_stub()}));function isValidBitrateMode(value){return value===`CBR`||value===`VBR`||value===`ABR`}function wrapEmbindHandle(raw){const stagedId3v2Frames={};let destroyed=false;const overrides={getTagData(){const tw=raw.getTag();return{title:tw.title(),artist:tw.artist(),album:tw.album(),comment:tw.comment(),genre:tw.genre(),year:tw.year(),track:tw.track()}},setTagData(data){const tw=raw.getTag();if(data.title!==void 0)tw.setTitle(data.title);if(data.artist!==void 0)tw.setArtist(data.artist);if(data.album!==void 0)tw.setAlbum(data.album);if(data.comment!==void 0)tw.setComment(data.comment);if(data.genre!==void 0)tw.setGenre(data.genre);if(data.year!==void 0)tw.setYear(data.year);if(data.track!==void 0)tw.setTrack(data.track)},getBextData(){const v=raw.getBextData();if(v===void 0||v===null)return void 0;const u8=v instanceof Uint8Array?v:new Uint8Array(v);return u8.length>0?u8:void 0},setBextData(data){raw.setBextData(data??null)},getIxml(){const v=raw.getIxml();return typeof v===`string`&&v.length>0?v:void 0},setIxml(data){raw.setIxml(data??null)},getLyrics(){return(raw.getProperties()[`LYRICS`]??[]).map(text=>({text,description:``,language:``}))},setLyrics(lyrics){const handle=raw;const props=handle.getProperties();if(lyrics.length>0)props[`LYRICS`]=lyrics.map(l=>l.text);else delete props[`LYRICS`];handle.setProperties(props)},setId3v2Frames(id,data){stagedId3v2Frames[id]=data.map(d=>new Uint8Array(d));raw.setId3v2Frames(id,data)},removeId3v2Frames(id){stagedId3v2Frames[id]=[];raw.removeId3v2Frames(id)},getStagedId3v2Frames(){return Object.keys(stagedId3v2Frames).length>0?{...stagedId3v2Frames}:void 0},hasId3Tags(){const v=raw.hasId3Tags();if(!v||typeof v!==`object`)return{v1:false,v2:false};const o=v;return{v1:o.v1===true,v2:o.v2===true}},stripId3Tags(opts){raw.stripId3Tags(opts)},destroy(){if(destroyed)return;destroyed=true;raw.destroy()},get destroyed(){return destroyed},setMp4ItemRemovals(removals){const handle=raw;for(const name of removals)handle.removeMP4Item(name)},getMP4FreeformItems(){return raw.getMP4FreeformItems()},setMP4FreeformItems(items){raw.setMP4FreeformItems(items)},getAudioProperties(){const pw=raw.getAudioProperties();if(!pw)return null;const containerFormat=pw.containerFormat()||`unknown`;const codec=pw.codec()||`unknown`;const mpegVersion=pw.mpegVersion();const formatVersion=pw.formatVersion();const bitrateMode=pw.bitrateMode();const isEncrypted=pw.isEncrypted();return{duration:pw.lengthInSeconds(),durationMs:pw.lengthInMilliseconds(),bitrate:pw.bitrate(),sampleRate:pw.sampleRate(),channels:pw.channels(),bitsPerSample:pw.bitsPerSample(),codec,containerFormat,isLossless:pw.isLossless(),...mpegVersion>0?{mpegVersion,mpegLayer:pw.mpegLayer()}:{},...isEncrypted||containerFormat===`MP4`||containerFormat===`ASF`?{isEncrypted}:{},...formatVersion>0?{formatVersion}:{},...isValidBitrateMode(bitrateMode)?{bitrateMode}:{},...containerFormat===`OGG`&&codec===`Opus`?{outputGainDb:pw.outputGainDb()}:{}}}};return new Proxy(raw,{get(target,prop,receiver){if(prop in overrides)return overrides[prop];const value=Reflect.get(target,prop,receiver);return typeof value===`function`?value.bind(target):value}})}var init_embind_adapter=__esmMin((()=>{}));function chapterStyle(chapters){const s=chapters[0]?.source;return s===`nero`||s===`both`?s:`quicktime`}function freeformSignature(items){return items.map(item=>`${item.mean}\u0000${item.name}\u0000${item.type}\u0000`+Array.from(item.value).join(`,`)).sort((a,b)=>a.localeCompare(b)).join(`
|
|
2
|
+
`)}function copyExtraState(target,source,sourceComplete){for(const field of EXTRA_FIELDS)field.copy(target,source,sourceComplete)}var EXTRA_FIELDS;var init_extra_state_registry=__esmMin((()=>{EXTRA_FIELDS=[{name:`pictures`,copy(target,source,complete){const v=source.getPictures();if(complete||v.length>0)target.setPictures(v)}},{name:`ratings`,copy(target,source,complete){const v=source.getRatings();if(complete||v.length>0)target.setRatings(v)}},{name:`lyrics`,copy(target,source,complete){const v=source.getLyrics();if(complete||v.length>0)target.setLyrics(v)}},{name:`chapters`,copy(target,source,complete){const v=source.getChapters();if(complete||v.length>0)target.setChapters(v,chapterStyle(v))}},{name:`bextData`,copy(target,source,complete){const v=source.getBextData();if(v!==void 0)target.setBextData(v);else if(complete)target.setBextData(null)}},{name:`ixml`,copy(target,source,complete){const v=source.getIxml();if(v!==void 0)target.setIxml(v);else if(complete)target.setIxml(null)}},{name:`_mp4Freeform`,copy(target,source,complete){const items=source.getMP4FreeformItems?.();if(items===void 0)return;if(!complete&&items.length===0)return;const targetItems=target.getMP4FreeformItems?.()??[];if(freeformSignature(items)===freeformSignature(targetItems))return;target.setMP4FreeformItems?.(items)}},{name:`_mp4ItemRemovals`,copy(target,source,complete){const v=source.getMp4ItemRemovals?.();if(complete||v!==void 0&&v.length>0)target.setMp4ItemRemovals?.(v??[])}},{name:`id3v2Frames`,copy(target,source){const staged=source.getStagedId3v2Frames?.();if(!staged)return;for(const[id,bodies]of Object.entries(staged))target.setId3v2Frames(id,bodies)}}]}));function copyEditedState(target,source,sourceComplete,deletedKeys){target.setTagData(source.getTagData());const merged=sourceComplete?source.getProperties():{...target.getProperties(),...source.getProperties()};for(const key of deletedKeys)delete merged[key];const atomNames=mp4FreeformAtomNames(Object.keys(merged));if(atomNames.length>0)merged[MP4_ITEM_NAMES_KEY]=atomNames;target.setProperties(merged);copyExtraState(target,source,sourceComplete)}async function saveViaFreshHandle(module,editing,source,targetPath,sourceComplete,deletedKeys=/* @__PURE__ */ new Set){const rawFullHandle=module.createFileHandle();const fullFileHandle=module.isWasi?rawFullHandle:wrapEmbindHandle(rawFullHandle);try{{const data=await readFileData(source);if(!fullFileHandle.loadFromBuffer(data))throw new InvalidFormatError(`Failed to load full audio file for saving`)}copyEditedState(fullFileHandle,editing,sourceComplete,deletedKeys);if(!fullFileHandle.save())throw new FileOperationError(`save`,`Failed to save changes to full file`);await writeFileData(targetPath,fullFileHandle.getBuffer())}finally{fullFileHandle.destroy()}}var init_save_reconstruct=__esmMin((()=>{init_errors();init_file();init_write();init_embind_adapter();init_extra_state_registry();init_properties();init_mp4_item_names()}));function sortChapters(list){return[...list].sort((a,b)=>a.startTimeMs-b.startTimeMs)}function inferEndTimeMs(sorted,index,trackEndMs){const own=sorted[index].endTimeMs;if(own!==void 0)return own;const next=sorted[index+1];return next?next.startTimeMs:trackEndMs}function readFileSync(path){if(isDeno())return Deno.readFileSync(path);const fs=getNodeFsSync();if(fs)return new Uint8Array(fs.readFileSync(path));throw new FileOperationError(`read`,`node:fs is unavailable in this runtime: cannot read file data from disk`,path)}var AudioFileImpl;var init_audio_file_impl=__esmMin((()=>{init_types();init_audio_file_bwf();init_id3v2_frames();init_errors();init_write();init__taglib_node_fs_stub();init_rating();init_detector();init_audio_file_base();init_audio_file_checksum();init__taglib_platform_io_stub();init_save_reconstruct();init_defineProperty();AudioFileImpl=class extends BaseAudioFileImpl{constructor(module,fileHandle,sourcePath,originalSource,isPartiallyLoaded=false,partialLoadOptions){super(module,fileHandle,sourcePath,originalSource,isPartiallyLoaded,partialLoadOptions);_defineProperty(this,`pathModeBuffer`,null);_defineProperty(this,`partiallyLoadedAtConstruction`,void 0);this.partiallyLoadedAtConstruction=isPartiallyLoaded}save(){if(this.isPartiallyLoaded&&this.originalSource)throw new FileOperationError(`save`,`Cannot save partially loaded file directly. Use saveToFile() instead`);this.cachedAudioProperties=null;this.pathModeBuffer=null;return this.handle.save()}getFileBuffer(){const buffer=this.handle.getBuffer();if(buffer.length>0)return buffer;if(this.pathModeBuffer)return this.pathModeBuffer;if(this.sourcePath)try{this.pathModeBuffer=readFileSync(this.sourcePath);return this.pathModeBuffer}catch(error){if(error instanceof FileOperationError)throw error;throw new FileOperationError(`read`,`Cannot return file data: ${errorMessage(error)}`,this.sourcePath,{cause:error})}throw new FileOperationError(`read`,`No file data available: in-memory buffer is empty and no source path is set`)}mediaChecksum(options){return mediaChecksum({bytes:this.handle.getBuffer(),...this.sourcePath!==void 0?{path:this.sourcePath}:{},...this.originalSource instanceof Blob?{blob:this.originalSource}:{},partiallyLoaded:this.partiallyLoadedAtConstruction},this.getFormat(),getPlatformIO(),options)}async saveToFile(path){const targetPath=path??this.sourcePath;if(!targetPath)throw new FileOperationError(`save`,`No file path available. Provide a path or open the file from a path`);if(this.isPartiallyLoaded&&this.originalSource){await saveViaFreshHandle(this.module,this.handle,this.originalSource,targetPath,false,this.partialDeletedPropertyKeys());this.isPartiallyLoaded=false;this.originalSource=void 0}else if(this.module.isWasi&&this.sourcePath&&targetPath!==this.sourcePath)await saveViaFreshHandle(this.module,this.handle,this.sourcePath,targetPath,true);else{if(!this.save())throw new FileOperationError(`save`,`Failed to save changes to in-memory buffer`);const buffer=this.handle.getBuffer();if(buffer.length>0)await writeFileData(targetPath,buffer)}this.pathModeBuffer=null}getPictures(){return this.handle.getPictures().map(pic=>({mimeType:pic.mimeType,data:pic.data,type:PICTURE_TYPE_NAMES[pic.type]??`Other`,...pic.description!==void 0?{description:pic.description}:{}}))}setPictures(pictures){this.handle.setPictures(pictures.map(pic=>({mimeType:pic.mimeType,data:pic.data,type:PICTURE_TYPE_VALUES[pic.type]??0,description:pic.description??``})))}addPicture(picture){this.handle.addPicture({mimeType:picture.mimeType,data:picture.data,type:PICTURE_TYPE_VALUES[picture.type]??0,description:picture.description??``})}removePictures(){this.handle.removePictures()}getChapters(){const sorted=sortChapters(this.handle.getChapters());const trackEndMs=this.audioProperties()?.durationMs;return sorted.map((c,i)=>{const endTimeMs=inferEndTimeMs(sorted,i,trackEndMs);return{startTimeMs:c.startTimeMs,...endTimeMs!==void 0?{endTimeMs}:{},...c.title?{title:c.title}:{},...c.id?{id:c.id}:{},...c.source!==void 0?{source:c.source}:{}}})}setChapters(chapters,options){const fmt=this.getFormat();if(fmt!==`MP3`&&fmt!==`AAC`&&fmt!==`MP4`)throw new UnsupportedFormatError(fmt,[`MP3`,`AAC`,`MP4`],{operation:`setChapters`});const sorted=sortChapters(chapters);const trackEndMs=this.audioProperties()?.durationMs;const style=options?.mp4ChapterStyle??`quicktime`;const source=fmt===`MP4`?style:`id3`;const raw=sorted.map((c,i)=>({...c.id!==void 0?{id:c.id}:{},startTimeMs:c.startTimeMs,endTimeMs:inferEndTimeMs(sorted,i,trackEndMs)??c.startTimeMs,...c.title!==void 0?{title:c.title}:{},source}));this.handle.setChapters(raw,style)}getBext(){return getBext(this.handle)}setBext(bext){setBext(this.handle,this.getFormat(),bext)}getBextData(){return getBextData(this.handle)}setBextData(data){setBextData(this.handle,this.getFormat(),data)}getIxml(){return getIxml(this.handle)}setIxml(data){setIxml(this.handle,this.getFormat(),data)}getRatings(){return this.handle.getRatings().map(r=>({rating:r.rating,...r.email!==void 0&&r.email!==``?{email:r.email}:{},...r.counter!==0?{counter:r.counter}:{}}))}setRatings(ratings){this.handle.setRatings(ratings.map(r=>({rating:r.rating,email:r.email??``,counter:r.counter??0})))}getLyrics(){return this.handle.getLyrics().map(l=>{const out={text:l.text};if(l.description)out.description=l.description;if(l.language)out.language=l.language;return out})}setLyrics(lyrics){this.handle.setLyrics(lyrics.map(l=>({text:l.text,description:l.description??``,language:l.language??``})))}getRating(){const ratings=this.getRatings();return ratings.length>0?normalized(ratings[0].rating):void 0}setRating(rating,email){this.setRatings([{rating,...email!==void 0?{email}:{},counter:0}])}getId3v2Frames(id){assertMp3(this.getFormat());if(id!==void 0)assertFrameId(id,`read`);return this.handle.getId3v2Frames(id??``).map(toPublicFrame)}setId3v2Frames(id,data){assertMp3(this.getFormat());assertFrameId(id,`write`);assertFrameBodies(id,data);this.handle.setId3v2Frames(id,data)}removeId3v2Frames(id){assertMp3(this.getFormat());assertFrameId(id,`write`);this.handle.removeId3v2Frames(id)}hasId3Tags(){return this.handle.hasId3Tags()}stripId3Tags(opts){this.handle.stripId3Tags({v1:opts?.v1??true,v2:opts?.v2??true})}}}));async function loadFull(input){return{data:await readFileData(input),isPartiallyLoaded:false}}async function loadPartialFile(input,opts){const headerSize=Math.min(opts.maxHeaderSize,input.size);const footerSize=Math.min(opts.maxFooterSize,input.size);if(input.size<=headerSize+footerSize)return loadFull(input);const header=new Uint8Array(await input.slice(0,headerSize).arrayBuffer());if(!metadataFitsInHeader(header,headerSize))return loadFull(input);const footerStart=Math.max(0,input.size-footerSize);const footer=new Uint8Array(await input.slice(footerStart).arrayBuffer());if(!trailerFitsInFooter(footer,footerSize))return loadFull(input);const combined=new Uint8Array(header.byteLength+footer.byteLength);combined.set(header,0);combined.set(footer,header.byteLength);return{data:combined,isPartiallyLoaded:true}}async function loadPartialPath(input,opts){if(await getFileSize(input)>opts.maxHeaderSize+opts.maxFooterSize){const data=await readPartialFileData(input,opts.maxHeaderSize,opts.maxFooterSize);if(metadataFitsInHeader(data,opts.maxHeaderSize)&&trailerFitsInFooter(data,opts.maxFooterSize))return{data,isPartiallyLoaded:true}}return loadFull(input)}async function loadAudioData(input,opts){if(!opts.partial)return loadFull(input);if(typeof File!==`undefined`&&input instanceof File)return loadPartialFile(input,opts);if(typeof input===`string`)return loadPartialPath(input,opts);return loadFull(input)}var init_load_audio_data=__esmMin((()=>{init_file();init_metadata_extent()}));function mergeTagUpdatesInto(currentProps,tags){const newProps=normalizeTagInput(tags);reconcilePairFields(currentProps,newProps,tags);if(newProps.date!==void 0||newProps.year!==void 0)currentProps.YEAR=[];return{...currentProps,...newProps}}function mergeTagUpdates(file,tags){file.setProperties(mergeTagUpdatesInto(file.properties(),tags))}function reconcilePairFields(currentProps,newProps,input){for(const[rawKey,totalKey,numericKey]of[[`trackNumber`,`totalTracks`,`track`],[`discNumber`,`totalDiscs`,`discNumber`]]){const incoming=newProps[rawKey]?.[0];if(incoming?.includes(`/`)){newProps[totalKey]=[];continue}if(!(input[numericKey]!==void 0&&input[rawKey]===void 0)||incoming===void 0)continue;const existing=currentProps[rawKey]?.[0];const slash=existing?.indexOf(`/`)??-1;if(existing!==void 0&&slash!==-1)newProps[rawKey]=[`${incoming}${existing.slice(slash)}`]}}function normalizeTagInput(input){const props={};for(const field of[`title`,`artist`,`album`,`comment`,`genre`]){const val=input[field];if(val===void 0)continue;props[field]=Array.isArray(val)?val:[val]}if(input.year!==void 0)props.date=[String(input.year)];if(input.date!==void 0)props.date=Array.isArray(input.date)?input.date:[input.date];if(input.track!==void 0)props.trackNumber=[String(input.track)];if(input.trackNumber!==void 0)props.trackNumber=Array.isArray(input.trackNumber)?input.trackNumber:[input.trackNumber];for(const[field,val]of Object.entries(input)){if(BASIC_FIELDS.has(field)||val===void 0)continue;if(field===`extraProperties`)continue;if(field===`compilation`)props[field]=[val?`1`:`0`];else if(field===`advisory`){if(val===`explicit`)props.itunesAdvisory=[`1`];else if(val===`clean`)props.itunesAdvisory=[`2`];else if(val===`unspecified`)props.itunesAdvisory=[]}else if(field===`bpm`)props[field]=[String(Math.trunc(val))];else if(NUMERIC_FIELDS.has(field))props[field]=[String(val)];else if(field===`r128TrackGain`||field===`r128AlbumGain`)props[field]=Array.isArray(val)?val:[String(Math.round(val*256))];else if(typeof val===`string`)props[field]=[val];else if(Array.isArray(val))props[field]=val}for(const[rawField,totalField]of[[`trackNumber`,`totalTracks`],[`discNumber`,`totalDiscs`]])if(props[rawField]?.[0]?.includes(`/`))delete props[totalField];return props}var BASIC_FIELDS,NUMERIC_FIELDS;var init_tag_mapping=__esmMin((()=>{BASIC_FIELDS=/* @__PURE__ */ new Set([`title`,`artist`,`album`,`comment`,`genre`,`year`,`date`,`track`,`trackNumber`]);NUMERIC_FIELDS=/* @__PURE__ */ new Set([`year`,`track`,`discNumber`,`totalTracks`,`totalDiscs`,`bpm`])}));var VERSION;var init_version=__esmMin((()=>{VERSION=`2.5.0`}));var module_loader_browser_exports=/* @__PURE__ */ __exportAll({loadTagLibModule:()=>loadTagLibModule});async function loadTagLibModule(options){let createTagLibModule;try{createTagLibModule=(await import(`./taglib-wrapper.js`)).default}catch{try{createTagLibModule=(await import(`./taglib-wrapper.js`)).default}catch{throw new TagLibInitializationError(`Could not load taglib-wrapper.js. Ensure it is co-located with the browser bundle.`)}}const moduleConfig={};if(options?.wasmBinary)moduleConfig.wasmBinary=options.wasmBinary;if(options?.wasmUrl)moduleConfig.locateFile=path=>{if(path.endsWith(`.wasm`))return options.wasmUrl;return path};else if(!options?.wasmBinary){const wasmUrl=new URL(`./taglib-web.wasm`,import.meta.url);moduleConfig.locateFile=path=>path.endsWith(`.wasm`)?wasmUrl.href:path}return await createTagLibModule(moduleConfig)}var init_module_loader_browser=__esmMin((()=>{init_classes()}));function trimTrailingSeparators(p){let end=p.length;while(end>0){const c=p.charAt(end-1);if(c!==`/`&&c!==`\\`)break;end--}return p.slice(0,end)}function toWasiPath(osPath){if(osPath.startsWith(`\\\\`)||osPath.startsWith(`//`))throw new FileOperationError(`read`,`UNC paths are not supported. Path: ${osPath}`);let p=osPath;if(!p.startsWith(`/`)&&!/^[A-Za-z]:/.test(p)){const g=globalThis;const cwd=isDeno()?Deno.cwd():g.process?.cwd?.();if(cwd)p=trimTrailingSeparators(cwd)+`/`+p}p=p.replaceAll(`\\`,`/`);const driveMatch=/^([A-Za-z]):\//.exec(p);if(driveMatch)p=`/${driveMatch[1].toUpperCase()}${p.slice(2)}`;p=p.replaceAll(`/./`,`/`).replace(/\/+/g,`/`);if(!p.startsWith(`/`))p=`/`+p;return p}function createTagLib(module){return Promise.resolve(new TagLib(module))}var TagLib;var init_taglib_class=__esmMin((()=>{init_audio_formats();init_errors();init_detector();init_audio_file_impl();init_load_audio_data();init_tag_mapping();init_version();init_embind_adapter();init_defineProperty();TagLib=class TagLib{constructor(module){_defineProperty(this,`module`,void 0);this.module=module}static async initialize(options){const{loadTagLibModule}=await Promise.resolve().then(()=>(init_module_loader_browser(),module_loader_browser_exports));const module=await loadTagLibModule(options);return new TagLib(module)}async open(input,options){if(!this.module.createFileHandle)throw new TagLibInitializationError(`TagLib module not properly initialized: createFileHandle not found. Make sure the module is fully loaded before calling open.`);const actualInput=isNamedAudioInput(input)?input.data:input;const sourcePath=typeof actualInput===`string`?actualInput:void 0;if(typeof actualInput===`string`&&this.module.isWasi){const wasiPath=toWasiPath(actualInput);if(this.module.loadAudioPath){const fileHandle=await this.module.loadAudioPath(wasiPath,actualInput);return new AudioFileImpl(this.module,fileHandle,sourcePath,actualInput,false)}}const opts={partial:true,maxHeaderSize:1048576,maxFooterSize:131072,...options};const{data:audioData,isPartiallyLoaded}=await loadAudioData(actualInput,opts);const uint8Array=actualInput instanceof Uint8Array&&audioData.buffer===actualInput.buffer?new Uint8Array(audioData.buffer.slice(audioData.byteOffset,audioData.byteOffset+audioData.byteLength)):audioData;const rawHandle=this.module.createFileHandle();const fileHandle=this.module.isWasi?rawHandle:wrapEmbindHandle(rawHandle);try{if(!fileHandle.loadFromBuffer(uint8Array))throw new InvalidFormatError(`Failed to load audio file. File may be corrupted or in an unsupported format`,uint8Array.byteLength);return new AudioFileImpl(this.module,fileHandle,sourcePath,actualInput,isPartiallyLoaded,opts)}catch(error){if(typeof fileHandle.destroy===`function`)fileHandle.destroy();throw error}}async edit(input,fn){const file=await this.open(input);try{await fn(file);if(typeof input===`string`)await file.saveToFile();else{file.save();return file.getFileBuffer()}}finally{file.dispose()}}async updateFile(path,tags){const file=await this.open(path);try{mergeTagUpdates(file,tags);await file.saveToFile()}finally{file.dispose()}}async copyWithTags(sourcePath,destPath,tags){const file=await this.open(sourcePath);try{mergeTagUpdates(file,tags);await file.saveToFile(destPath)}finally{file.dispose()}}version(){return`${VERSION} (TagLib ${this.taglibVersion()})`}taglibVersion(){if(this.module.getVersion)return this.module.getVersion();if(this.module.version)return this.module.version();return`unknown`}}}));var init_taglib$1=__esmMin((()=>{init_audio_file_impl();init_taglib_class();init_errors()}));var taglib_exports=/* @__PURE__ */ __exportAll({AudioFileImpl:()=>AudioFileImpl,EnvironmentError:()=>EnvironmentError,FileOperationError:()=>FileOperationError,InvalidFormatError:()=>InvalidFormatError,MemoryError:()=>MemoryError,MetadataError:()=>MetadataError,SUPPORTED_FORMATS:()=>SUPPORTED_FORMATS,TagLib:()=>TagLib,TagLibError:()=>TagLibError,TagLibInitializationError:()=>TagLibInitializationError,UnsupportedFormatError:()=>UnsupportedFormatError,createTagLib:()=>createTagLib,isEnvironmentError:()=>isEnvironmentError,isFileOperationError:()=>isFileOperationError,isInvalidFormatError:()=>isInvalidFormatError,isMemoryError:()=>isMemoryError,isMetadataError:()=>isMetadataError,isTagLibError:()=>isTagLibError,isUnsupportedFormatError:()=>isUnsupportedFormatError});var init_taglib=__esmMin((()=>{init_taglib$1()}));let cachedTagLib=null;let bufferModeEnabled=false;async function getTagLib(){if(!cachedTagLib){const{TagLib}=await Promise.resolve().then(()=>(init_taglib(),taglib_exports));const initOptions=bufferModeEnabled?{forceWasmType:`emscripten`}:void 0;cachedTagLib=await TagLib.initialize(initOptions)}return cachedTagLib}init_errors();init_file();async function withAudioFile(file,fn,options){const audioFile=await(await getTagLib()).open(file,options);try{if(!audioFile.isValid())throw new InvalidFormatError(`File may be corrupted or in an unsupported format`);return await fn(audioFile)}finally{audioFile.dispose()}}async function withAudioFileSave(file,fn){return withAudioFile(typeof file===`string`?await readFileData(file):file,audioFile=>{fn(audioFile);if(!audioFile.save())throw new FileOperationError(`save`,`Failed to save metadata changes. The file may be read-only or corrupted.`);return audioFile.getFileBuffer()},{partial:false})}async function readPictures(file){return withAudioFile(file,audioFile=>audioFile.getPictures())}async function applyPictures(file,pictures){return withAudioFileSave(file,audioFile=>{audioFile.setPictures(pictures)})}async function setCoverArtFromCanvas(file,canvas,options={}){const{format=`image/jpeg`,quality=.92,type=`FrontCover`,description=`Front Cover`}=options;const dataURL=canvas.toDataURL(format,quality);const picture=dataURLToPicture(dataURL,type,description);return applyPictures(file,[picture])}async function canvasToPicture(canvas,options={}){const{format=`image/jpeg`,quality=.92,type=`FrontCover`,description}=options;return new Promise((resolve,reject)=>{canvas.toBlob(blob=>{if(!blob){reject(/* @__PURE__ */ new Error(`Failed to convert canvas to blob`));return}blob.arrayBuffer().then(arrayBuffer=>{const data=new Uint8Array(arrayBuffer);resolve({mimeType:format,data,type,...description!==void 0?{description}:{}})},reject)},format,quality)})}async function imageFileToPicture(file,type=`FrontCover`,description){const arrayBuffer=await file.arrayBuffer();const data=new Uint8Array(arrayBuffer);return{mimeType:file.type,data,type,description:description??file.name}}function ensureArrayBufferBacked(data){if(data.buffer instanceof ArrayBuffer)return data;const copy=new Uint8Array(data.length);copy.set(data);return copy}function displayPicture(picture,imgElement){if(imgElement.src.startsWith(`blob:`))URL.revokeObjectURL(imgElement.src);const data=ensureArrayBufferBacked(picture.data);const blob=new Blob([data],{type:picture.mimeType});const objectURL=URL.createObjectURL(blob);imgElement.src=objectURL;imgElement.addEventListener(`load`,()=>{setTimeout(()=>URL.revokeObjectURL(objectURL),100)},{once:true})}function createPictureDownloadURL(picture,filename=`cover`){const data=ensureArrayBufferBacked(picture.data);const blob=new Blob([data],{type:picture.mimeType});return URL.createObjectURL(blob)}async function createPictureGallery(file,container,options={}){const pictures=await readPictures(file);container.innerHTML=``;pictures.forEach((picture,index)=>{const wrapper=document.createElement(`div`);wrapper.className=options.className??`picture-item`;const img=document.createElement(`img`);displayPicture(picture,img);img.alt=picture.description??`Picture ${index+1}`;if(options.onClick){img.style.cursor=`pointer`;img.addEventListener(`click`,()=>options.onClick(picture,index))}wrapper.appendChild(img);if(options.includeDescription&&picture.description){const caption=document.createElement(`p`);caption.textContent=picture.description;wrapper.appendChild(caption)}container.appendChild(wrapper)})}export{canvasToPicture,createPictureDownloadURL,createPictureGallery,dataURLToPicture,displayPicture,imageFileToPicture,pictureToDataURL,setCoverArtFromCanvas};
|