mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-03 13:53:53 +02:00
Bubble encoder errors to consumer
This commit is contained in:
+2
-7
@@ -18,7 +18,6 @@ export type SubtitleMetadata = {
|
||||
type SubtitleParserOptions = {
|
||||
codec: 'webvtt';
|
||||
output: (cue: SubtitleCue, metadata: SubtitleMetadata) => unknown;
|
||||
error: (error: Error) => unknown;
|
||||
};
|
||||
|
||||
const cueBlockHeaderRegex = /(?:(.+?)\n)?((?:\d{2}:)?\d{2}:\d{2}.\d{3})\s+-->\s+((?:\d{2}:)?\d{2}:\d{2}.\d{3})/g;
|
||||
@@ -42,18 +41,14 @@ export class SubtitleParser {
|
||||
|
||||
if (!this.preambleText) {
|
||||
if (!preambleStartRegex.test(text)) {
|
||||
const error = new Error('WebVTT preamble incorrect.');
|
||||
this.options.error(error);
|
||||
throw error;
|
||||
throw new Error('WebVTT preamble incorrect.');
|
||||
}
|
||||
|
||||
match = cueBlockHeaderRegex.exec(text);
|
||||
const preamble = text.slice(0, match?.index ?? text.length).trimEnd();
|
||||
|
||||
if (!preamble) {
|
||||
const error = new Error('No WebVTT preamble provided.');
|
||||
this.options.error(error);
|
||||
throw error;
|
||||
throw new Error('No WebVTT preamble provided.');
|
||||
}
|
||||
|
||||
this.preambleText = preamble;
|
||||
|
||||
Reference in New Issue
Block a user