@storyteller-platform/audiobook 0.1.0 → 0.3.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/dist/entry.cjs +121 -28
- package/dist/entry.d.cts +29 -10
- package/dist/entry.d.ts +29 -10
- package/dist/entry.js +124 -28
- package/dist/ffmpeg.cjs +259 -0
- package/dist/ffmpeg.d.cts +67 -0
- package/dist/ffmpeg.d.ts +67 -0
- package/dist/ffmpeg.js +231 -0
- package/dist/index.cjs +275 -33
- package/dist/index.d.cts +62 -11
- package/dist/index.d.ts +62 -11
- package/dist/index.js +263 -33
- package/dist/mime.cjs +112 -0
- package/dist/mime.d.cts +40 -0
- package/dist/mime.d.ts +40 -0
- package/dist/mime.js +75 -0
- package/dist/resources.cjs +16 -0
- package/dist/resources.d.cts +14 -0
- package/dist/resources.d.ts +14 -0
- package/dist/resources.js +0 -0
- package/package.json +23 -29
- package/dist/base.cjs +0 -248
- package/dist/base.d.cts +0 -67
- package/dist/base.d.ts +0 -67
- package/dist/base.js +0 -223
- package/dist/node/entry.cjs +0 -76
- package/dist/node/entry.d.cts +0 -18
- package/dist/node/entry.d.ts +0 -18
- package/dist/node/entry.js +0 -52
- package/dist/node/index.cjs +0 -107
- package/dist/node/index.d.cts +0 -17
- package/dist/node/index.d.ts +0 -17
- package/dist/node/index.js +0 -89
- package/dist/taglib/Uint8ArrayFileAbstraction.cjs +0 -128
- package/dist/taglib/Uint8ArrayFileAbstraction.d.cts +0 -26
- package/dist/taglib/Uint8ArrayFileAbstraction.d.ts +0 -26
- package/dist/taglib/Uint8ArrayFileAbstraction.js +0 -106
package/dist/base.js
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import { PictureType } from "node-taglib-sharp";
|
|
2
|
-
function splitNames(names) {
|
|
3
|
-
return names.flatMap(
|
|
4
|
-
(entry) => entry.split(/[;,/]/).map((name) => name.trim())
|
|
5
|
-
);
|
|
6
|
-
}
|
|
7
|
-
class BaseAudiobookEntry {
|
|
8
|
-
async getFile() {
|
|
9
|
-
if (this.file) return this.file;
|
|
10
|
-
const file = await this.createFile();
|
|
11
|
-
this.file = file;
|
|
12
|
-
return this.file;
|
|
13
|
-
}
|
|
14
|
-
async getTitle() {
|
|
15
|
-
const file = await this.getFile();
|
|
16
|
-
return file.tag.title;
|
|
17
|
-
}
|
|
18
|
-
async setTitle(title) {
|
|
19
|
-
const file = await this.getFile();
|
|
20
|
-
file.tag.title = title;
|
|
21
|
-
}
|
|
22
|
-
async getSubtitle() {
|
|
23
|
-
const file = await this.getFile();
|
|
24
|
-
return file.tag.subtitle;
|
|
25
|
-
}
|
|
26
|
-
async setSubtitle(subtitle) {
|
|
27
|
-
const file = await this.getFile();
|
|
28
|
-
file.tag.subtitle = subtitle;
|
|
29
|
-
}
|
|
30
|
-
async getDescription() {
|
|
31
|
-
const file = await this.getFile();
|
|
32
|
-
return file.tag.description || file.tag.comment || null;
|
|
33
|
-
}
|
|
34
|
-
async setDescription(description) {
|
|
35
|
-
const file = await this.getFile();
|
|
36
|
-
file.tag.description = description;
|
|
37
|
-
}
|
|
38
|
-
async getAuthors() {
|
|
39
|
-
const file = await this.getFile();
|
|
40
|
-
const albumArtists = file.tag.albumArtists;
|
|
41
|
-
if (albumArtists.length) {
|
|
42
|
-
return splitNames(albumArtists);
|
|
43
|
-
}
|
|
44
|
-
const artists = file.tag.performers;
|
|
45
|
-
return splitNames(artists);
|
|
46
|
-
}
|
|
47
|
-
async setAuthors(authors) {
|
|
48
|
-
const file = await this.getFile();
|
|
49
|
-
file.tag.albumArtists = authors;
|
|
50
|
-
file.tag.performers = authors;
|
|
51
|
-
}
|
|
52
|
-
async getNarrators() {
|
|
53
|
-
const file = await this.getFile();
|
|
54
|
-
const composers = file.tag.composers;
|
|
55
|
-
if (composers.length) {
|
|
56
|
-
return splitNames(composers);
|
|
57
|
-
}
|
|
58
|
-
const conductor = file.tag.conductor;
|
|
59
|
-
if (!conductor) return [];
|
|
60
|
-
return splitNames([conductor]);
|
|
61
|
-
}
|
|
62
|
-
async setNarrators(narrators) {
|
|
63
|
-
const file = await this.getFile();
|
|
64
|
-
file.tag.composers = narrators;
|
|
65
|
-
file.tag.conductor = narrators.join(";");
|
|
66
|
-
}
|
|
67
|
-
async getCoverArt() {
|
|
68
|
-
const file = await this.getFile();
|
|
69
|
-
return file.tag.pictures.find(
|
|
70
|
-
(picture) => picture.type === PictureType.FrontCover
|
|
71
|
-
) ?? null;
|
|
72
|
-
}
|
|
73
|
-
async setCoverArt(picture) {
|
|
74
|
-
const file = await this.getFile();
|
|
75
|
-
const pictures = file.tag.pictures;
|
|
76
|
-
const frontCover = pictures.find(
|
|
77
|
-
(picture2) => picture2.type === PictureType.FrontCover
|
|
78
|
-
);
|
|
79
|
-
if (frontCover) {
|
|
80
|
-
Object.assign(frontCover, picture);
|
|
81
|
-
} else {
|
|
82
|
-
pictures.push(picture);
|
|
83
|
-
}
|
|
84
|
-
file.tag.pictures = pictures;
|
|
85
|
-
}
|
|
86
|
-
async getPublisher() {
|
|
87
|
-
const file = await this.getFile();
|
|
88
|
-
return file.tag.publisher;
|
|
89
|
-
}
|
|
90
|
-
async setPublisher(publisher) {
|
|
91
|
-
const file = await this.getFile();
|
|
92
|
-
file.tag.publisher = publisher;
|
|
93
|
-
}
|
|
94
|
-
async getReleased() {
|
|
95
|
-
const file = await this.getFile();
|
|
96
|
-
return file.tag.year.toString();
|
|
97
|
-
}
|
|
98
|
-
async setReleased(released) {
|
|
99
|
-
const file = await this.getFile();
|
|
100
|
-
file.tag.year = parseInt(released);
|
|
101
|
-
}
|
|
102
|
-
save() {
|
|
103
|
-
var _a;
|
|
104
|
-
(_a = this.file) == null ? void 0 : _a.save();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
class BaseAudiobook {
|
|
108
|
-
metadata = {};
|
|
109
|
-
async getFirstValue(getter) {
|
|
110
|
-
for (const entry of this.entries) {
|
|
111
|
-
const value = await getter(entry);
|
|
112
|
-
if (value) return value;
|
|
113
|
-
}
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
async setValue(setter) {
|
|
117
|
-
for (const entry of this.entries) {
|
|
118
|
-
await setter(entry);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
async getTitle() {
|
|
122
|
-
if (this.metadata.title) {
|
|
123
|
-
return this.metadata.title;
|
|
124
|
-
}
|
|
125
|
-
const title = await this.getFirstValue((entry) => entry.getTitle());
|
|
126
|
-
if (title) this.metadata.title = title;
|
|
127
|
-
return title;
|
|
128
|
-
}
|
|
129
|
-
async setTitle(title) {
|
|
130
|
-
this.metadata.title = title;
|
|
131
|
-
await this.setValue((entry) => entry.setTitle(title));
|
|
132
|
-
}
|
|
133
|
-
async getSubtitle() {
|
|
134
|
-
if (this.metadata.subtitle) {
|
|
135
|
-
return this.metadata.subtitle;
|
|
136
|
-
}
|
|
137
|
-
const subtitle = await this.getFirstValue((entry) => entry.getSubtitle());
|
|
138
|
-
if (subtitle) this.metadata.subtitle = subtitle;
|
|
139
|
-
return subtitle;
|
|
140
|
-
}
|
|
141
|
-
async setSubtitle(subtitle) {
|
|
142
|
-
this.metadata.subtitle = subtitle;
|
|
143
|
-
await this.setValue((entry) => entry.setSubtitle(subtitle));
|
|
144
|
-
}
|
|
145
|
-
async getDescription() {
|
|
146
|
-
if (this.metadata.description) {
|
|
147
|
-
return this.metadata.description;
|
|
148
|
-
}
|
|
149
|
-
const description = await this.getFirstValue(
|
|
150
|
-
(entry) => entry.getDescription()
|
|
151
|
-
);
|
|
152
|
-
if (description) this.metadata.description = description;
|
|
153
|
-
return description;
|
|
154
|
-
}
|
|
155
|
-
async setDescription(description) {
|
|
156
|
-
this.metadata.description = description;
|
|
157
|
-
await this.setValue((entry) => entry.setDescription(description));
|
|
158
|
-
}
|
|
159
|
-
async getAuthors() {
|
|
160
|
-
if (this.metadata.authors) {
|
|
161
|
-
return this.metadata.authors;
|
|
162
|
-
}
|
|
163
|
-
const authors = await this.getFirstValue((entry) => entry.getAuthors());
|
|
164
|
-
if (authors) this.metadata.authors = authors;
|
|
165
|
-
return authors ?? [];
|
|
166
|
-
}
|
|
167
|
-
async setAuthors(authors) {
|
|
168
|
-
this.metadata.authors = authors;
|
|
169
|
-
await this.setValue((entry) => entry.setAuthors(authors));
|
|
170
|
-
}
|
|
171
|
-
async getNarrators() {
|
|
172
|
-
if (this.metadata.narrators) {
|
|
173
|
-
return this.metadata.narrators;
|
|
174
|
-
}
|
|
175
|
-
const narrators = await this.getFirstValue((entry) => entry.getNarrators());
|
|
176
|
-
if (narrators) this.metadata.narrators = narrators;
|
|
177
|
-
return narrators ?? [];
|
|
178
|
-
}
|
|
179
|
-
async setNarrators(narrators) {
|
|
180
|
-
this.metadata.narrators = narrators;
|
|
181
|
-
await this.setValue((entry) => entry.setNarrators(narrators));
|
|
182
|
-
}
|
|
183
|
-
async getCoverArt() {
|
|
184
|
-
if (this.metadata.coverArt) {
|
|
185
|
-
return this.metadata.coverArt;
|
|
186
|
-
}
|
|
187
|
-
const coverArt = await this.getFirstValue((entry) => entry.getCoverArt());
|
|
188
|
-
if (coverArt) this.metadata.coverArt = coverArt;
|
|
189
|
-
return coverArt;
|
|
190
|
-
}
|
|
191
|
-
async setCoverArt(picture) {
|
|
192
|
-
this.metadata.coverArt = picture;
|
|
193
|
-
await this.setValue((entry) => entry.setCoverArt(picture));
|
|
194
|
-
}
|
|
195
|
-
async getPublisher() {
|
|
196
|
-
if (this.metadata.publisher) {
|
|
197
|
-
return this.metadata.publisher;
|
|
198
|
-
}
|
|
199
|
-
const publisher = await this.getFirstValue((entry) => entry.getPublisher());
|
|
200
|
-
if (publisher) this.metadata.publisher = publisher;
|
|
201
|
-
return publisher;
|
|
202
|
-
}
|
|
203
|
-
async setPublisher(publisher) {
|
|
204
|
-
this.metadata.publisher = publisher;
|
|
205
|
-
await this.setValue((entry) => entry.setPublisher(publisher));
|
|
206
|
-
}
|
|
207
|
-
async getReleased() {
|
|
208
|
-
if (this.metadata.released) {
|
|
209
|
-
return this.metadata.released;
|
|
210
|
-
}
|
|
211
|
-
const released = await this.getFirstValue((entry) => entry.getReleased());
|
|
212
|
-
if (released) this.metadata.released = released;
|
|
213
|
-
return released;
|
|
214
|
-
}
|
|
215
|
-
async setReleased(released) {
|
|
216
|
-
this.metadata.released = released;
|
|
217
|
-
await this.setValue((entry) => entry.setReleased(released));
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
export {
|
|
221
|
-
BaseAudiobook,
|
|
222
|
-
BaseAudiobookEntry
|
|
223
|
-
};
|
package/dist/node/entry.cjs
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var entry_exports = {};
|
|
20
|
-
__export(entry_exports, {
|
|
21
|
-
AudiobookEntry: () => AudiobookEntry
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(entry_exports);
|
|
24
|
-
var import_promises = require("node:fs/promises");
|
|
25
|
-
var import_zip = require("@zip.js/zip.js");
|
|
26
|
-
var import_node_taglib_sharp = require("node-taglib-sharp");
|
|
27
|
-
var import_fs = require("@storyteller-platform/fs");
|
|
28
|
-
var import_base = require("../base.cjs");
|
|
29
|
-
var import_Uint8ArrayFileAbstraction = require("../taglib/Uint8ArrayFileAbstraction.cjs");
|
|
30
|
-
class AudiobookEntry extends import_base.BaseAudiobookEntry {
|
|
31
|
-
constructor(entry) {
|
|
32
|
-
super();
|
|
33
|
-
this.entry = entry;
|
|
34
|
-
this.filename = typeof entry === "string" ? entry : entry.filename;
|
|
35
|
-
}
|
|
36
|
-
filename;
|
|
37
|
-
file = null;
|
|
38
|
-
async createFile() {
|
|
39
|
-
if (typeof this.entry === "string") {
|
|
40
|
-
const file = import_node_taglib_sharp.File.createFromPath(this.entry);
|
|
41
|
-
return file;
|
|
42
|
-
}
|
|
43
|
-
const data = await this.readData();
|
|
44
|
-
return import_node_taglib_sharp.File.createFromAbstraction(
|
|
45
|
-
new import_Uint8ArrayFileAbstraction.Uint8ArrayFileAbstraction(this.filename, data)
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
async getData() {
|
|
49
|
-
if (typeof this.entry === "string") {
|
|
50
|
-
return await (0, import_promises.readFile)(this.entry);
|
|
51
|
-
}
|
|
52
|
-
const file = await this.getFile();
|
|
53
|
-
return file.fileAbstraction.data;
|
|
54
|
-
}
|
|
55
|
-
async readData() {
|
|
56
|
-
if (typeof this.entry === "string") {
|
|
57
|
-
return await (0, import_fs.streamFile)(this.entry);
|
|
58
|
-
}
|
|
59
|
-
if ("data" in this.entry) {
|
|
60
|
-
return this.entry.data;
|
|
61
|
-
}
|
|
62
|
-
const writer = new import_zip.Uint8ArrayWriter();
|
|
63
|
-
return await this.entry.getData(writer);
|
|
64
|
-
}
|
|
65
|
-
persisted() {
|
|
66
|
-
return typeof this.entry === "string";
|
|
67
|
-
}
|
|
68
|
-
close() {
|
|
69
|
-
var _a;
|
|
70
|
-
(_a = this.file) == null ? void 0 : _a.dispose();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
-
0 && (module.exports = {
|
|
75
|
-
AudiobookEntry
|
|
76
|
-
});
|
package/dist/node/entry.d.cts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Entry } from '@zip.js/zip.js';
|
|
2
|
-
import { File } from 'node-taglib-sharp';
|
|
3
|
-
import { BaseAudiobookEntry } from '../base.cjs';
|
|
4
|
-
import { Uint8ArrayEntry } from '../entry.cjs';
|
|
5
|
-
|
|
6
|
-
declare class AudiobookEntry extends BaseAudiobookEntry {
|
|
7
|
-
protected entry: string | Uint8ArrayEntry | Entry;
|
|
8
|
-
filename: string;
|
|
9
|
-
protected file: File | null;
|
|
10
|
-
constructor(entry: string | Uint8ArrayEntry | Entry);
|
|
11
|
-
createFile(): Promise<File>;
|
|
12
|
-
getData(): Promise<Uint8Array>;
|
|
13
|
-
protected readData(): Promise<Uint8Array>;
|
|
14
|
-
persisted(): boolean;
|
|
15
|
-
close(): void;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { AudiobookEntry };
|
package/dist/node/entry.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Entry } from '@zip.js/zip.js';
|
|
2
|
-
import { File } from 'node-taglib-sharp';
|
|
3
|
-
import { BaseAudiobookEntry } from '../base.js';
|
|
4
|
-
import { Uint8ArrayEntry } from '../entry.js';
|
|
5
|
-
|
|
6
|
-
declare class AudiobookEntry extends BaseAudiobookEntry {
|
|
7
|
-
protected entry: string | Uint8ArrayEntry | Entry;
|
|
8
|
-
filename: string;
|
|
9
|
-
protected file: File | null;
|
|
10
|
-
constructor(entry: string | Uint8ArrayEntry | Entry);
|
|
11
|
-
createFile(): Promise<File>;
|
|
12
|
-
getData(): Promise<Uint8Array>;
|
|
13
|
-
protected readData(): Promise<Uint8Array>;
|
|
14
|
-
persisted(): boolean;
|
|
15
|
-
close(): void;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { AudiobookEntry };
|
package/dist/node/entry.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import { Uint8ArrayWriter } from "@zip.js/zip.js";
|
|
3
|
-
import { File } from "node-taglib-sharp";
|
|
4
|
-
import { streamFile } from "@storyteller-platform/fs";
|
|
5
|
-
import { BaseAudiobookEntry } from "../base.js";
|
|
6
|
-
import { Uint8ArrayFileAbstraction } from "../taglib/Uint8ArrayFileAbstraction.js";
|
|
7
|
-
class AudiobookEntry extends BaseAudiobookEntry {
|
|
8
|
-
constructor(entry) {
|
|
9
|
-
super();
|
|
10
|
-
this.entry = entry;
|
|
11
|
-
this.filename = typeof entry === "string" ? entry : entry.filename;
|
|
12
|
-
}
|
|
13
|
-
filename;
|
|
14
|
-
file = null;
|
|
15
|
-
async createFile() {
|
|
16
|
-
if (typeof this.entry === "string") {
|
|
17
|
-
const file = File.createFromPath(this.entry);
|
|
18
|
-
return file;
|
|
19
|
-
}
|
|
20
|
-
const data = await this.readData();
|
|
21
|
-
return File.createFromAbstraction(
|
|
22
|
-
new Uint8ArrayFileAbstraction(this.filename, data)
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
async getData() {
|
|
26
|
-
if (typeof this.entry === "string") {
|
|
27
|
-
return await readFile(this.entry);
|
|
28
|
-
}
|
|
29
|
-
const file = await this.getFile();
|
|
30
|
-
return file.fileAbstraction.data;
|
|
31
|
-
}
|
|
32
|
-
async readData() {
|
|
33
|
-
if (typeof this.entry === "string") {
|
|
34
|
-
return await streamFile(this.entry);
|
|
35
|
-
}
|
|
36
|
-
if ("data" in this.entry) {
|
|
37
|
-
return this.entry.data;
|
|
38
|
-
}
|
|
39
|
-
const writer = new Uint8ArrayWriter();
|
|
40
|
-
return await this.entry.getData(writer);
|
|
41
|
-
}
|
|
42
|
-
persisted() {
|
|
43
|
-
return typeof this.entry === "string";
|
|
44
|
-
}
|
|
45
|
-
close() {
|
|
46
|
-
var _a;
|
|
47
|
-
(_a = this.file) == null ? void 0 : _a.dispose();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export {
|
|
51
|
-
AudiobookEntry
|
|
52
|
-
};
|
package/dist/node/index.cjs
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var node_exports = {};
|
|
20
|
-
__export(node_exports, {
|
|
21
|
-
Audiobook: () => Audiobook
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(node_exports);
|
|
24
|
-
var import_promises = require("node:fs/promises");
|
|
25
|
-
var import_zip = require("@zip.js/zip.js");
|
|
26
|
-
var import_node_taglib_sharp = require("node-taglib-sharp");
|
|
27
|
-
var import_fs = require("@storyteller-platform/fs");
|
|
28
|
-
var import_path = require("@storyteller-platform/path");
|
|
29
|
-
var import_base = require("../base.cjs");
|
|
30
|
-
var import_entry2 = require("./entry.cjs");
|
|
31
|
-
class Audiobook extends import_base.BaseAudiobook {
|
|
32
|
-
constructor(entries, zipPath) {
|
|
33
|
-
super();
|
|
34
|
-
this.entries = entries;
|
|
35
|
-
this.zipPath = zipPath;
|
|
36
|
-
}
|
|
37
|
-
static async from(pathOrPathsOrData) {
|
|
38
|
-
if (Array.isArray(pathOrPathsOrData)) {
|
|
39
|
-
return new Audiobook(
|
|
40
|
-
pathOrPathsOrData.map((path) => new import_entry2.AudiobookEntry(path))
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
const filepath = typeof pathOrPathsOrData === "string" ? pathOrPathsOrData : pathOrPathsOrData.filename;
|
|
44
|
-
const ext = (0, import_path.extname)(filepath);
|
|
45
|
-
if (ext === ".zip") {
|
|
46
|
-
const dataReader = new import_zip.Uint8ArrayReader(
|
|
47
|
-
typeof pathOrPathsOrData === "string" ? await (0, import_fs.streamFile)(pathOrPathsOrData) : pathOrPathsOrData.data
|
|
48
|
-
);
|
|
49
|
-
const zipReader = new import_zip.ZipReader(dataReader);
|
|
50
|
-
const zipEntries = await zipReader.getEntries();
|
|
51
|
-
const entries = zipEntries.map((entry) => new import_entry2.AudiobookEntry(entry));
|
|
52
|
-
return new Audiobook(entries, filepath);
|
|
53
|
-
}
|
|
54
|
-
return new Audiobook([new import_entry2.AudiobookEntry(pathOrPathsOrData)]);
|
|
55
|
-
}
|
|
56
|
-
async save() {
|
|
57
|
-
const result = [];
|
|
58
|
-
for (const entry of this.entries) {
|
|
59
|
-
entry.save();
|
|
60
|
-
if (!entry.persisted()) {
|
|
61
|
-
result.push({ filename: entry.filename, data: await entry.getData() });
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (this.zipPath) {
|
|
65
|
-
const dataWriter = new import_zip.Uint8ArrayWriter();
|
|
66
|
-
const zipWriter = new import_zip.ZipWriter(dataWriter);
|
|
67
|
-
await Promise.all(
|
|
68
|
-
this.entries.map(async (entry) => {
|
|
69
|
-
const data2 = await entry.getData();
|
|
70
|
-
const reader = new import_zip.Uint8ArrayReader(data2);
|
|
71
|
-
try {
|
|
72
|
-
return await zipWriter.add(entry.filename, reader);
|
|
73
|
-
} catch (e) {
|
|
74
|
-
if (e instanceof Error && e.message === import_zip.ERR_DUPLICATED_NAME) {
|
|
75
|
-
throw new Error(
|
|
76
|
-
`Failed to add file "${entry.filename}" to zip archive: ${e.message}`
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
throw e;
|
|
80
|
-
}
|
|
81
|
-
})
|
|
82
|
-
);
|
|
83
|
-
const data = await zipWriter.close();
|
|
84
|
-
await (0, import_promises.writeFile)(this.zipPath, data);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
if (result.length) return result;
|
|
88
|
-
return void 0;
|
|
89
|
-
}
|
|
90
|
-
async setCoverArt(picture) {
|
|
91
|
-
if (typeof picture === "string") {
|
|
92
|
-
const filename = (0, import_path.basename)(picture);
|
|
93
|
-
picture = import_node_taglib_sharp.Picture.fromPath(picture);
|
|
94
|
-
picture.filename = filename;
|
|
95
|
-
}
|
|
96
|
-
return super.setCoverArt(picture);
|
|
97
|
-
}
|
|
98
|
-
close() {
|
|
99
|
-
for (const entry of this.entries) {
|
|
100
|
-
entry.close();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
-
0 && (module.exports = {
|
|
106
|
-
Audiobook
|
|
107
|
-
});
|
package/dist/node/index.d.cts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { IPicture } from 'node-taglib-sharp';
|
|
2
|
-
import { BaseAudiobook } from '../base.cjs';
|
|
3
|
-
import { Uint8ArrayEntry } from '../entry.cjs';
|
|
4
|
-
import { AudiobookEntry } from './entry.cjs';
|
|
5
|
-
import '@zip.js/zip.js';
|
|
6
|
-
|
|
7
|
-
declare class Audiobook extends BaseAudiobook {
|
|
8
|
-
protected entries: AudiobookEntry[];
|
|
9
|
-
protected zipPath?: string | undefined;
|
|
10
|
-
protected constructor(entries: AudiobookEntry[], zipPath?: string | undefined);
|
|
11
|
-
static from(pathOrPathsOrData: string | string[] | Uint8ArrayEntry | Uint8ArrayEntry[]): Promise<Audiobook>;
|
|
12
|
-
save(): Promise<Uint8ArrayEntry[] | undefined>;
|
|
13
|
-
setCoverArt(picture: string | IPicture): Promise<void>;
|
|
14
|
-
close(): void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { Audiobook };
|
package/dist/node/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { IPicture } from 'node-taglib-sharp';
|
|
2
|
-
import { BaseAudiobook } from '../base.js';
|
|
3
|
-
import { Uint8ArrayEntry } from '../entry.js';
|
|
4
|
-
import { AudiobookEntry } from './entry.js';
|
|
5
|
-
import '@zip.js/zip.js';
|
|
6
|
-
|
|
7
|
-
declare class Audiobook extends BaseAudiobook {
|
|
8
|
-
protected entries: AudiobookEntry[];
|
|
9
|
-
protected zipPath?: string | undefined;
|
|
10
|
-
protected constructor(entries: AudiobookEntry[], zipPath?: string | undefined);
|
|
11
|
-
static from(pathOrPathsOrData: string | string[] | Uint8ArrayEntry | Uint8ArrayEntry[]): Promise<Audiobook>;
|
|
12
|
-
save(): Promise<Uint8ArrayEntry[] | undefined>;
|
|
13
|
-
setCoverArt(picture: string | IPicture): Promise<void>;
|
|
14
|
-
close(): void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { Audiobook };
|
package/dist/node/index.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { writeFile } from "node:fs/promises";
|
|
2
|
-
import {
|
|
3
|
-
ERR_DUPLICATED_NAME,
|
|
4
|
-
Uint8ArrayReader,
|
|
5
|
-
Uint8ArrayWriter,
|
|
6
|
-
ZipReader,
|
|
7
|
-
ZipWriter
|
|
8
|
-
} from "@zip.js/zip.js";
|
|
9
|
-
import { Picture } from "node-taglib-sharp";
|
|
10
|
-
import { streamFile } from "@storyteller-platform/fs";
|
|
11
|
-
import { basename, extname } from "@storyteller-platform/path";
|
|
12
|
-
import { BaseAudiobook } from "../base.js";
|
|
13
|
-
import { AudiobookEntry } from "./entry.js";
|
|
14
|
-
class Audiobook extends BaseAudiobook {
|
|
15
|
-
constructor(entries, zipPath) {
|
|
16
|
-
super();
|
|
17
|
-
this.entries = entries;
|
|
18
|
-
this.zipPath = zipPath;
|
|
19
|
-
}
|
|
20
|
-
static async from(pathOrPathsOrData) {
|
|
21
|
-
if (Array.isArray(pathOrPathsOrData)) {
|
|
22
|
-
return new Audiobook(
|
|
23
|
-
pathOrPathsOrData.map((path) => new AudiobookEntry(path))
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
const filepath = typeof pathOrPathsOrData === "string" ? pathOrPathsOrData : pathOrPathsOrData.filename;
|
|
27
|
-
const ext = extname(filepath);
|
|
28
|
-
if (ext === ".zip") {
|
|
29
|
-
const dataReader = new Uint8ArrayReader(
|
|
30
|
-
typeof pathOrPathsOrData === "string" ? await streamFile(pathOrPathsOrData) : pathOrPathsOrData.data
|
|
31
|
-
);
|
|
32
|
-
const zipReader = new ZipReader(dataReader);
|
|
33
|
-
const zipEntries = await zipReader.getEntries();
|
|
34
|
-
const entries = zipEntries.map((entry) => new AudiobookEntry(entry));
|
|
35
|
-
return new Audiobook(entries, filepath);
|
|
36
|
-
}
|
|
37
|
-
return new Audiobook([new AudiobookEntry(pathOrPathsOrData)]);
|
|
38
|
-
}
|
|
39
|
-
async save() {
|
|
40
|
-
const result = [];
|
|
41
|
-
for (const entry of this.entries) {
|
|
42
|
-
entry.save();
|
|
43
|
-
if (!entry.persisted()) {
|
|
44
|
-
result.push({ filename: entry.filename, data: await entry.getData() });
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (this.zipPath) {
|
|
48
|
-
const dataWriter = new Uint8ArrayWriter();
|
|
49
|
-
const zipWriter = new ZipWriter(dataWriter);
|
|
50
|
-
await Promise.all(
|
|
51
|
-
this.entries.map(async (entry) => {
|
|
52
|
-
const data2 = await entry.getData();
|
|
53
|
-
const reader = new Uint8ArrayReader(data2);
|
|
54
|
-
try {
|
|
55
|
-
return await zipWriter.add(entry.filename, reader);
|
|
56
|
-
} catch (e) {
|
|
57
|
-
if (e instanceof Error && e.message === ERR_DUPLICATED_NAME) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
`Failed to add file "${entry.filename}" to zip archive: ${e.message}`
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
throw e;
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
);
|
|
66
|
-
const data = await zipWriter.close();
|
|
67
|
-
await writeFile(this.zipPath, data);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (result.length) return result;
|
|
71
|
-
return void 0;
|
|
72
|
-
}
|
|
73
|
-
async setCoverArt(picture) {
|
|
74
|
-
if (typeof picture === "string") {
|
|
75
|
-
const filename = basename(picture);
|
|
76
|
-
picture = Picture.fromPath(picture);
|
|
77
|
-
picture.filename = filename;
|
|
78
|
-
}
|
|
79
|
-
return super.setCoverArt(picture);
|
|
80
|
-
}
|
|
81
|
-
close() {
|
|
82
|
-
for (const entry of this.entries) {
|
|
83
|
-
entry.close();
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
export {
|
|
88
|
-
Audiobook
|
|
89
|
-
};
|