@osbjs/osbjs
Version:
a minimalist osu! storyboarding framework
31 lines (30 loc) • 1.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubtitleCollection = void 0;
const subtitle_1 = require("subtitle");
const fs_extra_1 = require("fs-extra");
class SubtitleCollection {
constructor(path) {
this.path = path;
this.subtitles = this._getSubtitles();
}
_getSubtitles() {
const input = (0, fs_extra_1.readFileSync)(this.path, 'utf8');
if (this.path.match(/.*\.(srt|vtt)$/)) {
let data = (0, subtitle_1.parseSync)(input);
return data
.filter((s) => s.type == 'cue')
.map((s) => {
/** @ts-ignore */
return { startTime: s.data.start, endTime: s.data.end, text: s.data.text };
});
}
else if (this.path.match(/.*\.json$/)) {
return JSON.parse(input);
}
else {
throw new Error('Unsupported file type');
}
}
}
exports.SubtitleCollection = SubtitleCollection;